/* Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ CKEDITOR.dialog.add("image2",function(t){function e(){var t=this.getValue().match(w);return(t=!(!t||0===parseInt(t[1],10)))||alert(_.invalidLength.replace("%1",_[this.id]).replace("%2","px")),t}function i(){function t(t,a){i.push(e.once(t,function(t){for(var e;e=i.pop();)e.removeListener();a(t)}))}var e=s.createElement("img"),i=[];return function(i,a,n){t("load",function(){var t=N(e);a.call(n,e,t.width,t.height)}),t("error",function(){a(null)}),t("abort",function(){a(null)}),e.setAttribute("src",(K.baseHref||"")+i+"?"+Math.random().toString(16).substring(2))}}function a(){var e=this.getValue();l(!1),e!==u.data.src?(r(e,function(e,i,a){return l(!0),e?(V.setValue(!1===t.config.image2_prefillDimensions?0:i),k.setValue(!1===t.config.image2_prefillDimensions?0:a),p=c=i,g=h=a,void o(E.checkHasNaturalRatio(e))):o(!1)}),f=!0):f?(l(!0),V.setValue(c),k.setValue(h),f=!1):l(!0)}function n(){if(m){var t=this.getValue();if(t&&(t.match(w)||o(!1),"0"!==t)){var e="width"==this.id,i=c||p,a=h||g,t=e?Math.round(t/i*a):Math.round(t/a*i);isNaN(t)||(e?k:V).setValue(t)}}}function o(t){if(v){if("boolean"==typeof t){if(b)return;m=t}else t=V.getValue(),b=!0,(m=!m)&&t&&(t*=h/c,isNaN(t)||k.setValue(Math.round(t)));v[m?"removeClass":"addClass"]("cke_btn_unlocked"),v.setAttribute("aria-checked",m),CKEDITOR.env.hc&&v.getChild(0).setHtml(m?CKEDITOR.env.ie?"■":"▣":CKEDITOR.env.ie?"□":"▢")}}function l(t){t=t?"enable":"disable",V[t](),k[t]()}var s,u,d,r,c,h,p,g,f,m,b,v,y,V,k,C,w=/(^\s*(\d+)(px)?\s*$)|^$/i,D=CKEDITOR.tools.getNextId(),x=CKEDITOR.tools.getNextId(),I=t.lang.image2,_=t.lang.common,R=new CKEDITOR.template('
'+I.lockRatio+''+I.resetSize+"
").output({lockButtonId:D,resetButtonId:x}),E=CKEDITOR.plugins.image2,K=t.config,T=!(!K.filebrowserImageBrowseUrl&&!K.filebrowserBrowseUrl),B=t.widgets.registered.image.features,N=E.getNatural,O=[{id:"src",type:"text",label:_.url,onKeyup:a,onChange:a,setup:function(t){this.setValue(t.data.src)},commit:function(t){t.setData("src",this.getValue())},validate:CKEDITOR.dialog.validate.notEmpty(I.urlMissing)}];return T&&O.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:I.title,minWidth:250,minHeight:100,onLoad:function(){s=this._.element.getDocument(),r=i()},onShow:function(){u=this.getModel(),d=u.parts.image,f=b=m=!1,C=N(d),p=c=C.width,g=h=C.height},contents:[{id:"info",label:I.infoTab,elements:[{type:"vbox",padding:0,children:[{type:"hbox",widths:["100%"],className:"cke_dialog_image_url",children:O}]},{id:"alt",type:"text",label:I.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(I.altMissing):null},{type:"hbox",widths:["25%","25%","50%"],requiredContent:B.dimension.requiredContent,children:[{type:"text",width:"45px",id:"width",label:_.width,validate:e,onKeyUp:n,onLoad:function(){V=this},setup:function(t){this.setValue(t.data.width)},commit:function(t){t.setData("width",this.getValue())}},{type:"text",id:"height",width:"45px",label:_.height,validate:e,onKeyUp:n,onLoad:function(){k=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();v=s.getById(D),y=s.getById(x),v&&(e.addFocusable(v,4+T),v.on("click",function(t){o(),t.data&&t.data.preventDefault()},this.getDialog()),t(v)),y&&(e.addFocusable(y,5+T),y.on("click",function(t){f?(V.setValue(p),k.setValue(g)):(V.setValue(c),k.setValue(h)),t.data&&t.data.preventDefault()},this),t(y))},setup:function(t){o(t.data.lock)},commit:function(t){t.setData("lock",m)},html:R}]},{type:"hbox",id:"alignment",requiredContent:B.align.requiredContent,children:[{id:"align",type:"radio",items:[[_.alignNone,"none"],[_.left,"left"],[_.center,"center"],[_.right,"right"]],label:_.align,setup:function(t){this.setValue(t.data.align)},commit:function(t){t.setData("align",this.getValue())}}]},{id:"hasCaption",type:"checkbox",label:I.captioned,requiredContent:B.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:I.uploadTab,elements:[{type:"file",id:"upload",label:I.btnUpload,style:"height:40px"},{type:"fileButton",id:"uploadButton",filebrowser:"info:src",label:I.btnUpload,"for":["Upload","upload"]}]}]}});