1 line
5.3 KiB
JavaScript
1 line
5.3 KiB
JavaScript
!function(r){"use strict";var n,e,t,o,u,i,c=function(n){var e=n,t=function(){return e};return{get:t,set:function(n){e=n},clone:function(){return c(t())}}},a=tinymce.util.Tools.resolve("tinymce.PluginManager"),f=function(n){return{isEnabled:function(){return n.get()}}},d=function(n,e){return n.fire("VisualChars",{state:e})},l={"\xa0":"nbsp","\xad":"shy"},s=function(n,e){var t,r="";for(t in n)r+=t;return new RegExp("["+r+"]",e?"g":"")},m=function(n){var e,t="";for(e in n)t&&(t+=","),t+="span.mce-"+n[e];return t},N={charMap:l,regExp:s(l),regExpGlobal:s(l,!0),selector:m(l),charMapToRegExp:s,charMapToSelector:m},g=function(n){return function(){return n}},E=g(!1),h=g(!0),v=E,p=h,T=function(){return O},O=(o={fold:function(n,e){return n()},is:v,isSome:v,isNone:p,getOr:t=function(n){return n},getOrThunk:e=function(n){return n()},getOrDie:function(n){throw new Error(n||"error: getOrDie called on none.")},getOrNull:function(){return null},getOrUndefined:function(){return undefined},or:t,orThunk:e,map:T,ap:T,each:function(){},bind:T,flatten:T,exists:v,forall:p,filter:T,equals:n=function(n){return n.isNone()},equals_:n,toArray:function(){return[]},toString:g("none()")},Object.freeze&&Object.freeze(o),o),y=function(t){var n=function(){return t},e=function(){return o},r=function(n){return n(t)},o={fold:function(n,e){return e(t)},is:function(n){return t===n},isSome:p,isNone:v,getOr:n,getOrThunk:n,getOrDie:n,getOrNull:n,getOrUndefined:n,or:e,orThunk:e,map:function(n){return y(n(t))},ap:function(n){return n.fold(T,function(n){return y(n(t))})},each:function(n){n(t)},bind:r,flatten:n,exists:r,forall:r,filter:function(n){return n(t)?o:O},equals:function(n){return n.is(t)},equals_:function(n,e){return n.fold(v,function(n){return e(t,n)})},toArray:function(){return[t]},toString:function(){return"some("+t+")"}};return o},D=function(n){return null===n||n===undefined?O:y(n)},_=(u="function",function(n){return function(n){if(null===n)return"null";var e=typeof n;return"object"===e&&(Array.prototype.isPrototypeOf(n)||n.constructor&&"Array"===n.constructor.name)?"array":"object"===e&&(String.prototype.isPrototypeOf(n)||n.constructor&&"String"===n.constructor.name)?"string":e}(n)===u}),C=(Array.prototype.slice,function(n,e){for(var t=0,r=n.length;t<r;t++)e(n[t],t,n)}),w=(_(Array.from)&&Array.from,function(n){if(null===n||n===undefined)throw new Error("Node cannot be null or undefined");return{dom:g(n)}}),M={fromHtml:function(n,e){var t=(e||r.document).createElement("div");if(t.innerHTML=n,!t.hasChildNodes()||1<t.childNodes.length)throw r.console.error("HTML does not have a single root node",n),new Error("HTML must have a single root node");return w(t.childNodes[0])},fromTag:function(n,e){var t=(e||r.document).createElement(n);return w(t)},fromText:function(n,e){var t=(e||r.document).createTextNode(n);return w(t)},fromDom:w,fromPoint:function(n,e,t){var r=n.dom();return D(r.elementFromPoint(e,t)).map(w)}},b=(r.Node.ATTRIBUTE_NODE,r.Node.CDATA_SECTION_NODE,r.Node.COMMENT_NODE,r.Node.DOCUMENT_NODE,r.Node.DOCUMENT_TYPE_NODE,r.Node.DOCUMENT_FRAGMENT_NODE,r.Node.ELEMENT_NODE,r.Node.TEXT_NODE),k=(r.Node.PROCESSING_INSTRUCTION_NODE,r.Node.ENTITY_REFERENCE_NODE,r.Node.ENTITY_NODE,r.Node.NOTATION_NODE,"undefined"!=typeof r.window?r.window:Function("return this;")(),function(n){return n.dom().nodeValue}),S=(i=b,function(n){return n.dom().nodeType===i}),A=function(n){return'<span data-mce-bogus="1" class="mce-'+N.charMap[n]+'">'+n+"</span>"},x=function(n,e){var t=[],r=function(n,e){for(var t=n.length,r=new Array(t),o=0;o<t;o++){var u=n[o];r[o]=e(u,o,n)}return r}(n.dom().childNodes,M.fromDom);return C(r,function(n){e(n)&&(t=t.concat([n])),t=t.concat(x(n,e))}),t},P={isMatch:function(n){return S(n)&&k(n)!==undefined&&N.regExp.test(k(n))},filterDescendants:x,findParentElm:function(n,e){for(;n.parentNode;){if(n.parentNode===e)return n;n=n.parentNode}},replaceWithSpans:function(n){return n.replace(N.regExpGlobal,A)}},R=function(t,n){var r,o,e=P.filterDescendants(M.fromDom(n),P.isMatch);C(e,function(n){var e=P.replaceWithSpans(k(n));for(o=t.dom.create("div",null,e);r=o.lastChild;)t.dom.insertAfter(r,n.dom());t.dom.remove(n.dom())})},I=function(e,n){var t=e.dom.select(N.selector,n);C(t,function(n){e.dom.remove(n,1)})},B=R,U=I,V=function(n){var e=n.getBody(),t=n.selection.getBookmark(),r=P.findParentElm(n.selection.getNode(),e);r=r!==undefined?r:e,I(n,r),R(n,r),n.selection.moveToBookmark(t)},j=function(n,e){var t,r=n.getBody(),o=n.selection;e.set(!e.get()),d(n,e.get()),t=o.getBookmark(),!0===e.get()?B(n,r):U(n,r),o.moveToBookmark(t)},q=function(n,e){n.addCommand("mceVisualChars",function(){j(n,e)})},F=tinymce.util.Tools.resolve("tinymce.util.Delay"),G=function(e,t){var r=F.debounce(function(){V(e)},300);!1!==e.settings.forced_root_block&&e.on("keydown",function(n){!0===t.get()&&(13===n.keyCode?V(e):r())})},H=function(n){return n.getParam("visualchars_default_state",!1)},L=function(e,t){e.on("init",function(){var n=!H(e);t.set(n),j(e,t)})},Y=function(t){return function(n){var e=n.control;t.on("VisualChars",function(n){e.active(n.state)})}};a.add("visualchars",function(n){var e,t=c(!1);return q(n,t),(e=n).addButton("visualchars",{active:!1,title:"Show invisible characters",cmd:"mceVisualChars",onPostRender:Y(e)}),e.addMenuItem("visualchars",{text:"Show invisible characters",cmd:"mceVisualChars",onPostRender:Y(e),selectable:!0,context:"view",prependToContext:!0}),G(n,t),L(n,t),f(t)})}(window); |