mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-04 09:49:37 +01:00
9a1d80e858
See #31441. Built from https://develop.svn.wordpress.org/trunk@33512 git-svn-id: http://core.svn.wordpress.org/trunk@33479 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
1.7 KiB
JavaScript
1 line
1.7 KiB
JavaScript
!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(),i=g.startContainer;i&&d(i)===i&&(e=i.parentNode,f=i.data,a.each(l,function(a){var d=f.match(a.regExp);if(d&&g.startOffset===d[0].length)return c.undoManager.add(),c.undoManager.transact(function(){i.deleteData(0,d[0].length),e.innerHTML||e.appendChild(document.createElement("br")),c.selection.setCursorLocation(e),c.execCommand(a.cmd)}),b(function(){h="space"}),!1}))}function f(){var b,e,f=c.selection,g=f.getRng(),h=g.startOffset,k=g.startContainer,l=d(k),n=m.length;if(l){for(b=l.data;n--;)if(0===b.indexOf(m[n].start)){e=m[n];break}if(e){if(l===k){if(a.trim(b)===e.start)return;h=Math.max(0,h-e.start.length)}i=l,j=e}}}function g(){i&&(c.undoManager.add(),c.undoManager.transact(function(){c.formatter.apply(j.format,{},i),i.deleteData(0,j.start.length)}),b(function(){h="enter"})),i=null,j=null}var h,i,j,k=a.util.VK,l=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],m=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}];c.on("selectionchange",function(){h=null}),c.on("keydown",function(a){(h&&27===a.keyCode||"space"===h&&a.keyCode===k.BACKSPACE)&&(c.undoManager.undo(),a.preventDefault(),a.stopImmediatePropagation()),a.keyCode!==k.ENTER||k.modifierPressed(a)||f()},!0),c.on("keyup",function(a){k.modifierPressed(a)||(a.keyCode===k.SPACEBAR?e():a.keyCode===k.ENTER&&g())})})}(window.tinymce,window.setTimeout); |