tinymce-editor/copy_this/modules/hdi/hdi-tinymce/tinymce/plugins/template/plugin.min.js
Marat.Bedoev@heiner-direct.com 54431935e5 update to 1.1.4
2013-10-02 17:48:32 +02:00

1 line
3.8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

tinymce.PluginManager.add("template",function(e){function t(){function t(t){function r(t){if(-1==t.indexOf("<html>")){var n="";tinymce.each(e.contentCSS,function(t){n+='<link type="text/css" rel="stylesheet" href="'+e.documentBaseURI.toAbsolute(t)+'">'}),t="<!DOCTYPE html><html><head>"+n+"</head>"+"<body>"+t+"</body>"+"</html>"}t=l(t,"template_preview_replace_values");var r=a.find("iframe")[0].getEl().contentWindow.document;r.open(),r.write(t),r.close()}var c=t.control.value();c.url?tinymce.util.XHR.send({url:c.url,success:function(e){n=e,r(n)}}):(n=c.content,r(n)),a.find("#description")[0].text(t.control.value().description)}var a,n,c=[];return e.settings.templates?(tinymce.each(e.settings.templates,function(e){c.push({selected:!c.length,text:e.title,value:{url:e.url,content:e.content,description:e.description}})}),a=e.windowManager.open({title:"Insert template",body:[{type:"container",label:"Templates",items:{type:"listbox",name:"template",values:c,onselect:t}},{type:"label",name:"description",label:"Description",text:" "},{type:"iframe",minWidth:600,minHeight:400,border:1}],onsubmit:function(){r(!1,n)}}),a.find("listbox")[0].fire("select"),void 0):(e.windowManager.alert("No templates defined"),void 0)}function a(t,a){function n(e,t){if(e=""+e,e.length<t)for(var a=0;a<t-e.length;a++)e="0"+e;return e}var l="Sun Mon Tue Wed Thu Fri Sat Sun".split(" "),r="Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" "),c="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),o="January February March April May June July August September October November December".split(" ");return a=a||new Date,t=t.replace("%D","%m/%d/%Y"),t=t.replace("%r","%I:%M:%S %p"),t=t.replace("%Y",""+a.getFullYear()),t=t.replace("%y",""+a.getYear()),t=t.replace("%m",n(a.getMonth()+1,2)),t=t.replace("%d",n(a.getDate(),2)),t=t.replace("%H",""+n(a.getHours(),2)),t=t.replace("%M",""+n(a.getMinutes(),2)),t=t.replace("%S",""+n(a.getSeconds(),2)),t=t.replace("%I",""+((a.getHours()+11)%12+1)),t=t.replace("%p",""+(a.getHours()<12?"AM":"PM")),t=t.replace("%B",""+e.translate(o[a.getMonth()])),t=t.replace("%b",""+e.translate(c[a.getMonth()])),t=t.replace("%A",""+e.translate(r[a.getDay()])),t=t.replace("%a",""+e.translate(l[a.getDay()])),t=t.replace("%%","%")}function n(t){var a=e.dom,n=e.getParam("template_replace_values");c(a.select("*",t),function(e){c(n,function(t,l){a.hasClass(e,l)&&"function"==typeof n[l]&&n[l](e)})})}function l(t,a){return c(e.getParam(a),function(e,a){"function"!=typeof e&&(t=t.replace(new RegExp("\\{\\$"+a+"\\}","g"),e))}),t}function r(t,r){function o(e,t){return new RegExp("\\b"+t+"\\b","g").test(e.className)}var s,i,m=e.dom,p=e.selection.getContent();r=l(r,"template_replace_values"),s=m.create("div",null,r),i=m.select(".mceTmpl",s),i&&i.length>0&&(s=m.create("div",null),s.appendChild(i[0].cloneNode(!0))),c(m.select("*",s),function(t){o(t,e.getParam("template_cdate_classes","cdate").replace(/\s+/g,"|"))&&(t.innerHTML=a(e.getParam("template_cdate_format",e.getLang("template.cdate_format")))),o(t,e.getParam("template_mdate_classes","mdate").replace(/\s+/g,"|"))&&(t.innerHTML=a(e.getParam("template_mdate_format",e.getLang("template.mdate_format")))),o(t,e.getParam("template_selected_content_classes","selcontent").replace(/\s+/g,"|"))&&(t.innerHTML=p)}),n(s),e.execCommand("mceInsertContent",!1,s.innerHTML),e.addVisual()}var c=tinymce.each;e.addCommand("mceInsertTemplate",r),e.addButton("template",{title:"Insert template",onclick:t}),e.addMenuItem("template",{text:"Insert template",onclick:t,context:"insert"}),e.on("PreProcess",function(t){var l=e.dom;c(l.select("div",t.node),function(t){l.hasClass(t,"mceTmpl")&&(c(l.select("*",t),function(t){l.hasClass(t,e.getParam("template_mdate_classes","mdate").replace(/\s+/g,"|"))&&(t.innerHTML=a(e.getParam("template_mdate_format",e.getLang("template.mdate_format"))))}),n(t))})})});