Changeset 1022794
- Timestamp:
- 11/10/2014 07:54:35 AM (11 years ago)
- Location:
- wp-emmet/trunk
- Files:
-
- 1 added
- 6 edited
-
WP/Emmet.php (modified) (1 diff)
-
WP/Emmet/CodeMirror.php (modified) (3 diffs)
-
assets/js/codemirror/adapter.js (added)
-
assets/js/wp_emmet.js (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
views/apply_for_codemirror.php (modified) (2 diffs)
-
wp-emmet.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-emmet/trunk/WP/Emmet.php
r952584 r1022794 138 138 public function enqueueScripts() { 139 139 $type = $this->editorType(); 140 $deps = array('underscore'); 141 140 142 if ($this->isCodeMirrorMode()) { 141 143 $this->CodeMirror->enqueueAllScripts(); 144 $deps[] = $type; 142 145 } 143 wp_enqueue_script('wp_wmmet', self::assetURL("js/wp_emmet.js")); 144 wp_enqueue_script('emmet', self::assetURL("js/{$type}/emmet.js"), array('underscore'), false, true); 146 147 wp_enqueue_script('emmet', self::assetURL("js/{$type}/emmet.js"), $deps, false, true); 148 wp_enqueue_script('wp_wmmet', self::assetURL("js/wp_emmet.js"), array('emmet','editor')); 145 149 } 146 150 -
wp-emmet/trunk/WP/Emmet/CodeMirror.php
r858784 r1022794 36 36 $this->_registerThemes(); 37 37 $this->registerScript('codemirror'); 38 $this->registerScript('adapter', 'adapter', array('deps' => 'codemirror')); 38 39 $this->_registerModes(); 39 40 } … … 76 77 */ 77 78 public function enqueueScript($mode = null) { 78 wp_enqueue_script($mode ? "{$this->domain}-{$mode}" : $this->domain); 79 $handle = $this->domain; 80 $deps = array(); 81 82 if ($mode) { 83 $deps[] = $this->domain; 84 $handle.= '-' . $mode; 85 } 86 87 wp_enqueue_script($handle, $deps); 79 88 } 80 89 … … 84 93 public function enqueueAllScripts() { 85 94 $this->enqueueScript(); 95 $this->enqueueScript('adapter'); 86 96 array_walk($this->modes, array($this, 'enqueueScript')); 87 97 } -
wp-emmet/trunk/assets/js/wp_emmet.js
r738398 r1022794 1 !function($) { 1 var wp_emmet = (function($) { 2 'use strict'; 3 2 4 var editorID = 'wp-emmet-editor'; 3 5 6 /** 7 * Apply the CodeMirror 8 * 9 * @param options 10 * @returns {*} 11 */ 4 12 $.fn.codeMirror = function(options) { 5 13 return this.each(function() { … … 17 25 }; 18 26 27 /** 28 * Get an editor of the CodeMirror 29 * 30 * @param editor 31 * @returns {*} 32 */ 19 33 $.fn.codeMirrorEditor = function(editor) { 20 34 if (editor) { 21 return $.data(this[0],editorID, editor);35 return this.data(editorID, editor); 22 36 } 23 return $.data(this[0],editorID);37 return this.data(editorID); 24 38 }; 25 39 26 window.wp_emmet = { 27 adaptCodeMirror: function() { 28 if (typeof wp !== 'undefined' && 29 typeof wp.media !== 'undefined' && 30 typeof wp.media.editor !== 'undefined') { 31 this.adaptMediaEditor(); 40 /** 41 * Apply emmet 42 * 43 * @param options 44 * @param mimeTypes 45 * @returns {*} 46 */ 47 $.fn.emmet = function(options, mimeTypes) { 48 options = options || {}; 49 mimeTypes = mimeTypes || {}; 50 51 return this.each(function() { 52 var maxWidth, minHeight, 53 $textarea = $(this), 54 file = $textarea.closest('form').find('input[name="file"]').val(), 55 mode = $textarea.attr('data-cm-mode'); 56 57 if (!mode) { 58 mode = mimeTypes[file ? file.split('.').pop() : 'html']; 32 59 } 33 60 34 if (typeof switchEditors !== 'undefined') { 35 this.adaptSwitchEditors(); 61 $textarea.codeMirror($.extend({}, options, {mode: mode})); 62 63 if (maxWidth = $textarea.attr('data-cm-max-width')) { 64 $($textarea.codeMirrorEditor().display.wrapper).css({maxWidth: maxWidth}); 36 65 } 37 66 38 if ( typeof QTags !== 'undefined') {39 this.adaptQTags();67 if (minHeight = $textarea.attr('data-cm-min-height')) { 68 $($textarea.codeMirrorEditor().display.scroller).css({minHeight: minHeight}); 40 69 } 70 }); 71 }; 41 72 42 if (typeof wpLink !== 'undefined') {43 this.adaptWPLink();44 }73 function adjust() { 74 var editor = $('#content').codeMirrorEditor(), 75 $top = wp_emmet.$top || $('#ed_toolbar'); 45 76 46 if (typeof fullscreen !== 'undefined') {47 this.adaptFullScreen();48 }49 },77 if (editor) { 78 $(editor.display.wrapper).css('marginTop', $top.innerHeight()|0) 79 } 80 } 50 81 51 adaptMediaEditor: function() { 52 var originalInsert = wp.media.editor.insert; 82 var scrollTimerID; 53 83 54 wp.media.editor.insert = function(h) { 55 var cursor, 56 editor = $('#' + wpActiveEditor).codeMirrorEditor(); 84 $(window).on('scroll resize', function() { 85 adjust(); 86 clearTimeout(scrollTimerID); 87 scrollTimerID = setTimeout(adjust, 100); 88 }); 57 89 58 if (!editor) { 59 return originalInsert.call(this, h); 60 } 90 $(document).on('wp-collapse-menu postboxes-columnchange editor-classchange postbox-toggled', adjust); 61 91 62 editor.doc.replaceSelection(h); 63 cursor = editor.doc.getCursor(); 64 editor.doc.setCursor(cursor.line, cursor.ch + h.indexOf('>')); 65 editor.focus(); 66 }; 67 }, 68 69 adaptSwitchEditors: function() { 70 switchEditors.switchto = function(el) { 71 var params = el.id.split('-'), 72 $wrap = $('#wp-' + params[0] + '-wrap'), 73 $textarea = $(tinymce.DOM.get(params[0])), 74 editor = $textarea.codeMirrorEditor(), 75 toHTML = params[1] === 'html', 76 fromHTML = $wrap.hasClass('html-active'); 77 78 if ((toHTML && fromHTML) || (!toHTML && !fromHTML)) { 79 return; 80 } 81 82 if (!toHTML) { 83 editor.toTextArea(); 84 } 85 86 this.go(params[0], params[1]); 87 88 if (toHTML) { 89 editor = CodeMirror.fromTextArea(editor.getTextArea(), editor.options); 90 editor.disabled = false; 91 $textarea.codeMirrorEditor(editor); 92 } 93 }; 94 }, 95 96 adaptQTags: function() { 97 QTags.TagButton.prototype.callback = function(element, canvas, ed) { 98 var cursor, html, 99 editor = $(canvas).codeMirrorEditor(), 100 text = editor.doc.getSelection(), 101 startPos = text.indexOf(this.tagStart), 102 endPos = text.indexOf(this.tagEnd); 103 104 if (startPos !== -1 && endPos !== -1) { 105 html = text.substring(this.tagStart.length, endPos); 106 } else { 107 html = this.tagStart + text + this.tagEnd; 108 } 109 110 editor.doc.replaceSelection(html); 111 112 if (text) { 113 cursor = editor.doc.getCursor('end'); 114 } else { 115 cursor = editor.doc.getCursor('start'); 116 cursor.ch += this.tagStart.length; 117 } 118 119 editor.doc.setCursor(cursor, cursor); 120 editor.focus(); 121 }; 122 }, 123 124 adaptWPLink: function() { 125 wpLink.htmlUpdate = function() { 126 var cursor, 127 data = this.getAttrs(), 128 editor = $(this.textarea).codeMirrorEditor(), 129 tagStart = '<a', 130 tagEnd = '</a>'; 131 132 $.each(data, function(name, value) { 133 if (value) { 134 tagStart += ' ' + name + '="' + value + '"'; 135 } 136 }); 137 138 tagStart += '>'; 139 140 editor.replaceSelection(tagStart + editor.getSelection() + tagEnd); 141 142 cursor = editor.doc.getCursor('start'); 143 editor.doc.setCursor(cursor.line, cursor.ch + tagStart.length); 144 editor.focus(); 145 146 this.close(); 147 }; 148 }, 149 150 adaptFullScreen: function() { 151 var $fullScreen = $('#wp_mce_fullscreen'), 152 originalOff = fullscreen.off, 153 originalSwitchMode = fullscreen.switchmode, 154 originalSaveContent = fullscreen.savecontent; 155 156 fullscreen.pubsub.subscribe('showing', function() { 157 var editor = $('#' + wpActiveEditor).codeMirrorEditor(); 158 $fullScreen.codeMirror(editor.options); 159 }); 160 161 fullscreen.off = function() { 162 var $content = $('#' + fullscreen.settings.editor_id), 163 editor = $fullScreen.codeMirrorEditor(); 164 165 originalOff.call(this); 166 167 if ($content.is(':visible')) { 168 $content.val(editor.doc.getValue()); 169 $content.codeMirror(editor.options); 170 } 171 172 if (fullscreen.settings.mode === 'html') { 173 editor.toTextArea(); 174 } 175 }; 176 177 fullscreen.switchmode = function(to) { 178 if (fullscreen.settings.mode === to) { 179 return; 180 } 181 182 var editor = $fullScreen.codeMirrorEditor(), 183 mainEditor = $('#' + fullscreen.settings.editor_id).codeMirrorEditor(); 184 185 if (to === 'html') { 186 originalSwitchMode.call(this, to); 187 $fullScreen.codeMirror(mainEditor.options); 188 } else { 189 editor && editor.toTextArea(); 190 originalSwitchMode.call(this, to); 191 } 192 }; 193 194 fullscreen.savecontent = function() { 195 if (fullscreen.settings.mode === 'html') { 196 $fullScreen.codeMirrorEditor().save(); 197 } 198 originalSaveContent.call(this); 199 }; 200 201 QTags.FullscreenButton.prototype.callback = function(e, c) { 202 if (!c.id) { return; } 203 $(c).codeMirrorEditor().toTextArea(); 204 fullscreen.on(); 205 }; 206 } 92 return { 93 adjust: adjust 207 94 }; 208 }(jQuery) ;95 }(jQuery)); -
wp-emmet/trunk/readme.txt
r952585 r1022794 2 2 Contributors: rewish 3 3 Tags: emmet, zen-coding, editor, post, plugin, coding 4 Requires at least: 3.55 Tested up to: 3.9.14 Requires at least: 4.0 5 Tested up to: 4.0 6 6 Stable tag: trunk 7 7 License: GPLv2 or later … … 27 27 28 28 == Changelog == 29 30 = 0.3 = 31 * Fixes for WordPress 4.0 32 * Raise the requires version to 4.0 29 33 30 34 = 0.2.6 = -
wp-emmet/trunk/views/apply_for_codemirror.php
r742780 r1022794 4 4 } 5 5 </style> 6 6 7 <script> 7 8 <?php if ($this->Options->get('override_shortcuts')): ?> … … 17 18 jQuery(function($) { 18 19 var options = $.extend(<?php echo $this->Options->toJSON('codemirror'); ?>, { 19 profile: '<?php echo $this->Options->get('profile'); ?>' 20 }), 21 mimeTypes = { 22 php: 'application/x-httpd-php', 23 html: 'text/html', 24 css: 'text/css', 25 js: 'text/javascript', 26 json: 'application/json' 27 }; 20 profile: '<?php echo $this->Options->get('profile'); ?>' 21 }); 22 23 var mimeTypes = { 24 php: 'application/x-httpd-php', 25 html: 'text/html', 26 css: 'text/css', 27 js: 'text/javascript', 28 json: 'application/json' 29 }; 28 30 29 31 setTimeout(function() { 30 $('textarea:not(#wp_mce_fullscreen)').each(function() { 31 var $textarea = $(this), 32 file = $textarea.closest('form').find('input[name="file"]').val(), 33 mode = $textarea.attr('data-cm-mode'), 34 maxWidth = $textarea.attr('data-cm-max-width'), 35 minHeight = $textarea.attr('data-cm-min-height'); 36 37 $textarea.codeMirror($.extend({}, options, { 38 mode: mode || mimeTypes[file ? file.split('.').pop() : 'html'] 39 })); 40 41 if (maxWidth) { 42 $($textarea.codeMirrorEditor().display.wrapper).css({maxWidth: maxWidth}); 43 } 44 45 if (minHeight) { 46 $($textarea.codeMirrorEditor().display.scroller).css({minHeight: minHeight}); 47 } 48 }); 49 50 wp_emmet.adaptCodeMirror(); 51 }, 0); 32 $('textarea:not(#content-textarea-clone)').emmet(options, mimeTypes); 33 wp_emmet.adjust(); 34 }, 1); 52 35 }); 53 36 </script> -
wp-emmet/trunk/wp-emmet.php
r952584 r1022794 4 4 Plugin URI: https://github.com/rewish/wp-emmet 5 5 Description: Emmet (ex-Zen Coding) for WordPress. 6 Version: 0. 2.66 Version: 0.3 7 7 Author: rewish 8 8 Author URI: https://github.com/rewish
Note: See TracChangeset
for help on using the changeset viewer.