function clean_css_value(a){if(!(m=a.match(/^(\d+(?:\.\d*)?|\.\d+)([^\d\s]+)?$/m)))return defSize;if(!m[1])return"";a=Math.floor(m[1]);if(!m[2])return a+"px";switch(m[2]){case "em":case "%":return m[1]+m[2];default:return a+"px"}}function getColorBgVal(a){myWidgetData.QrColorBg=a.value;a=getQrImage(myWidgetData);domPreviewImg.src=a;domPreviewImgAdv.src=a}function getColorPtVal(a){myWidgetData.QrColorPt=a.value;a=getQrImage(myWidgetData);domPreviewImg.src=a;domPreviewImgAdv.src=a}
function getBorderColor(a){domPreviewImg.setAttribute("cke_qr_borderColor",a.value);domPreviewImg.style.borderColor=a.value;domPreviewImgAdv.style.borderColor=a.value}function getborderWidth(a){var d=a.value+"px";domPreviewImg.getAttribute("cke_qr_defCellSize");domPreviewImg.setAttribute("cke_qr_borderWidth",a.value);domPreviewImg.style.borderWidth=d;domPreviewImgAdv.style.borderWidth=d}
function getborderSpace(a){myWidgetData.QrMargin=a.value;a=getQrImage(myWidgetData);domPreviewImg.src=a;domPreviewImgAdv.src=a}function qrStrChanged(a,d){if(""==a.value.trim())return alert(d),!1;myWidgetData.QrUrl=a.value;var b=getQrImage(myWidgetData);domPreviewImg.src=b;domPreviewImgAdv.src=b}
function getHtmlPreview(a,d){var b="";return b+='\x3cdiv style\x3d"width: 70%; border-radius: 10px; text-align: center;margin: auto;border: 2px solid gray;"\x3e',b+='\x3cp style\x3d"font-weight: bold;text-align: center;"\x3e'+d+"\x3c/p\x3e",b+='\x3cimg id\x3d"previewImg_'+a+'" src\x3d"" alt\x3d"QR Code" style\x3d"width: 50%; border:5px solid black"\x3e',b+"\x3c/div\x3e"}
function getHtmlBorder(a,d,b,e){var f=d+"_vId",c='\x3cform style\x3d"text-align: center;"\x3e';return c+='\x3cinput type\x3d"range" style\x3d"vertical-align: middle; width: 50%; " name\x3d"'+d+'" min\x3d"'+b+'" max\x3d"'+e+'" ',c+='onchange\x3d"get'+d+'(this);" oninput\x3d"document.getElementById(\''+f+'\').innerText \x3d this.value;" value\x3d"5"\x3e',c+='\x3cspan style\x3d"font-weight: bold; margin-left: 15px;"\x3e'+a+"\x3c/span\x3e",c+='\x3cspan id\x3d"'+f+'" style\x3d"font-weight: bold; margin-left: 15px; color: tomato;"\x3eVALUE\x3c/span\x3e',
c+='\x3cspan style\x3d"font-weight: bold; color: tomato;"\x3e Px\x3c/span\x3e',c+"\x3c/form\x3e"}function getHtmlColor(a,d){var b='\x3cform style\x3d"text-align: center;"\x3e';return b+='\x3cinput type\x3d"color" style\x3d" width: 50px; height: 20px; border:1px black solid;  vertical-align: middle;" onchange\x3d"',b+=a+'" name\x3d"colorBg" value\x3d"#000000"\x3e\x3cspan style\x3d"font-weight: bold; margin-left: 15px;"\x3e'+d+"\x3c/span\x3e",b+"\x3c/form\x3e"}
function getHtmlCorrectionLevel(a,d,b,e,f){var c='\x3cdiv style\x3d"border: 1px solid red; padding:5px; border-radius: 10px;"\x3e';return c+='\x3cp style\x3d"text-align: center; font-weight: bold;color: tomato;"\x3e'+a+"\x3c/p\x3e",c+='\x3cform style\x3d"text-align: center;"\x3e',c+='\x3cinput type\x3d"radio" name\x3d"cor_level" value\x3d"L" onclick\x3d"handleCLClick(this);"\x3e\x26nbsp;\x26nbsp;'+d+"\x26nbsp;\x26nbsp;",c+='\x3cinput type\x3d"radio" name\x3d"cor_level" value\x3d"M" onclick\x3d"handleCLClick(this);"\x3e\x26nbsp;\x26nbsp;'+
b+"\x26nbsp;\x26nbsp;",c+='\x3cinput type\x3d"radio" name\x3d"cor_level" value\x3d"Q" onclick\x3d"handleCLClick(this);"\x3e\x26nbsp;\x26nbsp;'+e+"\x26nbsp;\x26nbsp;",c+='\x3cinput type\x3d"radio" name\x3d"cor_level" value\x3d"H" onclick\x3d"handleCLClick(this);"\x3e\x26nbsp;\x26nbsp;'+f+"\x26nbsp;\x26nbsp;",c+"\x3c/form\x3e\x3cdiv\x3e"}
function getQrStrHtml(a,d){var b=a+"\x3cbr\x3e";return b+='\x3cinput class\x3d"cke_dialog_ui_input_text" id\x3d"cke_qstring" type\x3d"text" value\x3d""',b+('name\x3d"QR String" onchange\x3d"qrStrChanged(this,\''+d+"')\"\x3e")}function setSelectedValue(a,d){for(var b=a.getElement("tab-adv","correctionLevel").getElementsByTag("form").$[0].elements.namedItem("cor_level"),e=0;e<b.length;e++)if(b[e].value==d){b[e].checked=!0;break}}
function getSelectedValue(a){a=a.getElement("tab-adv","correctionLevel").getElementsByTag("form").$[0].elements.namedItem("cor_level");for(var d=0;d<a.length;d++)if(a[d].checked)return a[d].value}function handleCLClick(a){myWidgetData.QrCorLevel=a.value;a=getQrImage(myWidgetData);domPreviewImg.src=a;domPreviewImgAdv.src=a}var domPreviewImg=null,domPreviewImgAdv=null,myWidgetData=null;
CKEDITOR.dialog.add("yaqr",function(a){return{title:a.lang.yaqr.qrProp,minWidth:400,minHeight:200,contents:[{id:"tab-basic",label:a.lang.yaqr.basicSettings,elements:[{type:"html",id:"preview",html:getHtmlPreview("ref",a.lang.yaqr.preview),setup:function(a){myWidgetData=Object.assign({},a.data);previewImg_ref=this.getDialog().getContentElement("tab-basic","preview").domId;(domPreviewImg=document.getElementById(previewImg_ref).getElementsByTagName("img")[0]).src=getQrImage(myWidgetData)},commit:function(a){}},
{type:"html",id:"qrString",label:"qrString",html:getQrStrHtml(a.lang.yaqr.qrString,a.lang.yaqr.qrString+" "+a.lang.yaqr.badQRmsg),setup:function(a){document.getElementById("cke_qstring").value=a.data.QrUrl},commit:function(a){a.setData("QrUrl",document.getElementById("cke_qstring").value)}},{type:"checkbox",id:"target",label:a.lang.yaqr.targetText,"default":"checked",setup:function(a){this.setValue("_blank"===a.data.QrUrlTarget)},commit:function(a){var b="_self";this.getValue()&&(b="_blank");a.setData("QrUrlTarget",
b)}},{type:"text",id:"qrSize",label:a.lang.yaqr.qrSizeLabel,validate:CKEDITOR.dialog.validate.notEmpty(a.lang.yaqr.qrSizeLabel+" "+a.lang.yaqr.badQRmsg),setup:function(a){this.setValue(clean_css_value(a.data.QRSize))},commit:function(a){var b=clean_css_value(this.getValue());a.setData("QRSize",b)}}]},{id:"tab-adv",label:a.lang.yaqr.advSettings,elements:[{type:"html",id:"preview",html:getHtmlPreview("adv",a.lang.yaqr.preview),setup:function(a){previewImg_adv=this.getDialog().getContentElement("tab-adv",
"preview").domId;(domPreviewImgAdv=document.getElementById(previewImg_adv).getElementsByTagName("img")[0]).src=getQrImage(myWidgetData)},commit:function(a){}},{type:"vbox",title:a.lang.yaqr.setQrTitle,style:"border: 1px solid tomato; border-radius: 10px; text-align: center;",children:[{type:"html",id:"borderQR",style:"text-align: center; font-weight: bold;color: tomato;",html:"\x3cp\x3e"+a.lang.yaqr.qrPropColor+"\x3c/p\x3e"},{type:"html",id:"colorBg",label:"colorBg",html:getHtmlColor("getColorBgVal(this)",
a.lang.yaqr.backColor),style:"text-align: center;",setup:function(a){this.getElement("tab-adv","colorBg").getElementsByTag("input").$[0].value=a.data.QrColorBg},commit:function(a){var b=this.getElement("tab-adv","colorBg").getElementsByTag("input").$[0].value;a.setData("QrColorBg",b)}},{type:"html",id:"colorPt",label:"colorPt",html:getHtmlColor("getColorPtVal(this)",a.lang.yaqr.ptColor),setup:function(a){this.getElement("tab-adv","colorPt").getElementsByTag("input").$[0].value=a.data.QrColorPt},commit:function(a){var b=
this.getElement("tab-adv","colorPt").getElementsByTag("input").$[0].value;a.setData("QrColorPt",b)}}]},{type:"vbox",title:a.lang.yaqr.setBPTitle,style:"border: 1px solid tomato; border-radius: 10px; text-align: center;",children:[{type:"html",id:"borderTitle",style:"text-align: center; font-weight: bold;color: tomato;",html:"\x3cp\x3e"+a.lang.yaqr.borderProp+"\x3c/p\x3e"},{type:"html",id:"borderColor",label:"borderColor",html:'\x3cp\x3e\x3cinput type\x3d"color" style\x3d" width: 50px; height: 20px; border:1px black solid;  vertical-align: middle;" onchange\x3d"getBorderColor(this)" name\x3d"borderColor" value\x3d"#000000"\x3e\x3cspan style\x3d"font-weight: bold; margin-left: 15px;"\x3e'+
a.lang.yaqr.borderColor+"\x3c/span\x3e\x3c/p\x3e",style:"text-align: center;",setup:function(a){this.getElement("tab-adv","borderColor").getElementsByTag("input").$[0].value=a.data.QrBorderColor;domPreviewImg.style.borderColor=a.data.QrBorderColor;domPreviewImgAdv.style.borderColor=a.data.QrBorderColor},commit:function(a){var b=this.getElement("tab-adv","borderColor").getElementsByTag("input").$[0].value;a.setData("QrBorderColor",b)}},{type:"html",id:"borderWidth",label:"borderWidth",html:getHtmlBorder(a.lang.yaqr.borderWidth,
"borderWidth",0,10),setup:function(a){this.getElement("tab-adv","borderWidth").getElementsByTag("input").$[0].value=a.data.QrBorderWidth;document.getElementById("borderWidth_vId").innerText=a.data.QrBorderWidth;domPreviewImg.style.borderWidth=a.data.QrBorderWidth+"px";domPreviewImgAdv.style.borderWidth=a.data.QrBorderWidth+"px"},commit:function(a){var b=this.getElement("tab-adv","borderWidth").getElementsByTag("input").$[0].value;a.setData("QrBorderWidth",b)}},{type:"html",id:"borderSpace",label:"borderSpace",
html:getHtmlBorder(a.lang.yaqr.borderSpace,"borderSpace",0,100),setup:function(a){this.getElement("tab-adv","borderSpace").getElementsByTag("input").$[0].value=a.data.QrMargin;document.getElementById("borderSpace_vId").innerText=a.data.QrMargin},commit:function(a){var b=this.getElement("tab-adv","borderSpace").getElementsByTag("input").$[0].value;a.setData("QrMargin",b)}}]},{type:"html",id:"correctionLevel",title:a.lang.yaqr.setECLTitle,label:"correctionLevel",html:getHtmlCorrectionLevel(a.lang.yaqr.corLevel,
a.lang.yaqr.low,a.lang.yaqr.medium,a.lang.yaqr.quality,a.lang.yaqr.high),setup:function(a){console.log("setup tab-adv correctionLevel ",a.data.QrCorLevel);setSelectedValue(this,a.data.QrCorLevel)},commit:function(a){this.getElement("tab-adv","correctionLevel").getElementsByTag("form").$[0];var b=getSelectedValue(this);console.log("commit tab-adv correctionLevel ",b);a.setData("QrCorLevel",b)}}]}]}});