﻿(function(){CKEDITOR.dialog.add("lightbox",function(d){var h=CKEDITOR.plugins.link,e=!1,l=function(a){icon=CKEDITOR.getUrl(CKEDITOR.plugins.get("lightbox").path+"images/loading.gif");document.getElementById("cke_lightbox_image_preview").style.backgroundSize="auto auto";document.getElementById("cke_lightbox_image_preview").style.backgroundImage="url('"+icon+"')";var c=new Image;c.onload=function(){e=!0;document.getElementById("cke_lightbox_image_preview").style.backgroundSize="contain";document.getElementById("cke_lightbox_image_preview").style.backgroundImage=
"url('"+a+"')"};c.onerror=function(){e=!1};c.src=a},g=d.lang.common,k=d.lang.link;return{title:"Lightbox",minWidth:350,minHeight:230,contents:[{id:"info",label:k.info,title:k.info,elements:[{type:"vbox",id:"urlOptions",children:[{type:"hbox",widths:["25%","75%"],children:[{type:"text",id:"url",label:d.lang.lightbox.url,required:!0,onLoad:function(){this.allowOnChange=!0},onKeyUp:function(){this.allowOnChange=!1;var a=this.getValue();/^((javascript:)|[#\/\.\?])/i.test(a);document.getElementById("cke_lightbox_image_preview").style.backgroundImage=
"url('"+a+"')";l(a);this.allowOnChange=!0},onChange:function(){if(this.allowOnChange)this.onKeyUp()},validate:function(){this.getDialog();return e?!d.config.linkJavaScriptLinksAllowed&&/javascript\:/.test(this.getValue())?(alert(g.invalidValue),!1):this.getDialog().fakeObj?!0:CKEDITOR.dialog.validate.notEmpty(k.noUrl).apply(this):(alert(g.invalidValue),!1)},setup:function(a){this.allowOnChange=!1;a.url&&this.setValue(a.url.url);this.allowOnChange=!0},commit:function(a){this.onChange();a.type="url";
a.url||(a.url={});a.url.protocol="";a.url.url=this.getValue();this.allowOnChange=!1}}],setup:function(){this.getDialog().getContentElement("info","linkType")||this.getElement().show()}},{type:"button",id:"browse",hidden:"true",filebrowser:"info:url",label:g.browseServer}]},{id:"prev",type:"html",html:d.lang.lightbox.preview+'\x3cdiv id\x3d"cke_lightbox_image_preview" class\x3d"ImagePreview" style\x3d"border:2px solid #000; height:100px; text-align:center; background-size:contain; background-position:center center; background-repeat:no-repeat;"\x3e\x3c/div\x3e'},
{type:"text",label:d.lang.lightbox.title,"a[title]":"",id:"advTitle",setup:function(a){a.advanced&&this.setValue(a.advanced[this.id]||"")},commit:function(a){a.advanced||(a.advanced={});a.advanced[this.id]=this.getValue()||""}},{type:"text",label:d.lang.lightbox.gallery,"default":"",id:"advRel",setup:function(a){this.setValue(gal||"")},commit:function(a){gal=this.getValue()||""}}]}],onShow:function(){document.getElementById("cke_lightbox_image_preview").style.backgroundSize="auto auto";document.getElementById("cke_lightbox_image_preview").style.backgroundImage=
"url('"+CKEDITOR.getUrl(CKEDITOR.plugins.get("lightbox").path+"images/noimage.png")+"')";var a=this.getParentEditor(),c=a.getSelection(),b=null;(b=h.getSelectedLink(a))&&b.hasAttribute("href")?c.getSelectedElement()||c.selectElement(b):b=null;a=h.parseLinkAttributes(a,b);this._.selectedElement=b;p="undefined"!==typeof a.url.protocol?a.url.protocol:"";document.getElementById("cke_lightbox_image_preview").style.backgroundSize="contain";document.getElementById("cke_lightbox_image_preview").style.backgroundImage=
"url('"+p+a.url.url+"')";a.url.url=p+a.url.url;e=!0;gal=b.getAttribute("data-lightbox-saved");this.setupContent(a)},onOk:function(){var a={};this.commitContent(a);var c=d.getSelection(),b=h.getLinkAttributes(d,a);b.set["data-lightbox-saved"]=gal;var e=b.set,f;if(""!=gal)f=gal;else{f="";for(var g=0;10>g;g++)f+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()))}e["data-lightbox"]=f;"undefined"!==typeof b.set.title?b.set["data-title"]=b.set.title:b.removed.push("data-title");
this._.selectedElement?(a=this._.selectedElement,e=a.data("cke-saved-href"),f=a.getHtml(),a.setAttributes(b.set),a.removeAttributes(b.removed),e==f&&(a.setHtml(b.set["data-cke-saved-href"]),c.selectElement(a)),delete this._.selectedElement):(c=c.getRanges()[0],c.collapsed&&(a=new CKEDITOR.dom.text(b.set["data-cke-saved-href"],d.document),c.insertNode(a),c.selectNodeContents(a)),b=new CKEDITOR.style({element:"a",attributes:b.set}),b.type=CKEDITOR.STYLE_INLINE,b.applyToRange(c,d),c.select())}}})})();