mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-12 09:40:45 +01:00
1 line
7.6 KiB
JavaScript
1 line
7.6 KiB
JavaScript
!function(){"use strict";var e,t,n,r,a,o=tinymce.util.Tools.resolve("tinymce.PluginManager"),u=function(e){return function(){return e}},i=u(!1),c=u(!0),f=tinymce.util.Tools.resolve("tinymce.util.Tools"),p=tinymce.util.Tools.resolve("tinymce.util.XHR"),l=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),s=function(e){return e.getParam("template_cdate_classes","cdate")},m=function(e){return e.getParam("template_mdate_classes","mdate")},d=function(e){return e.getParam("template_selected_content_classes","selcontent")},g=function(e){return e.getParam("template_preview_replace_values")},y=function(e){return e.getParam("template_replace_values")},h=function(e){return e.templates},v=function(e){return e.getParam("template_cdate_format",e.getLang("template.cdate_format"))},b=function(e){return e.getParam("template_mdate_format",e.getLang("template.mdate_format"))},_=function(e){return e.getParam("template_popup_width",600)},M=function(e){return Math.min(l.DOM.getViewPort().h,e.getParam("template_popup_height",500))},T=function(e,t){if((e=""+e).length<t)for(var n=0;n<t-e.length;n++)e="0"+e;return e},O=function(e,t,n){var r="Sun Mon Tue Wed Thu Fri Sat Sun".split(" "),a="Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" "),o="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),u="January February March April May June July August September October November December".split(" ");return n=n||new Date,t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace("%D","%m/%d/%Y")).replace("%r","%I:%M:%S %p")).replace("%Y",""+n.getFullYear())).replace("%y",""+n.getYear())).replace("%m",T(n.getMonth()+1,2))).replace("%d",T(n.getDate(),2))).replace("%H",""+T(n.getHours(),2))).replace("%M",""+T(n.getMinutes(),2))).replace("%S",""+T(n.getSeconds(),2))).replace("%I",""+((n.getHours()+11)%12+1))).replace("%p",n.getHours()<12?"AM":"PM")).replace("%B",""+e.translate(u[n.getMonth()]))).replace("%b",""+e.translate(o[n.getMonth()]))).replace("%A",""+e.translate(a[n.getDay()]))).replace("%a",""+e.translate(r[n.getDay()]))).replace("%%","%")},x=function(n,e){return f.each(e,function(e,t){"function"==typeof e&&(e=e(t)),n=n.replace(new RegExp("\\{\\$"+t+"\\}","g"),e)}),n},P=function(e,t){var r=e.dom,a=y(e);f.each(r.select("*",t),function(n){f.each(a,function(e,t){r.hasClass(n,t)&&"function"==typeof a[t]&&a[t](n)})})},S=function(e,t){return new RegExp("\\b"+t+"\\b","g").test(e.className)},w=function(t,n){return function(){var e=h(t);"function"!=typeof e?"string"==typeof e?p.send({url:e,success:function(e){n(JSON.parse(e))}}):n(e):e(n)}},A=x,D=P,C=function(t,e,n){var r,a,o=t.dom,u=t.selection.getContent();n=x(n,y(t)),r=o.create("div",null,n),(a=o.select(".mceTmpl",r))&&0<a.length&&(r=o.create("div",null)).appendChild(a[0].cloneNode(!0)),f.each(o.select("*",r),function(e){S(e,s(t).replace(/\s+/g,"|"))&&(e.innerHTML=O(t,v(t))),S(e,m(t).replace(/\s+/g,"|"))&&(e.innerHTML=O(t,b(t))),S(e,d(t).replace(/\s+/g,"|"))&&(e.innerHTML=u)}),P(t,r),t.execCommand("mceInsertContent",!1,r.innerHTML),t.addVisual()},H=function(e){e.addCommand("mceInsertTemplate",function(o){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];for(var u=new Array(arguments.length-1),n=1;n<arguments.length;n++)u[n-1]=arguments[n];return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];var a=u.concat(n);return o.apply(null,a)}}(C,e))},N=function(r){r.on("PreProcess",function(e){var t=r.dom,n=b(r);f.each(t.select("div",e.node),function(e){t.hasClass(e,"mceTmpl")&&(f.each(t.select("*",e),function(e){t.hasClass(e,r.getParam("template_mdate_classes","mdate").replace(/\s+/g,"|"))&&(e.innerHTML=O(r,n))}),D(r,e))})})},k=i,I=c,L=function(){return J},J=(r={fold:function(e,t){return e()},is:k,isSome:k,isNone:I,getOr:n=function(e){return e},getOrThunk:t=function(e){return e()},getOrDie:function(e){throw new Error(e||"error: getOrDie called on none.")},getOrNull:function(){return null},getOrUndefined:function(){return undefined},or:n,orThunk:t,map:L,ap:L,each:function(){},bind:L,flatten:L,exists:k,forall:I,filter:L,equals:e=function(e){return e.isNone()},equals_:e,toArray:function(){return[]},toString:u("none()")},Object.freeze&&Object.freeze(r),r),F=function(n){var e=function(){return n},t=function(){return a},r=function(e){return e(n)},a={fold:function(e,t){return t(n)},is:function(e){return n===e},isSome:I,isNone:k,getOr:e,getOrThunk:e,getOrDie:e,getOrNull:e,getOrUndefined:e,or:t,orThunk:t,map:function(e){return F(e(n))},ap:function(e){return e.fold(L,function(e){return F(e(n))})},each:function(e){e(n)},bind:r,flatten:e,exists:r,forall:r,filter:function(e){return e(n)?a:J},equals:function(e){return e.is(n)},equals_:function(e,t){return e.fold(k,function(e){return t(n,e)})},toArray:function(){return[n]},toString:function(){return"some("+n+")"}};return a},Y={some:F,none:L,from:function(e){return null===e||e===undefined?J:F(e)}},j=(a="function",function(e){return function(e){if(null===e)return"null";var t=typeof e;return"object"===t&&Array.prototype.isPrototypeOf(e)?"array":"object"===t&&String.prototype.isPrototypeOf(e)?"string":t}(e)===a}),q=(Array.prototype.slice,j(Array.from)&&Array.from,tinymce.util.Tools.resolve("tinymce.util.Promise")),E=function(t,e){if(-1===e.indexOf("<html>")){var n="";f.each(t.contentCSS,function(e){n+='<link type="text/css" rel="stylesheet" href="'+t.documentBaseURI.toAbsolute(e)+'">'});var r=t.settings.body_class||"";-1!==r.indexOf("=")&&(r=(r=t.getParam("body_class","","hash"))[t.id]||""),e="<!DOCTYPE html><html><head>"+n+'</head><body class="'+r+'">'+e+"</body></html>"}return A(e,g(t))},R=function(c,t){var e=function(e){return function(e,t){for(var n=e.length,r=new Array(n),a=0;a<n;a++){var o=e[a];r[a]=t(o,a,e)}return r}(e,function(e){return{text:e.text,value:e.text}})},l=function(e,t){return function(e,t){for(var n=0,r=e.length;n<r;n++){var a=e[n];if(t(a,n,e))return Y.some(a)}return Y.none()}(e,function(e){return e.text===t})},s=function(e){return new q(function(t,n){e.value.url?p.send({url:e.value.url,success:function(e){t(e)},error:function(e){n(e)}}):t(e.value.content)})};(function(){if(t&&0!==t.length)return Y.from(f.map(t,function(e,t){return{selected:0===t,text:e.title,value:{url:e.url,content:e.content,description:e.description}}}));var e=c.translate("No templates defined.");return c.notificationManager.open({text:e,type:"info"}),Y.none()})().each(function(a){var o=e(a),u=function(e,t){return void 0===e&&(e=[]),void 0===t&&(t={}),{title:"Insert Template",size:"large",layout:"flex",direction:"column",align:"stretch",padding:15,spacing:10,minWidth:_(c),minHeight:M(c),body:{type:"panel",items:e},initialData:t,buttons:[{type:"submit",name:"ok",text:"Ok",primary:!0},{type:"cancel",name:"cancel",text:"Cancel"}],onSubmit:(n=a,function(t){var e=t.getData();l(n,e.template).each(function(e){s(e).then(function(e){C(c,!1,e),t.close()})})}),onChange:(r=a,function(n,e){if("template"===e.name){var t=n.getData().template;l(r,t).each(function(e){s(e).then(function(e){var t=E(c,e);n.setData({preview:t})})})}})};var r,n},i=c.windowManager.open(u());i.block("Loading..."),s(a[0]).then(function(e){var t=E(c,e),n=[{type:"selectbox",name:"template",label:"Templates",items:o},{label:"Preview",type:"iframe",name:"preview",flex:!0,border:1,sandboxed:!1}],r={template:a[0].text,preview:t};i.unblock(),i.redial(u(n,r)),i.focus("template")})})},U=function(t){return function(e){R(t,e)}},z=function(e){e.ui.registry.addButton("template",{type:"button",icon:"template",tooltip:"Insert template",onAction:w(e.settings,U(e))}),e.ui.registry.addMenuItem("template",{icon:"template",text:"Template",onAction:w(e.settings,U(e))})};o.add("template",function(e){z(e),H(e),N(e)}),function B(){}}(); |