WordPress/wp-includes/js/tinymce/plugins/wptextpattern/plugin.min.js
Ella Iseulde Van Dorpe f78068c152 TinyMCE: wptextpattern: headings on enter
Fixes #31441.

Built from https://develop.svn.wordpress.org/trunk@33452


git-svn-id: http://core.svn.wordpress.org/trunk@33419 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-07-27 23:16:25 +00:00

1 line
1.6 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=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);