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