CKEDITOR.dialog.add("base64imageDialog",function(c){function p(b){if("string"!=typeof b||!b)e.getElement().setHtml("");else{var f=new Image;e.getElement().setHtml("Loading...");f.onload=function(){e.getElement().setHtml("");null==i||null==h?(d.setValueOf("tab-properties","width",this.width),d.setValueOf("tab-properties","height",this.height),j=1,0=j&&(j=1)):h=i=null;this.id=c.id+"previewimage";this.setAttribute("style","max-width:400px;max-height:100px;"); this.setAttribute("alt","");try{var b=e.getElement().$;b&&b.appendChild(this)}catch(f){}};f.onerror=function(){e.getElement().setHtml("")};f.onabort=function(){e.getElement().setHtml("")};f.src=b}}function n(b){e.getElement().setHtml("");if("base64"==b)l&&l.setValue(!1,!0),m&&m.setValue(!1,!0);else if("url"==b)l&&l.setValue(!0,!0),m&&m.setValue(!1,!0),q&&p(q.getValue());else if(r){l&&l.setValue(!1,!0);m&&m.setValue(!0,!0);var f=d.getContentElement("tab-source","file"),b=null;try{b=f.getInputElement().$}catch(a){b= null}if(b&&("files"in b&&b.files&&0')).output()}]:[{type:"text",id:"url",label:c.lang.common.url,onChange:function(){n("url")}},{type:"html",id:"preview",html:(new CKEDITOR.template('
')).output()}];return{title:c.lang.common.image,minWidth:450,minHeight:180,onLoad:function(){r&&(l=this.getContentElement("tab-source","urlcheckbox"),m= this.getContentElement("tab-source","filecheckbox"),l.getInputElement().on("click",function(){n("url")}),m.getInputElement().on("click",function(){n("file")}));q=this.getContentElement("tab-source","url");e=this.getContentElement("tab-source","preview");this.getContentElement("tab-properties","lock").getInputElement().on("click",function(){(o=this.getValue()?true:false)&&s("width")},this.getContentElement("tab-properties","lock"));this.getContentElement("tab-properties","width").getInputElement().on("keyup", function(){o&&s("width")});this.getContentElement("tab-properties","height").getInputElement().on("keyup",function(){o&&s("height")});this.getContentElement("tab-properties","vmargin").getInputElement().on("keyup",function(){t(this)},this.getContentElement("tab-properties","vmargin"));this.getContentElement("tab-properties","hmargin").getInputElement().on("keyup",function(){t(this)},this.getContentElement("tab-properties","hmargin"));this.getContentElement("tab-properties","border").getInputElement().on("keyup", function(){t(this)},this.getContentElement("tab-properties","border"))},onShow:function(){e.getElement().setHtml("");d=this;h=i=null;j=1;o=!0;(a=c.getSelection())&&(a=a.getSelectedElement());if(!a||"img"!==a.getName())a=null;d.setValueOf("tab-properties","lock",o);d.setValueOf("tab-properties","vmargin","0");d.setValueOf("tab-properties","hmargin","0");d.setValueOf("tab-properties","border","0");d.setValueOf("tab-properties","align","none");if(a){"string"==typeof a.getAttribute("width")&&(i=a.getAttribute("width")); "string"==typeof a.getAttribute("height")&&(h=a.getAttribute("height"));if((null==i||null==h)&&a.$)i=a.$.width,h=a.$.height;null!=i&&null!=h&&(d.setValueOf("tab-properties","width",i),d.setValueOf("tab-properties","height",h),i=parseInt(i,10),h=parseInt(h,10),j=1,!isNaN(i)&&(!isNaN(h)&&0=j&&(j=1));"string"==typeof a.getAttribute("src")&&(0===a.getAttribute("src").indexOf("data:")?(n("base64"),p(a.getAttribute("src"))):d.setValueOf("tab-source","url",a.getAttribute("src")));"string"== typeof a.getAttribute("alt")&&d.setValueOf("tab-properties","alt",a.getAttribute("alt"));"string"==typeof a.getAttribute("hspace")&&d.setValueOf("tab-properties","hmargin",a.getAttribute("hspace"));"string"==typeof a.getAttribute("vspace")&&d.setValueOf("tab-properties","vmargin",a.getAttribute("vspace"));"string"==typeof a.getAttribute("border")&&d.setValueOf("tab-properties","border",a.getAttribute("border"));if("string"==typeof a.getAttribute("align"))switch(a.getAttribute("align")){case "top":case "text-top":d.setValueOf("tab-properties", "align","top");break;case "baseline":case "bottom":case "text-bottom":d.setValueOf("tab-properties","align","bottom");break;case "left":d.setValueOf("tab-properties","align","left");break;case "right":d.setValueOf("tab-properties","align","right")}d.selectPage("tab-properties")}},onOk:function(){var b="";try{b=CKEDITOR.document.getById(c.id+"previewimage").$.src}catch(f){b=""}if(!("string"!=typeof b||null==b||""===b)){var e=a?a:c.document.createElement("img");e.setAttribute("src",b);e.setAttribute("alt", d.getValueOf("tab-properties","alt").replace(/^\s+/,"").replace(/\s+$/,""));var b={width:["width","width:#;","integer",1],height:["height","height:#;","integer",1],vmargin:["vspace","margin-top:#;margin-bottom:#;","integer",0],hmargin:["hspace","margin-left:#;margin-right:#;","integer",0],align:["align",""],border:["border","border:# solid black;","integer",0]},i=[],g,h,j,k;for(k in b){h=j=g=d.getValueOf("tab-properties",k);unit="px";if("align"==k)switch(g){case "top":case "bottom":b[k][1]="vertical-align:#;"; break;case "left":case "right":b[k][1]="float:#;";break;default:g=null}"integer"==b[k][2]&&(0<=g.indexOf("%")&&(unit="%"),g=parseInt(g,10),isNaN(g)?g=null:g