mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-11 17:20:53 +01:00
1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
!function(){"use strict";var n,e,r,t,o=tinymce.util.Tools.resolve("tinymce.PluginManager"),c=0,i=function(n,e,r){var t,o,i;n.plugins.table?n.plugins.table.insertTable(e,r):(o=e,i=r,(t=n).undoManager.transact(function(){var n,e;t.insertContent(function(n,e){var r,t,o;for(o='<table data-mce-id="mce" style="width: 100%">',o+="<tbody>",t=0;t<e;t++){for(o+="<tr>",r=0;r<n;r++)o+="<td><br></td>";o+="</tr>"}return o+="</tbody>",o+="</table>"}(o,i)),(n=t.dom.select("*[data-mce-id]")[0]).removeAttribute("data-mce-id"),e=t.dom.select("td,th",n),t.selection.setCursorLocation(e[0],0)}))},u=function(n,e,r){var t,o,i,u;o=(t=n.editorUpload.blobCache).create((i="mceu",u=(new Date).getTime(),i+"_"+Math.floor(1e9*Math.random())+ ++c+String(u)),r,e),t.add(o),n.insertContent(n.dom.createHTML("img",{src:o.blobUri()}))},s="undefined"!=typeof window?window:Function("return this;")(),a=function(n,e){return function(n,e){for(var r=e!==undefined&&null!==e?e:s,t=0;t<n.length&&r!==undefined&&null!==r;++t)r=r[n[t]];return r}(n.split("."),e)},f=function(n,e){var r=a(n,e);if(r===undefined||null===r)throw n+" not available on this browser";return r},d=tinymce.util.Tools.resolve("tinymce.util.Promise"),l=function(t){return new d(function(n){var e=function r(){return new(f("FileReader"))}();e.onloadend=function(){n(e.result.split(",")[1])},e.readAsDataURL(t)})},m=function(){return new d(function(e){var n;(n=document.createElement("input")).type="file",n.style.position="fixed",n.style.left=0,n.style.top=0,n.style.opacity=.001,document.body.appendChild(n),n.onchange=function(n){e(Array.prototype.slice.call(n.target.files))},n.click(),n.parentNode.removeChild(n)})},v=function(r){r.ui.registry.addButton("quickimage",{icon:"image",tooltip:"Insert image",onAction:function(){m().then(function(n){var e=n[0];l(e).then(function(n){u(r,n,e)})})}}),r.ui.registry.addButton("quicktable",{icon:"table",tooltip:"Insert table",onAction:function(){i(r,2,2)}})},h=function(n){return function(){return n}},g=h(!1),T=h(!0),p=g,N=T,E=function(){return O},O=(t={fold:function(n,e){return n()},is:p,isSome:p,isNone:N,getOr:r=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:r,orThunk:e,map:E,ap:E,each:function(){},bind:E,flatten:E,exists:p,forall:N,filter:E,equals:n=function(n){return n.isNone()},equals_:n,toArray:function(){return[]},toString:h("none()")},Object.freeze&&Object.freeze(t),t),y=function(r){var n=function(){return r},e=function(){return o},t=function(n){return n(r)},o={fold:function(n,e){return e(r)},is:function(n){return r===n},isSome:N,isNone:p,getOr:n,getOrThunk:n,getOrDie:n,getOrNull:n,getOrUndefined:n,or:e,orThunk:e,map:function(n){return y(n(r))},ap:function(n){return n.fold(E,function(n){return y(n(r))})},each:function(n){n(r)},bind:t,flatten:n,exists:t,forall:t,filter:function(n){return n(r)?o:O},equals:function(n){return n.is(r)},equals_:function(n,e){return n.fold(p,function(n){return e(r,n)})},toArray:function(){return[r]},toString:function(){return"some("+r+")"}};return o},b={some:y,none:E,from:function(n){return null===n||n===undefined?O:y(n)}},S=function(n){if(null===n||n===undefined)throw new Error("Node cannot be null or undefined");return{dom:h(n)}},w={fromHtml:function(n,e){var r=(e||document).createElement("div");if(r.innerHTML=n,!r.hasChildNodes()||1<r.childNodes.length)throw console.error("HTML does not have a single root node",n),"HTML must have a single root node";return S(r.childNodes[0])},fromTag:function(n,e){var r=(e||document).createElement(n);return S(r)},fromText:function(n,e){var r=(e||document).createTextNode(n);return S(r)},fromDom:S,fromPoint:function(n,e,r){var t=n.dom();return b.from(t.elementFromPoint(e,r)).map(S)}},x={ATTRIBUTE:Node.ATTRIBUTE_NODE,CDATA_SECTION:Node.CDATA_SECTION_NODE,COMMENT:Node.COMMENT_NODE,DOCUMENT:Node.DOCUMENT_NODE,DOCUMENT_TYPE:Node.DOCUMENT_TYPE_NODE,DOCUMENT_FRAGMENT:Node.DOCUMENT_FRAGMENT_NODE,ELEMENT:Node.ELEMENT_NODE,TEXT:Node.TEXT_NODE,PROCESSING_INSTRUCTION:Node.PROCESSING_INSTRUCTION_NODE,ENTITY_REFERENCE:Node.ENTITY_REFERENCE_NODE,ENTITY:Node.ENTITY_NODE,NOTATION:Node.NOTATION_NODE},D=function(n){return n.dom().nodeName.toLowerCase()},C=function(n){return n.dom().nodeType},A=function(e){return function(n){return C(n)===e}},M=A(x.ELEMENT),_=A(x.TEXT),R=A(x.DOCUMENT),k={name:D,type:C,value:function(n){return n.dom().nodeValue},isElement:M,isText:_,isDocument:R,isComment:function(n){return C(n)===x.COMMENT||"#comment"===D(n)}},I=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}},U=I("string"),L=I("array"),B=I("boolean"),F=I("function"),q=function(n,e){for(var r=0,t=n.length;r<t;r++){var o=n[r];if(e(o,r,n))return b.some(o)}return b.none()},P=(Array.prototype.slice,F(Array.from)&&Array.from,function(r){var t,o=!1;return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return o||(o=!0,t=r.apply(null,n)),t}}),j=P(function(){return X(w.fromDom(document))}),X=function(n){var e=n.dom().body;if(null===e||e===undefined)throw"Body is not available yet";return w.fromDom(e)},H={body:j,getBody:X,inBody:function(n){var e=k.isText(n)?n.dom().parentNode:n.dom();return e!==undefined&&null!==e&&e.ownerDocument.body.contains(e)}},W=function(n,e){var r=function(n,e){for(var r=0;r<n.length;r++){var t=n[r];if(t.test(e))return t}return undefined}(n,e);if(!r)return{major:0,minor:0};var t=function(n){return Number(e.replace(r,"$"+n))};return z(t(1),t(2))},Y=function(){return z(0,0)},z=function(n,e){return{major:n,minor:e}},G={nu:z,detect:function(n,e){var r=String(e).toLowerCase();return 0===n.length?Y():W(n,r)},unknown:Y},V="Firefox",$=function(n,e){return function(){return e===n}},J=function(n){var e=n.current;return{current:e,version:n.version,isEdge:$("Edge",e),isChrome:$("Chrome",e),isIE:$("IE",e),isOpera:$("Opera",e),isFirefox:$(V,e),isSafari:$("Safari",e)}},K={unknown:function(){return J({current:undefined,version:G.unknown()})},nu:J,edge:h("Edge"),chrome:h("Chrome"),ie:h("IE"),opera:h("Opera"),firefox:h(V),safari:h("Safari")},Q="Windows",Z="Android",nn="Solaris",en="FreeBSD",rn=function(n,e){return function(){return e===n}},tn=function(n){var e=n.current;return{current:e,version:n.version,isWindows:rn(Q,e),isiOS:rn("iOS",e),isAndroid:rn(Z,e),isOSX:rn("OSX",e),isLinux:rn("Linux",e),isSolaris:rn(nn,e),isFreeBSD:rn(en,e)}},on={unknown:function(){return tn({current:undefined,version:G.unknown()})},nu:tn,windows:h(Q),ios:h("iOS"),android:h(Z),linux:h("Linux"),osx:h("OSX"),solaris:h(nn),freebsd:h(en)},un=function(n,e){var r=String(e).toLowerCase();return q(n,function(n){return n.search(r)})},cn=function(n,r){return un(n,r).map(function(n){var e=G.detect(n.versionRegexes,r);return{current:n.name,version:e}})},sn=function(n,r){return un(n,r).map(function(n){var e=G.detect(n.versionRegexes,r);return{current:n.name,version:e}})},an=function(n,e){return-1!==n.indexOf(e)},fn=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,dn=function(e){return function(n){return an(n,e)}},ln=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:function(n){return an(n,"edge/")&&an(n,"chrome")&&an(n,"safari")&&an(n,"applewebkit")}},{name:"Chrome",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,fn],search:function(n){return an(n,"chrome")&&!an(n,"chromeframe")}},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:function(n){return an(n,"msie")||an(n,"trident")}},{name:"Opera",versionRegexes:[fn,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:dn("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:dn("firefox")},{name:"Safari",versionRegexes:[fn,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:function(n){return(an(n,"safari")||an(n,"mobile/"))&&an(n,"applewebkit")}}],mn=[{name:"Windows",search:dn("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:function(n){return an(n,"iphone")||an(n,"ipad")},versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:dn("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"OSX",search:dn("os x"),versionRegexes:[/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:dn("linux"),versionRegexes:[]},{name:"Solaris",search:dn("sunos"),versionRegexes:[]},{name:"FreeBSD",search:dn("freebsd"),versionRegexes:[]}],vn={browsers:h(ln),oses:h(mn)},gn=function(n){var e,r,t,o,i,u,c,s,a,f,d,l=vn.browsers(),m=vn.oses(),v=cn(l,n).fold(K.unknown,K.nu),g=sn(m,n).fold(on.unknown,on.nu);return{browser:v,os:g,deviceType:(r=v,t=n,o=(e=g).isiOS()&&!0===/ipad/i.test(t),i=e.isiOS()&&!o,u=e.isAndroid()&&3===e.version.major,c=e.isAndroid()&&4===e.version.major,s=o||u||c&&!0===/mobile/i.test(t),a=e.isiOS()||e.isAndroid(),f=a&&!s,d=r.isSafari()&&e.isiOS()&&!1===/safari/i.test(t),{isiPad:h(o),isiPhone:h(i),isTablet:h(s),isPhone:h(f),isTouch:h(a),isAndroid:e.isAndroid,isiOS:e.isiOS,isWebView:h(d)})}},hn=P(function(){var n=navigator.userAgent;return gn(n)}),Tn=x.ELEMENT,pn=x.DOCUMENT,Nn=function(n){return n.nodeType!==Tn&&n.nodeType!==pn||0===n.childElementCount},En={all:function(n,e){var r=e===undefined?document:e.dom();return Nn(r)?[]:function(n,e){for(var r=n.length,t=new Array(r),o=0;o<r;o++){var i=n[o];t[o]=e(i,o,n)}return t}(r.querySelectorAll(n),w.fromDom)},is:function(n,e){var r=n.dom();if(r.nodeType!==Tn)return!1;if(r.matches!==undefined)return r.matches(e);if(r.msMatchesSelector!==undefined)return r.msMatchesSelector(e);if(r.webkitMatchesSelector!==undefined)return r.webkitMatchesSelector(e);if(r.mozMatchesSelector!==undefined)return r.mozMatchesSelector(e);throw new Error("Browser lacks native selectors")},one:function(n,e){var r=e===undefined?document:e.dom();return Nn(r)?b.none():b.from(r.querySelector(n)).map(w.fromDom)}},On=function(n,e){return n.dom()===e.dom()},yn=(hn().browser.isIE(),On);function bn(n,e,r,t,o){return n(r,t)?b.some(r):F(o)&&o(r)?b.none():e(r,t,o)}var Sn,wn=function(n,e,r){for(var t=n.dom(),o=F(r)?r:h(!1);t.parentNode;){t=t.parentNode;var i=w.fromDom(t);if(e(i))return b.some(i);if(o(i))break}return b.none()},xn=function(n,e){var r,t;return q(n.dom().childNodes,(r=e,t=w.fromDom,function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return r(t.apply(null,arguments))})).map(w.fromDom)},Dn=function(n,t){var o=function(n){for(var e=0;e<n.childNodes.length;e++){if(t(w.fromDom(n.childNodes[e])))return b.some(w.fromDom(n.childNodes[e]));var r=o(n.childNodes[e]);if(r.isSome())return r}return b.none()};return o(n.dom())},Cn={first:function(n){return Dn(H.body(),n)},ancestor:wn,closest:function(n,e,r){return bn(function(n){return e(n)},wn,n,e,r)},sibling:function(e,r){var n=e.dom();return n.parentNode?xn(w.fromDom(n.parentNode),function(n){return!yn(e,n)&&r(n)}):b.none()},child:xn,descendant:Dn},An=function(n,e,r){return Cn.ancestor(n,function(n){return En.is(n,e)},r)},Mn=function(n,e,r){return bn(En.is,An,n,e,r)},_n={getToolbarItemsOr:(Sn=L,function(n,e,r){var t,o,i,u,c,s=e in n.settings?n.settings[e]:r;return function(n,e){if(!e(n))throw new Error("Default value doesn't match requested type.")}(r,Sn),o=r,L(t=s)?t:U(t)?"string"==typeof(u=t)?(c=/[ ,]/,u.split(c).filter(function(n){return 0<n.length})):u:B(t)?(i=o,!1===t?[]:i):o})},Rn=function(n){return _n.getToolbarItemsOr(n,"inlite_selection_toolbar",["bold","forecolor","italic","|","form:link-form","h2","h3","blockquote"])},kn=function(n){return _n.getToolbarItemsOr(n,"inlite_insert_toolbar",["quickimage","quicktable"])},In=function(o){o.ui.registry.addContextToolbar("quickblock",{predicate:function(n){var e=w.fromDom(n),r=o.schema.getTextBlockElements(),t=function(n){return n.dom()===o.getBody()};return Mn(e,"table",t).fold(function(){return Cn.closest(e,function(n){return k.name(n)in r&&o.dom.isEmpty(n.dom())},t).isSome()},function(){return!1})},items:kn(o),position:"line",scope:"editor"})},Un=(tinymce.util.Tools.resolve("tinymce.util.Tools"),tinymce.util.Tools.resolve("tinymce.dom.TreeWalker"),tinymce.util.Tools.resolve("tinymce.dom.RangeUtils"),function(n,e){n.execCommand("FormatBlock",!1,e)}),Ln=function(t){for(var n=function(n){var e,r="h"+n;t.ui.registry.addToggleButton(r,{type:"togglebutton",text:r.toUpperCase(),tooltip:"Heading "+n,onSetup:function(n){return t.selection.selectorChangedWithUnbind(r,n.setActive).unbind},onAction:(e=r,function(){Un(t,e)})})},e=1;e<6;e++)n(e)},Bn=function(e){e.ui.registry.addContextToolbar("textselection",{type:"contexttoolbar",predicate:function(n){return!e.selection.isCollapsed()},items:Rn(e),position:"selection"})};o.add("inlite",function(n){v(n),In(n),Ln(n),Bn(n)}),function Fn(){}}(); |