2016-02-23 09:33:27 +01:00
|
|
|
!function(a,b){a.PluginManager.add("wptextpattern",function(c){function d(){function d(a){for(var b,c=q.length;c--;)if(g=q[c],b=a.data.indexOf(g.end),-1!==b)return b}var e,f,g,h,i,k=c.selection.getRng(),l=k.startContainer,n=k.startOffset;3===l.nodeType&&l.data.length&&n&&-1!==a.inArray(r,l.data.charAt(n-1))&&(e=d(l),f=l.data.lastIndexOf(g.end),e!==f&&-1!==f&&(f-e<=g.start.length||-1===l.data.slice(e+g.start.length,f).indexOf(g.start.slice(0,1))&&(h=c.formatter.get(g.format),h&&h[0].inline&&(c.undoManager.add(),c.undoManager.transact(function(){l.insertData(n,"\u200b"),l=l.splitText(e),i=l.splitText(n-e),l.deleteData(0,g.start.length),l.deleteData(l.data.length-g.end.length,g.end.length),c.formatter.apply(g.format,{},l),c.selection.setCursorLocation(i,1)}),b(function(){j="space",m=i})))))}function e(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&&3===b.nextSibling.nodeType?b.nextSibling:null),b}}function f(){var d,f,g=c.selection.getRng(),h=g.startContainer;h&&e(h)===h&&(d=h.parentNode,f=h.data,a.each(o,function(a){var e=f.match(a.regExp);if(e&&g.startOffset===e[0].length)return c.undoManager.add(),c.undoManager.transact(function(){h.deleteData(0,e[0].length),d.innerHTML||d.appendChild(document.createElement("br")),c.selection.setCursorLocation(d),c.execCommand(a.cmd)}),b(function(){j="space"}),!1}))}function g(){var b,d,f=c.selection.getRng(),g=f.startContainer,h=e(g),i=p.length;if(h){for(b=h.data;i--;)if(0===b.indexOf(p[i].start)){d=p[i];break}d&&(h!==g||a.trim(b)!==d.start)&&(k=h,l=d)}}function h(a){return a?a.replace(/^\s+/,""):""}function i(){k&&(c.undoManager.add(),c.undoManager.transact(function(){c.formatter.apply(l.format,{},k),k.replaceData(0,k.data.length,h(k.data.slice(l.start.length)))}),b(function(){j="enter"})),k=null,l=null}var j,k,l,m,n=a.util.VK,o=[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],p=[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"}],q=[{start:"*",end:"*",format:"italic"},{start:"**",end:"**",format:"bold"},{start:"_",end:"_",format:"italic"},{start:"__",end:"__",format:"bold"},{start:"`",end:"`",format:"code"}],r=[];a.each(q,function(b){a.each((b.start+b.end).split(""),function(b){-1===a.inArray(r,b)&&r.push(b)})}),c.on("selectionchange",function(){var a;j=null,m&&(a=m.data.indexOf("\u200b"),-1!==a&&m.deleteData(a,a+1))}),c.on("keydown",function(a){(j&&27===a.keyCode||"space"===j&&a.keyCode===n.BACKSPACE)&&(c.undoManager.undo(),a.preventDefault(),a.stopImmediatePropagation()),a.keyCode!==n.ENTER||n.modifierPressed(a)||g()},!0),c.on("keyup",function(a){a.keyCode!==n.SPACEBAR||a.ctrlKey||a.metaKey||a.altKey?a.keyCode!==n.ENTER||n.modifierPressed(a)?a.keyCode>47&&!(a.keyCode>=91&&a.keyCode<=93)&&d():i():f()})})}(window.tinymce,window.setTimeout);
|