plugin.min.js 6.2KB

1
  1. !function(){"use strict";var n,e,t,r,o=function(n){var e=n,t=function(){return e};return{get:t,set:function(n){e=n},clone:function(){return o(t())}}},u=tinymce.util.Tools.resolve("tinymce.PluginManager"),i=function(n){return{isEnabled:function(){return n.get()}}},c=function(n,e){return n.fire("VisualChars",{state:e})},a={"\xa0":"nbsp","\xad":"shy"},f=function(n,e){var t,r="";for(t in n)r+=t;return new RegExp("["+r+"]",e?"g":"")},l=function(n){var e,t="";for(e in n)t&&(t+=","),t+="span.mce-"+n[e];return t},s={charMap:a,regExp:f(a),regExpGlobal:f(a,!0),selector:l(a),charMapToRegExp:f,charMapToSelector:l},d=function(n){return function(){return n}},m=d(!1),p=d(!0),v={noop:function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e]},noarg:function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t()}},compose:function(t,r){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(r.apply(null,arguments))}},constant:d,identity:function(n){return n},tripleEquals:function(n,e){return n===e},curry:function(u){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];for(var i=new Array(arguments.length-1),t=1;t<arguments.length;t++)i[t-1]=arguments[t];return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];for(var t=new Array(arguments.length),r=0;r<t.length;r++)t[r]=arguments[r];var o=i.concat(t);return u.apply(null,o)}},not:function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(null,arguments)}},die:function(n){return function(){throw new Error(n)}},apply:function(n){return n()},call:function(n){n()},never:m,always:p},h=v.never,g=v.always,y=function(){return b},b=(r={fold:function(n,e){return n()},is:h,isSome:h,isNone:g,getOr:t=function(n){return n},getOrThunk:e=function(n){return n()},getOrDie:function(n){throw new Error(n||"error: getOrDie called on none.")},or:t,orThunk:e,map:y,ap:y,each:function(){},bind:y,flatten:y,exists:h,forall:g,filter:y,equals:n=function(n){return n.isNone()},equals_:n,toArray:function(){return[]},toString:v.constant("none()")},Object.freeze&&Object.freeze(r),r),T=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:g,isNone:h,getOr:n,getOrThunk:n,getOrDie:n,or:e,orThunk:e,map:function(n){return T(n(t))},ap:function(n){return n.fold(y,function(n){return T(n(t))})},each:function(n){n(t)},bind:r,flatten:n,exists:r,forall:r,filter:function(n){return n(t)?o:b},equals:function(n){return n.is(t)},equals_:function(n,e){return n.fold(h,function(n){return e(t,n)})},toArray:function(){return[t]},toString:function(){return"some("+t+")"}};return o},w={some:T,none:y,from:function(n){return null===n||n===undefined?b:T(n)}},x=function(e){return function(n){return function(n){if(null===n)return"null";var e=typeof n;return"object"===e&&Array.prototype.isPrototypeOf(n)?"array":"object"===e&&String.prototype.isPrototypeOf(n)?"string":e}(n)===e}},E={isString:x("string"),isObject:x("object"),isArray:x("array"),isNull:x("null"),isBoolean:x("boolean"),isUndefined:x("undefined"),isFunction:x("function"),isNumber:x("number")},N=(Array.prototype.indexOf,undefined,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}),k=function(n,e){for(var t=0,r=n.length;t<r;t++)e(n[t],t,n)},A=(Array.prototype.push,Array.prototype.slice,E.isFunction(Array.from)&&Array.from,N),O=k,C=function(n){if(null===n||n===undefined)throw new Error("Node cannot be null or undefined");return{dom:v.constant(n)}},M={fromHtml:function(n,e){var t=(e||document).createElement("div");if(t.innerHTML=n,!t.hasChildNodes()||1<t.childNodes.length)throw console.error("HTML does not have a single root node",n),"HTML must have a single root node";return C(t.childNodes[0])},fromTag:function(n,e){var t=(e||document).createElement(n);return C(t)},fromText:function(n,e){var t=(e||document).createTextNode(n);return C(t)},fromDom:C,fromPoint:function(n,e,t){return w.from(n.dom().elementFromPoint(e,t)).map(C)}},S=8,D=9,P=3,B=function(n){return n.dom().nodeName.toLowerCase()},j=function(n){return n.dom().nodeType},V=function(e){return function(n){return j(n)===e}},q=V(1),H=V(P),L=V(D),R={name:B,type:j,value:function(n){return n.dom().nodeValue},isElement:q,isText:H,isDocument:L,isComment:function(n){return j(n)===S||"#comment"===B(n)}},_=function(n){return'<span data-mce-bogus="1" class="mce-'+s.charMap[n]+'">'+n+"</span>"},F=function(n,e){var t=[],r=n.dom(),o=A(r.childNodes,M.fromDom);return O(o,function(n){e(n)&&(t=t.concat([n])),t=t.concat(F(n,e))}),t},z={isMatch:function(n){return R.isText(n)&&R.value(n)!==undefined&&s.regExp.test(R.value(n))},filterDescendants:F,findParentElm:function(n,e){for(;n.parentNode;){if(n.parentNode===e)return n;n=n.parentNode}},replaceWithSpans:function(n){return n.replace(s.regExpGlobal,_)}},G=function(t,n){var r,o,e=z.filterDescendants(M.fromDom(n),z.isMatch);O(e,function(n){var e=z.replaceWithSpans(R.value(n));for(o=t.dom.create("div",null,e);r=o.lastChild;)t.dom.insertAfter(r,n.dom());t.dom.remove(n.dom())})},W=function(e,n){var t=e.dom.select(s.selector,n);O(t,function(n){e.dom.remove(n,1)})},I=G,U=W,J=function(n){var e=n.getBody(),t=n.selection.getBookmark(),r=z.findParentElm(n.selection.getNode(),e);r=r!==undefined?r:e,W(n,r),G(n,r),n.selection.moveToBookmark(t)},K=function(n,e){var t,r=n.getBody(),o=n.selection;e.set(!e.get()),c(n,e.get()),t=o.getBookmark(),!0===e.get()?I(n,r):U(n,r),o.moveToBookmark(t)},Q=function(n,e){n.addCommand("mceVisualChars",function(){K(n,e)})},X=tinymce.util.Tools.resolve("tinymce.util.Delay"),Y=function(e,t){var r=X.debounce(function(){J(e)},300);!1!==e.settings.forced_root_block&&e.on("keydown",function(n){!0===t.get()&&(13===n.keyCode?J(e):r())})},Z=function(t){return function(n){var e=n.control;t.on("VisualChars",function(n){e.active(n.state)})}};u.add("visualchars",function(n){var e,t=o(!1);return Q(n,t),(e=n).addButton("visualchars",{active:!1,title:"Show invisible characters",cmd:"mceVisualChars",onPostRender:Z(e)}),e.addMenuItem("visualchars",{text:"Show invisible characters",cmd:"mceVisualChars",onPostRender:Z(e),selectable:!0,context:"view",prependToContext:!0}),Y(n,t),i(t)})}();