(function(){var b=CKEDITOR.document;CKEDITOR.dialog.add("templates",function(r){function q(j,i){j.setHtml("");for(var h=0,g=i.length;h<g;h++){var f=CKEDITOR.getTemplates(i[h]),e=f.imagesPath,d=f.templates,c=d.length;for(var x=0;x<c;x++){var w=d[x],v=p(w,e);v.setAttribute("aria-posinset",x+1);v.setAttribute("aria-setsize",c);j.append(v)}}}function p(e,d){var c=CKEDITOR.dom.element.createFromHtml('<a href="javascript:void(0)" tabIndex="-1" role="option" ><div class="cke_tpl_item"></div></a>'),f='<table style="width:350px;" class="cke_tpl_preview" role="presentation"><tr>';if(e.image&&d){f+='<td class="cke_tpl_preview_img"><img src="'+CKEDITOR.getUrl(d+e.image)+'"'+(CKEDITOR.env.ie6Compat?' onload="this.width=this.width"':"")+' alt="" title=""></td>'}f+='<td style="white-space:normal;"><span class="cke_tpl_title">'+e.title+"</span><br/>";if(e.description){f+="<span>"+e.description+"</span>"}f+="</td></tr></table>";c.getFirst().setHtml(f);c.on("click",function(){o(e.html)});return c}function o(e){var d=CKEDITOR.dialog.getCurrent(),c=d.getValueOf("selectTpl","chkInsertOpt");if(c){r.on("contentDom",function(g){g.removeListener();d.hide();var f=new CKEDITOR.dom.range(r.document);f.moveToElementEditStart(r.document.getBody());f.select(1);setTimeout(function(){r.fire("saveSnapshot")},0)});r.fire("saveSnapshot");r.setData(e)}else{r.insertHtml(e);d.hide()}}function n(e){var d=e.data.getTarget(),c=m.equals(d);if(c||m.contains(d)){var h=e.data.getKeystroke(),g=m.getElementsByTag("a"),f;if(g){if(c){f=g.getItem(0)}else{switch(h){case 40:f=d.getNext();break;case 38:f=d.getPrevious();break;case 13:case 32:d.fire("click")}}if(f){f.focus();e.data.preventDefault()}}}}CKEDITOR.skins.load(r,"templates");var m,l="cke_tpl_list_label_"+CKEDITOR.tools.getNextNumber(),k=r.lang.templates,a=r.config;return{title:r.lang.templates.title,minWidth:CKEDITOR.env.ie?440:400,minHeight:340,contents:[{id:"selectTpl",label:k.title,elements:[{type:"vbox",padding:5,children:[{id:"selectTplText",type:"html",html:"<span>"+k.selectPromptMsg+"</span>"},{id:"templatesList",type:"html",focus:true,html:'<div class="cke_tpl_list" tabIndex="-1" role="listbox" aria-labelledby="'+l+'"><div class="cke_tpl_loading"><span></span></div></div><span class="cke_voice_label" id="'+l+'">'+k.options+"</span>"},{id:"chkInsertOpt",type:"checkbox",label:k.insertOption,"default":a.templates_replaceContent}]}]}],buttons:[CKEDITOR.dialog.cancelButton],onShow:function(){var c=this.getContentElement("selectTpl","templatesList");m=c.getElement();CKEDITOR.loadTemplates(a.templates_files,function(){var d=(a.templates||"default").split(",");if(d.length){q(m,d);c.focus()}else{m.setHtml('<div class="cke_tpl_empty"><span>'+k.emptyListMsg+"</span></div>")}});this._.element.on("keydown",n)},onHide:function(){this._.element.removeListener("keydown",n)}}})})();