CKEDITOR.dialog.add("image2",(function(t){function e(){var t=this.getValue().match(w);return(t=!(!t||0===parseInt(t[1],10)))||alert(I.invalidLength.replace("%1",I[this.id]).replace("%2","px")),t}function i(){var e=this.getValue();o(!1),e!==s.data.src?(d(e,(function(e,i,a){if(o(!0),!e)return n(!1);y.setValue(!1===t.config.image2_prefillDimensions?0:i),V.setValue(!1===t.config.image2_prefillDimensions?0:a),h=r=i,p=c=a,n(R.checkHasNaturalRatio(e))})),g=!0):g?(o(!0),y.setValue(r),V.setValue(c),g=!1):o(!0)}function a(){if(f&&((a=this.getValue())&&(a.match(w)||n(!1),"0"!==a))){var t="width"==this.id,e=r||h,i=c||p,a=t?Math.round(a/e*i):Math.round(a/i*e);isNaN(a)||(t?V:y).setValue(a)}}function n(t){if(b){if("boolean"==typeof t){if(m)return;f=t}else t=y.getValue(),m=!0,(f=!f)&&t&&(t*=c/r,isNaN(t)||V.setValue(Math.round(t)));b[f?"removeClass":"addClass"]("cke_btn_unlocked"),b.setAttribute("aria-checked",f),CKEDITOR.env.hc&&b.getChild(0).setHtml(f?CKEDITOR.env.ie?"■":"▣":CKEDITOR.env.ie?"□":"▢")}}function o(t){y[t=t?"enable":"disable"](),V[t]()}var l,s,u,d,r,c,h,p,g,f,m,b,v,y,V,k,w=/(^\s*(\d+)(px)?\s*$)|^$/i,C=CKEDITOR.tools.getNextId(),D=CKEDITOR.tools.getNextId(),x=t.lang.image2,I=t.lang.common,_=new CKEDITOR.template('<div><a href="javascript:void(0)" tabindex="-1" title="'+x.lockRatio+'" class="cke_btn_locked" id="{lockButtonId}" role="checkbox"><span class="cke_icon"></span><span class="cke_label">'+x.lockRatio+'</span></a><a href="javascript:void(0)" tabindex="-1" title="'+x.resetSize+'" class="cke_btn_reset" id="{resetButtonId}" role="button"><span class="cke_label">'+x.resetSize+"</span></a></div>").output({lockButtonId:C,resetButtonId:D}),R=CKEDITOR.plugins.image2,E=t.config,K=!(!E.filebrowserImageBrowseUrl&&!E.filebrowserBrowseUrl),T=t.widgets.registered.image.features,B=R.getNatural,N=[{id:"src",type:"text",label:I.url,onKeyup:i,onChange:i,setup:function(t){this.setValue(t.data.src)},commit:function(t){t.setData("src",this.getValue())},validate:CKEDITOR.dialog.validate.notEmpty(x.urlMissing)}];return K&&N.push({type:"button",id:"browse",style:"display:inline-block;margin-top:14px;",align:"center",label:t.lang.common.browseServer,hidden:!0,filebrowser:"info:src"}),{title:x.title,minWidth:250,minHeight:100,onLoad:function(){l=this._.element.getDocument(),d=function(){function t(t,a){i.push(e.once(t,(function(t){for(var e;e=i.pop();)e.removeListener();a(t)})))}var e=l.createElement("img"),i=[];return function(i,a,n){t("load",(function(){var t=B(e);a.call(n,e,t.width,t.height)})),t("error",(function(){a(null)})),t("abort",(function(){a(null)})),e.setAttribute("src",(E.baseHref||"")+i+"?"+Math.random().toString(16).substring(2))}}()},onShow:function(){s=this.widget,u=s.parts.image,g=m=f=!1,k=B(u),h=r=k.width,p=c=k.height},contents:[{id:"info",label:x.infoTab,elements:[{type:"vbox",padding:0,children:[{type:"hbox",widths:["100%"],className:"cke_dialog_image_url",children:N}]},{id:"alt",type:"text",label:x.alt,setup:function(t){this.setValue(t.data.alt)},commit:function(t){t.setData("alt",this.getValue())},validate:!0===t.config.image2_altRequired?CKEDITOR.dialog.validate.notEmpty(x.altMissing):null},{type:"hbox",widths:["25%","25%","50%"],requiredContent:T.dimension.requiredContent,children:[{type:"text",width:"45px",id:"width",label:I.width,validate:e,onKeyUp:a,onLoad:function(){y=this},setup:function(t){this.setValue(t.data.width)},commit:function(t){t.setData("width",this.getValue())}},{type:"text",id:"height",width:"45px",label:I.height,validate:e,onKeyUp:a,onLoad:function(){V=this},setup:function(t){this.setValue(t.data.height)},commit:function(t){t.setData("height",this.getValue())}},{id:"lock",type:"html",style:"margin-top:18px;width:40px;height:20px;",onLoad:function(){function t(t){t.on("mouseover",(function(){this.addClass("cke_btn_over")}),t),t.on("mouseout",(function(){this.removeClass("cke_btn_over")}),t)}var e=this.getDialog();b=l.getById(C),v=l.getById(D),b&&(e.addFocusable(b,4+K),b.on("click",(function(t){n(),t.data&&t.data.preventDefault()}),this.getDialog()),t(b)),v&&(e.addFocusable(v,5+K),v.on("click",(function(t){g?(y.setValue(h),V.setValue(p)):(y.setValue(r),V.setValue(c)),t.data&&t.data.preventDefault()}),this),t(v))},setup:function(t){n(t.data.lock)},commit:function(t){t.setData("lock",f)},html:_}]},{type:"hbox",id:"alignment",requiredContent:T.align.requiredContent,children:[{id:"align",type:"radio",items:[[I.alignNone,"none"],[I.left,"left"],[I.center,"center"],[I.right,"right"]],label:I.align,setup:function(t){this.setValue(t.data.align)},commit:function(t){t.setData("align",this.getValue())}}]},{id:"hasCaption",type:"checkbox",label:x.captioned,requiredContent:T.caption.requiredContent,setup:function(t){this.setValue(t.data.hasCaption)},commit:function(t){t.setData("hasCaption",this.getValue())}}]},{id:"Upload",hidden:!0,filebrowser:"uploadButton",label:x.uploadTab,elements:[{type:"file",id:"upload",label:x.btnUpload,style:"height:40px"},{type:"fileButton",id:"uploadButton",filebrowser:"info:src",label:x.btnUpload,for:["Upload","upload"]}]}]}}));