TinyMCE: wptextpattern: fix typo and make it faster
See #31441. Built from https://develop.svn.wordpress.org/trunk@33458 git-svn-id: http://core.svn.wordpress.org/trunk@33425 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ca038394e9
commit
974c1533ea
|
@ -12,8 +12,7 @@
|
|||
*/
|
||||
( function( tinymce, setTimeout ) {
|
||||
tinymce.PluginManager.add( 'wptextpattern', function( editor ) {
|
||||
var $$ = editor.$,
|
||||
VK = tinymce.util.VK,
|
||||
var VK = tinymce.util.VK,
|
||||
canUndo = false,
|
||||
spacePatterns = [
|
||||
{ regExp: /^[*-]\s/, cmd: 'InsertUnorderedList' },
|
||||
|
@ -44,7 +43,7 @@
|
|||
}, true );
|
||||
|
||||
editor.on( 'keyup', function( event ) {
|
||||
if ( event.keyCode === VK.SPACEBAR || ! VK.modifierPressed( event ) ) {
|
||||
if ( event.keyCode === VK.SPACEBAR && ! VK.modifierPressed( event ) ) {
|
||||
space();
|
||||
}
|
||||
} );
|
||||
|
@ -79,41 +78,30 @@
|
|||
function space() {
|
||||
var rng = editor.selection.getRng(),
|
||||
node = rng.startContainer,
|
||||
parent,
|
||||
text;
|
||||
|
||||
if ( firstNode( node ) !== node ) {
|
||||
if ( ! node || firstNode( node ) !== node ) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent = node.parentNode;
|
||||
text = node.data;
|
||||
|
||||
tinymce.each( spacePatterns, function( pattern ) {
|
||||
var replace = text.replace( pattern.regExp, '' );
|
||||
var match = text.match( pattern.regExp );
|
||||
|
||||
if ( text === replace ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( rng.startOffset !== text.length - replace.length ) {
|
||||
if ( ! match || rng.startOffset !== match[0].length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
editor.undoManager.add();
|
||||
|
||||
editor.undoManager.transact( function() {
|
||||
var parent = node.parentNode,
|
||||
$$parent;
|
||||
node.deleteData( 0, match[0].length );
|
||||
|
||||
if ( replace ) {
|
||||
$$( node ).replaceWith( document.createTextNode( replace ) );
|
||||
} else {
|
||||
$$parent = $$( parent );
|
||||
|
||||
$$( node ).remove();
|
||||
|
||||
if ( ! $$parent.html() ) {
|
||||
$$parent.append( '<br>' );
|
||||
}
|
||||
if ( ! parent.innerHTML ) {
|
||||
parent.appendChild( document.createElement( 'br' ) );
|
||||
}
|
||||
|
||||
editor.selection.setCursorLocation( parent );
|
||||
|
|
|
@ -1 +1 @@
|
|||
!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a){var b,d=c.dom.getParent(a,"p");if(d){for(;(b=d.firstChild)&&3!==b.nodeType;)d=b;if(b)return b.data||(b=b.nextSibling),b}}function e(){var e,f=c.selection.getRng(),h=f.startContainer;d(h)===h&&(e=h.data,a.each(j,function(a){var d=e.replace(a.regExp,"");if(e!==d&&f.startOffset===e.length-d.length)return c.undoManager.add(),c.undoManager.transact(function(){var b,e=h.parentNode;d?g(h).replaceWith(document.createTextNode(d)):(b=g(e),g(h).remove(),b.html()||b.append("<br>")),c.selection.setCursorLocation(e),c.execCommand(a.cmd)}),b(function(){i=!0}),!1}))}function f(){var b,e,f=c.selection,g=f.getRng(),h=g.startOffset,i=g.startContainer,j=d(i),l=k.length;if(j){for(b=j.data;l--;)if(0===b.indexOf(k[l].start)){e=k[l];break}if(e){if(j===i){if(a.trim(b)===e.start)return;h=Math.max(0,h-e.start.length)}c.undoManager.add(),c.undoManager.transact(function(){j.deleteData(0,e.start.length),c.formatter.apply(e.format,{},i),g.setStart(i,h),g.collapse(!0),f.setRng(g)})}}}var g=c.$,h=a.util.VK,i=!1,j=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],k=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}];c.on("selectionchange",function(){i=!1}),c.on("keydown",function(a){!i||a.keyCode!==h.BACKSPACE&&27!==a.keyCode||(c.undoManager.undo(),a.preventDefault()),a.keyCode!==h.ENTER||h.modifierPressed(a)||f()},!0),c.on("keyup",function(a){a.keyCode!==h.SPACEBAR&&h.modifierPressed(a)||e()})})}(window.tinymce,window.setTimeout);
|
||||
!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(a){var b,d=c.dom.getParent(a,"p");if(d){for(;(b=d.firstChild)&&3!==b.nodeType;)d=b;if(b)return b.data||(b=b.nextSibling),b}}function e(){var e,f,g=c.selection.getRng(),j=g.startContainer;j&&d(j)===j&&(e=j.parentNode,f=j.data,a.each(i,function(a){var d=f.match(a.regExp);if(d&&g.startOffset===d[0].length)return c.undoManager.add(),c.undoManager.transact(function(){j.deleteData(0,d[0].length),e.innerHTML||e.appendChild(document.createElement("br")),c.selection.setCursorLocation(e),c.execCommand(a.cmd)}),b(function(){h=!0}),!1}))}function f(){var b,e,f=c.selection,g=f.getRng(),h=g.startOffset,i=g.startContainer,k=d(i),l=j.length;if(k){for(b=k.data;l--;)if(0===b.indexOf(j[l].start)){e=j[l];break}if(e){if(k===i){if(a.trim(b)===e.start)return;h=Math.max(0,h-e.start.length)}c.undoManager.add(),c.undoManager.transact(function(){k.deleteData(0,e.start.length),c.formatter.apply(e.format,{},i),g.setStart(i,h),g.collapse(!0),f.setRng(g)})}}}var g=a.util.VK,h=!1,i=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],j=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}];c.on("selectionchange",function(){h=!1}),c.on("keydown",function(a){!h||a.keyCode!==g.BACKSPACE&&27!==a.keyCode||(c.undoManager.undo(),a.preventDefault()),a.keyCode!==g.ENTER||g.modifierPressed(a)||f()},!0),c.on("keyup",function(a){a.keyCode!==g.SPACEBAR||g.modifierPressed(a)||e()})})}(window.tinymce,window.setTimeout);
|
Binary file not shown.
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-beta4-33457';
|
||||
$wp_version = '4.3-beta4-33458';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue