forked from extern/egroupware
1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
!function(){"use strict";var n,t,e,r,o,i=tinymce.util.Tools.resolve("tinymce.PluginManager"),u=tinymce.util.Tools.resolve("tinymce.util.VK"),a=function(n){return n.target_list},c=function(n){return n.rel_list},l=function(n){return n.link_class_list},h=function(n){return"boolean"==typeof n.link_assume_external_targets&&n.link_assume_external_targets},f=function(n){return n.link_list},p=function(n){return"string"==typeof n.default_link_target},v=function(n){return n.default_link_target},s=a,g=function(n){return!1!==a(n)},d=c,m=function(n){return c(n)!==undefined},y=l,x=function(n){return l(n)!==undefined},k=function(n){return!1!==n.link_title},b=function(n){return"boolean"==typeof n.allow_unsafe_link_target&&n.allow_unsafe_link_target},O=function(n){return!0===n.link_quicklink},w=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),_=tinymce.util.Tools.resolve("tinymce.Env"),A=function(n){if(!_.ie||10<_.ie){var t=document.createElement("a");t.target="_blank",t.href=n,t.rel="noreferrer noopener";var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),i=t,u=e,document.body.appendChild(i),i.dispatchEvent(u),document.body.removeChild(i)}else{var r=window.open("","_blank");if(r){r.opener=null;var o=r.document;o.open(),o.write('<meta http-equiv="refresh" content="0; url='+w.DOM.encode(n)+'">'),o.close()}}var i,u},T=tinymce.util.Tools.resolve("tinymce.util.Tools"),C=function(n,t){var e,r,o=["noopener"],i=n?n.split(/\s+/):[],u=function(n){return n.filter(function(n){return-1===T.inArray(o,n)})};return(i=t?(e=u(e=i)).length?e.concat(o):o:u(i)).length?(r=i,T.trim(r.sort().join(" "))):null},N=function(n,t){return t=t||n.selection.getNode(),D(t)?n.dom.select("a[href]",t)[0]:n.dom.getParent(t,"a[href]")},S=function(n){return n&&"A"===n.nodeName&&n.href},D=function(n){return n&&"FIGURE"===n.nodeName&&/\bimage\b/i.test(n.className)},M=function(n,t){var e,r;(r=n.dom.select("img",t)[0])&&(e=n.dom.getParents(r,"a[href]",t)[0])&&(e.parentNode.insertBefore(r,e),n.dom.remove(e))},z=function(n,t,e){var r,o;(o=n.dom.select("img",t)[0])&&(r=n.dom.create("a",e),o.parentNode.insertBefore(r,o),r.appendChild(o))},U=function(o,i){return function(r){o.undoManager.transact(function(){var n=o.selection.getNode(),t=N(o,n),e={href:r.href,target:r.target?r.target:null,rel:r.rel?r.rel:null,"class":r["class"]?r["class"]:null,title:r.title?r.title:null};m(o.settings)||!1!==b(o.settings)||(e.rel=C(e.rel,"_blank"===e.target)),r.href===i.href&&(i.attach(),i={}),t?(o.focus(),r.hasOwnProperty("text")&&("innerText"in t?t.innerText=r.text:t.textContent=r.text),o.dom.setAttribs(t,e),o.selection.select(t),o.undoManager.add()):D(n)?z(o,n,e):r.hasOwnProperty("text")?o.insertContent(o.dom.createHTML("a",e,o.dom.encode(r.text))):o.execCommand("mceInsertLink",!1,e)})}},E=function(t){return function(){t.undoManager.transact(function(){var n=t.selection.getNode();D(n)?M(t,n):t.execCommand("unlink")})}},P=function(n){return 0<T.grep(n,S).length},L=function(n){return!(/</.test(n)&&(!/^<a [^>]+>[^<]+<\/a>$/.test(n)||-1===n.indexOf("href=")))},R=N,K=function(n,t){var e=t?t.innerText||t.textContent:n.getContent({format:"text"});return e.replace(/\uFEFF/g,"")},q=C,j=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t]},I=function(n){return function(){return n}},V=I(!1),B=I(!0),F=V,W=B,H=function(){return $},$=(r={fold:function(n,t){return n()},is:F,isSome:F,isNone:W,getOr:e=function(n){return n},getOrThunk:t=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:e,orThunk:t,map:H,ap:H,each:function(){},bind:H,flatten:H,exists:F,forall:W,filter:H,equals:n=function(n){return n.isNone()},equals_:n,toArray:function(){return[]},toString:I("none()")},Object.freeze&&Object.freeze(r),r),G=function(e){var n=function(){return e},t=function(){return o},r=function(n){return n(e)},o={fold:function(n,t){return t(e)},is:function(n){return e===n},isSome:W,isNone:F,getOr:n,getOrThunk:n,getOrDie:n,getOrNull:n,getOrUndefined:n,or:t,orThunk:t,map:function(n){return G(n(e))},ap:function(n){return n.fold(H,function(n){return G(n(e))})},each:function(n){n(e)},bind:r,flatten:n,exists:r,forall:r,filter:function(n){return n(e)?o:$},equals:function(n){return n.is(e)},equals_:function(n,t){return n.fold(F,function(n){return t(e,n)})},toArray:function(){return[e]},toString:function(){return"some("+e+")"}};return o},J={some:G,none:H,from:function(n){return null===n||n===undefined?$:G(n)}},X=function(t){return function(n){return function(n){if(null===n)return"null";var t=typeof n;return"object"===t&&Array.prototype.isPrototypeOf(n)?"array":"object"===t&&String.prototype.isPrototypeOf(n)?"string":t}(n)===t}},Q=X("string"),Y=X("function"),Z=(o=Array.prototype.indexOf)===undefined?function(n,t){return nn(n,t)}:function(n,t){return o.call(n,t)},nn=function(n,t){for(var e=0,r=n.length;e<r;++e)if(n[e]===t)return e;return-1},tn=Array.prototype.push,en=function(n){for(var t=[],e=0,r=n.length;e<r;++e){if(!Array.prototype.isPrototypeOf(n[e]))throw new Error("Arr.flatten item "+e+" was not an array, input: "+n);tn.apply(t,n[e])}return t},rn=function(n,t){var e=function(n,t){for(var e=n.length,r=new Array(e),o=0;o<e;o++){var i=n[o];r[o]=t(i,o,n)}return r}(n,t);return en(e)},on=(Array.prototype.slice,Y(Array.from)&&Array.from,function(n,t){for(var e=0;e<n.length;e++){var r=t(n[e],e);if(r.isSome())return r}return J.none()}),un=function(n){return Q(n.value)?n.value:""},an=function(n,o){var i=[];return T.each(n,function(n){var t=Q(n.text)?n.text:Q(n.title)?n.title:"";if(n.menu!==undefined){var e=an(n.menu,o);i.push({text:t,items:e})}else{var r=o(n);i.push({text:t,value:r})}}),i},cn=function(t){return void 0===t&&(t=un),function(n){return J.from(n).map(function(n){return an(n,t)})}},ln={sanitize:function(n){return cn(un)(n)},sanitizeWith:cn,createUi:function(t,e){return function(n){return{name:t,type:"selectbox",label:e,items:n}}},getValue:un},fn=function(n){var t=n,e=function(){return t};return{get:e,set:function(n){t=n},clone:function(){return fn(e())}}},sn=function(t,n){return on(n,function(n){return"items"in n?sn(t,n.items):J.some(n).filter(function(n){return n.value===t})})},gn=function(n,t,e,r){var o=r[t],i=r.text,u=""===i||n===i;return o!==undefined?sn(o,e).map(function(n){return{url:{value:n.value,meta:{text:u?n.text:i,attach:j}},text:u?n.text:i}}):J.none()},dn=function(n,u){var a=fn(n.text),o=function(n,t){var e,r,o=(e=u,r=t.name,"link"===r?e.catalogs.link:"anchor"===r?e.catalogs.anchor:J.none()).getOr([]),i=gn(a.get(),t.name,o,n);return i.each(function(n){a.set(n.text)}),i};return{onChange:function(n,t){return"url"===t.name?function(n){if(n.text===a.get()||n.text!==undefined&&0===n.text.length){var t=n.url.meta.text!==undefined?n.url.meta.text:n.url.value;return a.set(t),J.some({text:a.get()})}return J.none()}(n()):(e=["anchor","link"],r=t.name,-1<Z(e,r)?o(n(),t):J.none());var e,r}}},mn=function(n){var e=J.none(),t=[],r=function(n){o()?u(n):t.push(n)},o=function(){return e.isSome()},i=function(n){!function(n,t){for(var e=0,r=n.length;e<r;e++)t(n[e],e,n)}(n,u)},u=function(t){e.each(function(n){setTimeout(function(){t(n)},0)})};return n(function(n){e=J.some(n),i(t),t=[]}),{get:r,map:function(e){return mn(function(t){r(function(n){t(e(n))})})},isReady:o}},hn={nu:mn,pure:function(t){return mn(function(n){n(t)})}},pn=function(t){var n=function(n){var r;t((r=n,function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=this;setTimeout(function(){r.apply(e,n)},0)}))},e=function(){return hn.nu(n)};return{map:function(r){return pn(function(e){n(function(n){var t=r(n);e(t)})})},bind:function(e){return pn(function(t){n(function(n){e(n).get(t)})})},anonBind:function(e){return pn(function(t){n(function(n){e.get(t)})})},toLazy:e,toCached:function(){var t=null;return pn(function(n){null===t&&(t=e()),t.get(n)})},get:n}},vn={nu:pn,pure:function(t){return pn(function(n){n(t)})}},yn=tinymce.util.Tools.resolve("tinymce.util.Delay"),xn=undefined&&undefined.__assign||Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},kn=function(n){var t=n.href;return 0<t.indexOf("@")&&-1===t.indexOf("//")&&-1===t.indexOf("mailto:")?J.some({message:"The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?",preprocess:function(n){return xn({},n,{href:"mailto:"+t})}}):J.none()},bn=function(u,n,a){return console.log("preprocessing"),on([kn,(e=n,function(n){var t=n.href;return!0===e&&!/^\w+:/i.test(t)||!1===e&&/^\s*www[\.|\d\.]/i.test(t)?J.some({message:"The URL you entered seems to be an external link. Do you want to add the required http:// prefix?",preprocess:function(n){return xn({},n,{href:"http://"+t})}}):J.none()})],function(n){return n(a)}).fold(function(){return vn.pure(a)},function(i){return vn.nu(function(t){var e,n,r,o;e=u,n=i.message,r=function(n){console.log("state",n),t(n?i.preprocess(a):a)},o=e.selection.getRng(),yn.setEditorTimeout(e,function(){e.windowManager.confirm(n,function(n){e.selection.setRng(o),r(n)})})})});var e},On=function(n){var t=n.dom.select("a:not([href])"),e=rn(t,function(n){var t=n.name||n.id;return t?[{text:t,value:"#"+t}]:[]});return 0<e.length?J.some([{text:"None",value:""}].concat(e)):J.none()},wn=function(n){if(x(n.settings)){var t=y(n.settings);return ln.sanitize(t)}return J.none()},_n=tinymce.util.Tools.resolve("tinymce.util.XHR"),An=function(t){var e=function(n){return t.convertURL(n.value||n.url,"href")},n=f(t.settings);return vn.nu(function(t){"string"==typeof n?_n.send({url:n,success:function(n){return t(function(n){try{return J.some(JSON.parse(n))}catch(t){return J.none()}}(n))},error:function(n){return t(J.none())}}):"function"==typeof n?n(function(n){return t(J.some(n))}):t(J.from(n))}).map(function(n){return n.bind(ln.sanitizeWith(e))})},Tn=function(n,t){if(m(n.settings)){var e=d(n.settings),r=t.is("_blank");return(!1===b(n.settings)?ln.sanitizeWith(function(n){return q(ln.getValue(n),r)}):ln.sanitize)(e)}return J.none()},Cn=[{text:"None",value:""},{text:"New window",value:"_blank"}],Nn=function(n){if(g(n.settings)){var t=s(n.settings);return ln.sanitize(t).orThunk(function(){return J.some(Cn)})}return J.none()},Sn=function(n,t,e){var r=n.getAttrib(t,e);return null!==r&&0<r.length?J.some(r):J.none()},Dn=function(d,m,h){return An(d).map(function(n){var t,e,r,o,i,u,a,c,l,f,s,g=(e=m,r=h,o=(t=d).selection,i=t.dom,u=L(o.getContent())?J.some(K(o,r)):J.none(),a=r?J.some(i.getAttrib(r,"href")):J.none(),c=p(e)?J.some(v(e)):J.none(),l=r?J.from(i.getAttrib(r,"target")):c,f=Sn(i,r,"rel"),s=Sn(i,r,"class"),{url:a,text:u,title:Sn(i,r,"title"),target:l,rel:f,linkClass:s});return{anchor:g,catalogs:{targets:Nn(d),rels:Tn(d,g.target),classes:wn(d),anchor:On(d),link:n},optNode:J.from(h),flags:{titleEnabled:k(m)}}})},Mn=function(m){var n,t,e;(t=(n=m).settings,e=R(n),Dn(n,t,e)).map(function(n){var u,a,c,l,t,e,r,o,i,f,s,g,d=(u=m,c=(a=n).anchor.text,l=h(m.settings),function(n){var t=n.getData(),e={href:t.url.value,text:t.text?t.text:c.getOr(undefined),target:t.target?t.target:undefined,rel:t.rel?t.rel:undefined,"class":t.classz?t.classz:undefined,title:t.title?t.title:undefined};console.log("resultData",e,c.getOr("<none>"));var r={href:t.url.value,attach:t.url.meta!==undefined&&t.url.meta.attach?t.url.meta.attach:function(){}},o=U(u,r),i=E(u);t.url.value?((c.is(t.text)||a.optNode.isNone()&&!t.text)&&delete e.text,console.log("result data",e),bn(u,l,e).get(function(n){console.log("preprocessed",n),o(n)}),n.close()):i()});return e=d,o=(t=n).anchor.text.map(function(){return{name:"text",type:"input",label:"Text to display"}}).toArray(),i=t.flags.titleEnabled?[{name:"title",type:"input",label:"Title"}]:[],f={url:{value:(r=t).anchor.url.getOr(""),meta:{attach:function(){},text:r.anchor.text.getOr(""),original:{value:r.anchor.url.getOr("")}}},text:r.anchor.text.getOr(""),title:r.anchor.title.getOr(""),anchor:r.anchor.url.getOr(""),link:r.anchor.url.getOr(""),rel:r.anchor.rel.getOr(""),target:r.anchor.target.getOr(""),classz:r.anchor.linkClass.getOr("")},s=dn(f,t),g=t.catalogs,{title:"Insert link",size:"normal",body:{type:"panel",items:en([[{name:"url",type:"urlinput",filetype:"file",label:"Url"}],o,i,function(n){for(var t=[],e=function(n){t.push(n)},r=0;r<n.length;r++)n[r].each(e);return t}([g.anchor.map(ln.createUi("anchor","Anchors")),g.rels.map(ln.createUi("rel","Rel")),g.targets.map(ln.createUi("target","Targets")),g.link.map(ln.createUi("link","Link list")),g.classes.map(ln.createUi("classz","Class"))])])},buttons:[{type:"submit",name:"ok",text:"Ok",primary:!0},{type:"cancel",name:"cancel",text:"Cancel"}],initialData:f,onChange:function(t,n){var e=n.name;s.onChange(t.getData,{name:e}).each(function(n){t.setData(n)})},onSubmit:e}}).get(function(n){m.windowManager.open(n)})},zn=function(n,t){return n.dom.getParent(t,"a[href]")},Un=function(n){return zn(n,n.selection.getStart())},En=function(n,t){if(t){var e=(o=t).getAttribute("data-mce-href")||o.getAttribute("href");if(/^#/.test(e)){var r=n.$(e);r.length&&n.selection.scrollIntoView(r[0],!0)}else A(t.href)}var o},Pn=function(n){return function(){Mn(n)}},Ln=function(n){return function(){En(n,Un(n))}},Rn=function(r){r.on("click",function(n){var t=zn(r,n.target);t&&u.metaKeyPressed(n)&&(n.preventDefault(),En(r,t))}),r.on("keydown",function(n){var t,e=Un(r);e&&13===n.keyCode&&!0===(t=n).altKey&&!1===t.shiftKey&&!1===t.ctrlKey&&!1===t.metaKey&&(n.preventDefault(),En(r,e))})},Kn=function(e){return function(t){var n=function(n){return t.setActive(!e.readonly&&!!R(e,n.element))};return e.on("nodechange",n),function(){return e.off("nodechange",n)}}},qn=function(e){return function(t){t.setDisabled(!P(e.dom.getParents(e.selection.getStart())));var n=function(n){return t.setDisabled(!P(n.parents))};return e.on("nodechange",n),function(){return e.off("nodechange",n)}}},jn=function(n){n.addCommand("mceLink",function(){O(n.settings)?n.fire("contexttoolbar-show",{toolbarKey:"link-form"}):Pn(n)()})},In=function(n){n.addShortcut("Meta+K","",function(){n.execCommand("mceLink")})},Vn=function(n){n.ui.registry.addToggleButton("link",{icon:"link",tooltip:"Link",onAction:Pn(n),onSetup:Kn(n)}),n.ui.registry.addButton("unlink",{icon:"unlink",onAction:E(n),onSetup:qn(n)})},Bn=function(n){n.ui.registry.addMenuItem("openlink",{text:"Open link",icon:"new-tab",onAction:Ln(n),onSetup:qn(n)}),n.ui.registry.addMenuItem("link",{icon:"link",text:"Link",shortcut:"Meta+K",onAction:Pn(n)}),n.ui.registry.addMenuItem("unlink",{icon:"unlink",text:"Remove link",onAction:E(n),onSetup:qn(n)})},Fn=function(t){var e=["link"],r=["link","unlink","openlink"];t.ui.registry.addContextMenu("link",{update:function(n){return P(t.dom.getParents(n,"a"))?r:e}})},Wn=function(i){i.ui.registry.addContextForm("link-form",{launch:{type:"contextformtogglebutton",icon:"link",onSetup:Kn(i)},label:"Link",predicate:function(n){return!!R(i,n)},initValue:function(){return R(i)||""},commands:[{type:"contextformtogglebutton",icon:"link",primary:!0,onSetup:function(n){var t=i.selection.getNode();return n.setActive(!!R(i,t)),Kn(i)(n)},onAction:function(n){var t=R(i),e=n.getValue();if(t)i.dom.setAttrib(t,"href",e),i.selection.collapse(!1),n.hide();else{var r={href:e,attach:function(){}},o=L(i.selection.getContent())?J.some(K(i.selection,t)).filter(function(n){return 0<n.length}):J.none();U(i,r)({href:e,text:o.getOr(e)}),n.hide()}}},{type:"contextformtogglebutton",icon:"unlink",active:!1,onSetup:function(){return function(){}},onAction:function(n){E(i)(),n.hide()}}]})};i.add("link",function(n){Vn(n),Bn(n),Fn(n),Wn(n),Rn(n),jn(n),In(n)}),function Hn(){}}(); |