1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
|
!function(u,p){function h(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}u.Env.ie&&u.Env.ie<9||u.PluginManager.add("wptextpattern",function(s){var f,d=u.util.VK,e=s.settings.wptextpattern||{},t=e.space||[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],l=e.enter||[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"},{regExp:/^(-){3,}$/,element:"hr"}],a=e.inline||[{delimiter:"`",format:"code"}];function c(){var r,i,o,t,d,l,e=s.selection.getRng(),n=e.startContainer,c=e.startOffset;n&&3===n.nodeType&&n.data.length&&c&&(d=n.data.slice(0,c),l=n.data.charAt(c-1),u.each(a,function(e){if(l===e.delimiter.slice(-1)){var t=h(e.delimiter),n=e.delimiter.charAt(0),t=new RegExp("(.*)"+t+".+"+t+"$"),t=d.match(t);if(t){r=t[1].length,i=c-e.delimiter.length;var t=d.charAt(r-1),a=d.charAt(r+e.delimiter.length);if(!(r&&/\S/.test(t)&&(/\s/.test(a)||t===n)||new RegExp("^[\\s"+h(n)+"]+$").test(d.slice(r,i))))return o=e,!1}}}),o&&(e=s.formatter.get(o.format))&&e[0].inline&&(s.undoManager.add(),s.undoManager.transact(function(){n.insertData(c,"\ufeff"),n=n.splitText(r),t=n.splitText(c-r),n.deleteData(0,o.delimiter.length),n.deleteData(n.data.length-o.delimiter.length,o.delimiter.length),s.formatter.apply(o.format,{},n),s.selection.setCursorLocation(t,1)}),p(function(){f="space",s.once("selectionchange",function(){var e;t&&-1!==(e=t.data.indexOf("\ufeff"))&&t.deleteData(e,e+1)})})))}function g(e){var t,n=s.dom.getParent(e,"p");if(n){for(;(t=n.firstChild)&&3!==t.nodeType;)n=t;if(t)return t=t.data?t:t.nextSibling&&3===t.nextSibling.nodeType?t.nextSibling:null}}function m(){var n,a,r=s.selection.getRng(),i=r.startContainer;i&&g(i)===i&&(n=i.parentNode,a=i.data,u.each(t,function(e){var t=a.match(e.regExp);if(t&&r.startOffset===t[0].length)return s.undoManager.add(),s.undoManager.transact(function(){i.deleteData(0,t[0].length),n.innerHTML||n.appendChild(document.createElement("br")),s.selection.setCursorLocation(n),s.execCommand(e.cmd)}),p(function(){f="space"}),!1}))}s.on("selectionchange",function(){f=null}),s.on("keydown",function(e){if((f&&27===e.keyCode||"space"===f&&e.keyCode===d.BACKSPACE)&&(s.undoManager.undo(),e.preventDefault(),e.stopImmediatePropagation()),!d.metaKeyPressed(e))if(e.keyCode===d.ENTER){var t,n,a,r=s.selection.getRng().startContainer,i=g(r),o=l.length;if(i){for(t=i.data;o--;)if(l[o].start){if(0===t.indexOf(l[o].start)){n=l[o];break}}else if(l[o].regExp&&l[o].regExp.test(t)){n=l[o];break}!n||i===r&&u.trim(t)===n.start||s.once("keyup",function(){s.undoManager.add(),s.undoManager.transact(function(){var e;n.format?(s.formatter.apply(n.format,{},i),i.replaceData(0,i.data.length,(e=i.data.slice(n.start.length))?e.replace(/^\s+/,""):"")):n.element&&(a=i.parentNode&&i.parentNode.parentNode)&&a.replaceChild(document.createElement(n.element),i.parentNode)}),p(function(){f="enter"})})}}else e.keyCode===d.SPACEBAR?p(m):47<e.keyCode&&!(91<=e.keyCode&&e.keyCode<=93)&&p(c)},!0)})}(window.tinymce,window.setTimeout);
|