Ticket #31441: 31441.2.patch
File 31441.2.patch, 6.2 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-wp-editor.php
368 368 'wplink', 369 369 'wpdialogs', 370 370 'wpview', 371 'wptextpattern' 371 372 ); 372 373 373 374 if ( ! self::$has_medialib ) { -
src/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js
1 ( function( tinymce ) { 2 tinymce.PluginManager.add( 'wptextpattern', function( editor ) { 3 var $$ = editor.$; 4 var patterns = []; 5 6 function add( regExp, callback ) { 7 patterns.push( { 8 regExp: regExp, 9 callback: callback 10 } ); 11 } 12 13 add( /^[*-]\s/, function() { 14 this.execCommand( 'InsertUnorderedList' ); 15 } ); 16 17 add( /^1[.)]\s/, function() { 18 this.execCommand( 'InsertOrderedList' ); 19 } ); 20 21 add( /^>\s/, function() { 22 this.execCommand( 'mceBlockQuote' ); 23 } ); 24 25 editor.on( 'keyup', function( event ) { 26 var node; 27 28 if ( event.keyCode !== tinymce.util.VK.SPACEBAR ) { 29 return; 30 } 31 32 node = editor.selection.getRng().startContainer; 33 34 if ( node.nodeType !== 3 ) { 35 return; 36 } 37 38 tinymce.each( patterns, function( pattern ) { 39 var text = node.nodeValue, 40 replace; 41 42 if ( node.parentNode.firstChild !== node ) { 43 return; 44 } 45 46 replace = text.replace( pattern.regExp, '' ); 47 48 if ( text === replace ) { 49 return; 50 } 51 52 editor.undoManager.transact( function() { 53 $$( node.parentNode ).replaceWith( replace ? document.createTextNode( replace ) : document.createElement( 'BR' ) ); 54 55 pattern.callback.apply( editor ); 56 } ); 57 58 return false; 59 } ); 60 } ); 61 } ); 62 } )( window.tinymce ); -
tests/qunit/editor/js/utils.js
131 131 132 132 // TODO: Replace this with the new event logic in 3.5 133 133 function type(chr) { 134 var editor = tinymce.activeEditor, keyCode, charCode, evt, startElm, rng; 134 var editor = tinymce.activeEditor, keyCode, charCode, evt, startElm, rng, textNode; 135 136 function charCodeToKeyCode(charCode) { 137 var lookup = { 138 '0': 48, '1': 49, '2': 50, '3': 51, '4': 52, '5': 53, '6': 54, '7': 55, '8': 56, '9': 57,'a': 65, 'b': 66, 'c': 67, 139 'd': 68, 'e': 69, 'f': 70, 'g': 71, 'h': 72, 'i': 73, 'j': 74, 'k': 75, 'l': 76, 'm': 77, 'n': 78, 'o': 79, 'p': 80, 'q': 81, 140 'r': 82, 's': 83, 't': 84, 'u': 85, 'v': 86, 'w': 87, 'x': 88, 'y': 89, ' ': 32, ',': 188, '-': 189, '.': 190, '/': 191, '\\': 220, 141 '[': 219, ']': 221, '\'': 222, ';': 186, '=': 187, ')': 41 142 }; 143 144 return lookup[String.fromCharCode(charCode)]; 145 } 135 146 136 147 function fakeEvent(target, type, evt) { 137 148 editor.dom.fire(target, type, evt); … … 139 150 140 151 // Numeric keyCode 141 152 if (typeof(chr) == "number") { 142 charCode = keyCode = chr; 153 charCode = chr; 154 keyCode = charCodeToKeyCode(charCode); 143 155 } else if (typeof(chr) == "string") { 144 156 // String value 145 157 if (chr == '\b') { … … 150 162 charCode = chr.charCodeAt(0); 151 163 } else { 152 164 charCode = chr.charCodeAt(0); 153 keyCode = charCode ;165 keyCode = charCodeToKeyCode(charCode); 154 166 } 155 167 } else { 156 168 evt = chr; 169 170 if (evt.charCode) { 171 chr = String.fromCharCode(evt.charCode); 172 } 173 174 if (evt.keyCode) { 175 keyCode = evt.keyCode; 176 } 157 177 } 158 178 159 179 evt = evt || {keyCode: keyCode, charCode: charCode}; … … 196 216 if (rng.startContainer.nodeType == 3 && rng.collapsed) { 197 217 rng.startContainer.insertData(rng.startOffset, chr); 198 218 rng.setStart(rng.startContainer, rng.startOffset + 1); 199 rng.collapse(true);200 editor.selection.setRng(rng);201 219 } else { 202 rng.insertNode(editor.getDoc().createTextNode(chr)); 220 textNode = editor.getDoc().createTextNode(chr); 221 rng.insertNode(textNode); 222 rng.setStart(textNode, 1); 203 223 } 224 225 rng.collapse(true); 226 editor.selection.setRng(rng); 204 227 } 205 228 } 206 229 -
tests/qunit/index.html
39 39 <script src="wp-includes/js/shortcode.js"></script> 40 40 <script src="wp-admin/js/customize-controls.js"></script> 41 41 <script src="wp-admin/js/customize-controls-utils.js"></script> 42 43 <!-- TinyMCE --> 44 45 <script src="../../src/wp-includes/js/tinymce/tinymce.js"></script> 46 47 <script src="editor/js/utils.js"></script> 48 49 <script src="wp-includes/js/tinymce/plugins/wptextpattern/plugin.js"></script> 50 42 51 </body> 43 52 </html> -
tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js
1 ( function( $, _type ) { 2 3 var editor; 4 5 function type( string ) { 6 tinymce.each( string.split( '' ), _type ); 7 } 8 9 module( 'tinymce.plugins.wptextpattern', { 10 beforeEach: function() { 11 stop(); 12 13 $( '#qunit-fixture' ).append( '<textarea id="editor">' ); 14 15 tinymce.init( { 16 selector: '#editor', 17 plugins: 'wptextpattern', 18 init_instance_callback: function() { 19 editor = arguments[0]; 20 editor.focus(); 21 start(); 22 } 23 } ); 24 }, 25 afterEach: function( assert ) { 26 editor.remove(); 27 } 28 } ); 29 30 test( 'unordered list', function() { 31 type( '* ' ); 32 equal( editor.getContent(), '<ul>\n<li></li>\n</ul>' ); 33 } ); 34 35 test( 'ordered list', function() { 36 type( '1. ' ); 37 equal( editor.getContent(), '<ol>\n<li></li>\n</ol>' ); 38 } ); 39 40 test( 'ordered list with text', function() { 41 type( 'test' ); 42 editor.selection.setCursorLocation(); 43 type( '1. ' ); 44 equal( editor.getContent(), '<ol>\n<li>test</li>\n</ol>' ); 45 } ); 46 47 } )( window.jQuery, window.Utils.type );