CKEDITOR.plugins.add('dialogui');(function(){var a=function(i){var l=this;l._||(l._={});l._['default']=l._.initValue=i['default']||'';l._.required=i.required||false;var j=[l._];for(var k=1;k<arguments.length;k++)j.push(arguments[k]);j.push(true);CKEDITOR.tools.extend.apply(CKEDITOR.tools,j);return l._;},b={build:function(i,j,k){return new CKEDITOR.ui.dialog.textInput(i,j,k);}},c={build:function(i,j,k){return new CKEDITOR.ui.dialog[j.type](i,j,k);}},d={build:function(i,j,k){var l=j.children,m,n=[],o=[];for(var p=0;p<l.length&&(m=l[p]);p++){var q=[];n.push(q);o.push(CKEDITOR.dialog._.uiElementBuilders[m.type].build(i,m,q));}return new CKEDITOR.ui.dialog[j.type](i,o,n,k,j);}},e={isChanged:function(){return this.getValue()!=this.getInitValue();},reset:function(i){this.setValue(this.getInitValue(),i);},setInitValue:function(){this._.initValue=this.getValue();},resetInitValue:function(){this._.initValue=this._['default'];},getInitValue:function(){return this._.initValue;}},f=CKEDITOR.tools.extend({},CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,{onChange:function(i,j){if(!this._.domOnChangeRegistered){i.on('load',function(){this.getInputElement().on('change',function(){if(!i.parts.dialog.isVisible())return;this.fire('change',{value:this.getValue()});},this);},this);this._.domOnChangeRegistered=true;}this.on('change',j);}},true),g=/^on([A-Z]\w+)/,h=function(i){for(var j in i){if(g.test(j)||j=='title'||j=='type')delete i[j];}return i;};CKEDITOR.tools.extend(CKEDITOR.ui.dialog,{labeledElement:function(i,j,k,l){if(arguments.length<4)return;var m=a.call(this,j);m.labelId=CKEDITOR.tools.getNextId()+'_label';var n=this._.children=[],o=function(){var p=[],q=j.required?' cke_required':'';if(j.labelLayout!='horizontal')p.push('<label class="cke_dialog_ui_labeled_label'+q+'" ',' id="'+m.labelId+'"',' for="'+m.inputId+'"',' style="'+j.labelStyle+'">',j.label,'</label>','<div class="cke_dialog_ui_labeled_content" role="presentation">',l.call(this,i,j),'</div>');else{var r={type:'hbox',widths:j.widths,padding:0,children:[{type:'html',html:'<label class="cke_dialog_ui_labeled_label'+q+'"'+' id="'+m.labelId+'"'+' for="'+m.inputId+'"'+' style="'+j.labelStyle+'">'+CKEDITOR.tools.htmlEncode(j.label)+'</span>'},{type:'html',html:'<span class="cke_dialog_ui_labeled_content">'+l.call(this,i,j)+'</span>'}]};CKEDITOR.dialog._.uiElementBuilders.hbox.build(i,r,p);}return p.join('');};CKEDITOR.ui.dialog.uiElement.call(this,i,j,k,'div',null,{role:'presentation'},o);},textInput:function(i,j,k){if(arguments.length<3)return;
a.call(this,j);var l=this._.inputId=CKEDITOR.tools.getNextId()+'_textInput',m={'class':'cke_dialog_ui_input_'+j.type,id:l,type:'text'},n;if(j.validate)this.validate=j.validate;if(j.maxLength)m.maxlength=j.maxLength;if(j.size)m.size=j.size;if(j.controlStyle)m.style=j.controlStyle;var o=this,p=false;i.on('load',function(){o.getInputElement().on('keydown',function(r){if(r.data.getKeystroke()==13)p=true;});o.getInputElement().on('keyup',function(r){if(r.data.getKeystroke()==13&&p){i.getButton('ok')&&setTimeout(function(){i.getButton('ok').click();},0);p=false;}},null,null,1000);});var q=function(){var r=['<div class="cke_dialog_ui_input_',j.type,'" role="presentation"'];if(j.width)r.push('style="width:'+j.width+'" ');r.push('><input ');m['aria-labelledby']=this._.labelId;this._.required&&(m['aria-required']=this._.required);for(var s in m)r.push(s+'="'+m[s]+'" ');r.push(' /></div>');return r.join('');};CKEDITOR.ui.dialog.labeledElement.call(this,i,j,k,q);},textarea:function(i,j,k){if(arguments.length<3)return;a.call(this,j);var l=this,m=this._.inputId=CKEDITOR.tools.getNextId()+'_textarea',n={};if(j.validate)this.validate=j.validate;n.rows=j.rows||5;n.cols=j.cols||20;var o=function(){n['aria-labelledby']=this._.labelId;this._.required&&(n['aria-required']=this._.required);var p=['<div class="cke_dialog_ui_input_textarea" role="presentation"><textarea class="cke_dialog_ui_input_textarea" id="',m,'" '];for(var q in n)p.push(q+'="'+CKEDITOR.tools.htmlEncode(n[q])+'" ');p.push('>',CKEDITOR.tools.htmlEncode(l._['default']),'</textarea></div>');return p.join('');};CKEDITOR.ui.dialog.labeledElement.call(this,i,j,k,o);},checkbox:function(i,j,k){if(arguments.length<3)return;var l=a.call(this,j,{'default':!!j['default']});if(j.validate)this.validate=j.validate;var m=function(){var n=CKEDITOR.tools.extend({},j,{id:j.id?j.id+'_checkbox':CKEDITOR.tools.getNextId()+'_checkbox'},true),o=[],p=CKEDITOR.tools.getNextId()+'_label',q={'class':'cke_dialog_ui_checkbox_input',type:'checkbox','aria-labelledby':p};h(n);if(j['default'])q.checked='checked';if(typeof n.controlStyle!='undefined')n.style=n.controlStyle;l.checkbox=new CKEDITOR.ui.dialog.uiElement(i,n,o,'input',null,q);o.push(' <label id="',p,'" for="',q.id,'">',CKEDITOR.tools.htmlEncode(j.label),'</label>');return o.join('');};CKEDITOR.ui.dialog.uiElement.call(this,i,j,k,'span',null,null,m);},radio:function(i,j,k){if(arguments.length<3)return;a.call(this,j);if(!this._['default'])this._['default']=this._.initValue=j.items[0][1];
if(j.validate)this.validate=j.valdiate;var l=[],m=this,n=function(){var o=[],p=[],q={'class':'cke_dialog_ui_radio_item','aria-labelledby':this._.labelId},r=j.id?j.id+'_radio':CKEDITOR.tools.getNextId()+'_radio';for(var s=0;s<j.items.length;s++){var t=j.items[s],u=t[2]!==undefined?t[2]:t[0],v=t[1]!==undefined?t[1]:t[0],w=CKEDITOR.tools.getNextId()+'_radio_input',x=w+'_label',y=CKEDITOR.tools.extend({},j,{id:w,title:null,type:null},true),z=CKEDITOR.tools.extend({},y,{title:u},true),A={type:'radio','class':'cke_dialog_ui_radio_input',name:r,value:v,'aria-labelledby':x},B=[];if(m._['default']==v)A.checked='checked';h(y);h(z);if(typeof y.controlStyle!='undefined')y.style=y.controlStyle;l.push(new CKEDITOR.ui.dialog.uiElement(i,y,B,'input',null,A));B.push(' ');new CKEDITOR.ui.dialog.uiElement(i,z,B,'label',null,{id:x,'for':A.id},t[0]);o.push(B.join(''));}new CKEDITOR.ui.dialog.hbox(i,[],o,p);return p.join('');};CKEDITOR.ui.dialog.labeledElement.call(this,i,j,k,n);this._.children=l;},button:function(i,j,k){if(!arguments.length)return;if(typeof j=='function')j=j(i.getParentEditor());a.call(this,j,{disabled:j.disabled||false});CKEDITOR.event.implementOn(this);var l=this;i.on('load',function(o){var p=this.getElement();(function(){p.on('click',function(q){l.fire('click',{dialog:l.getDialog()});q.data.preventDefault();});p.on('keydown',function(q){if(q.data.getKeystroke() in {32:1}){l.click();q.data.preventDefault();}});})();p.unselectable();},this);var m=CKEDITOR.tools.extend({},j);delete m.style;var n=CKEDITOR.tools.getNextId()+'_label';CKEDITOR.ui.dialog.uiElement.call(this,i,m,k,'a',null,{style:j.style,href:'javascript:void(0)',title:j.label,hidefocus:'true','class':j['class'],role:'button','aria-labelledby':n},'<span id="'+n+'" class="cke_dialog_ui_button">'+CKEDITOR.tools.htmlEncode(j.label)+'</span>');},select:function(i,j,k){if(arguments.length<3)return;var l=a.call(this,j);if(j.validate)this.validate=j.validate;l.inputId=CKEDITOR.tools.getNextId()+'_select';var m=function(){var n=CKEDITOR.tools.extend({},j,{id:j.id?j.id+'_select':CKEDITOR.tools.getNextId()+'_select'},true),o=[],p=[],q={id:l.inputId,'class':'cke_dialog_ui_input_select','aria-labelledby':this._.labelId};if(j.size!=undefined)q.size=j.size;if(j.multiple!=undefined)q.multiple=j.multiple;h(n);for(var r=0,s;r<j.items.length&&(s=j.items[r]);r++)p.push('<option value="',CKEDITOR.tools.htmlEncode(s[1]!==undefined?s[1]:s[0]).replace(/"/g,'&quot;'),'" /> ',CKEDITOR.tools.htmlEncode(s[0]));if(typeof n.controlStyle!='undefined')n.style=n.controlStyle;
l.select=new CKEDITOR.ui.dialog.uiElement(i,n,o,'select',null,q,p.join(''));return o.join('');};CKEDITOR.ui.dialog.labeledElement.call(this,i,j,k,m);},file:function(i,j,k){if(arguments.length<3)return;if(j['default']===undefined)j['default']='';var l=CKEDITOR.tools.extend(a.call(this,j),{definition:j,buttons:[]});if(j.validate)this.validate=j.validate;var m=function(){l.frameId=CKEDITOR.tools.getNextId()+'_fileInput';var n=CKEDITOR.env.isCustomDomain(),o=['<iframe frameborder="0" allowtransparency="0" class="cke_dialog_ui_input_file" id="',l.frameId,'" title="',j.label,'" src="javascript:void('];o.push(n?"(function(){document.open();document.domain='"+document.domain+"';"+'document.close();'+'})()':'0');o.push(')"></iframe>');return o.join('');};i.on('load',function(){var n=CKEDITOR.document.getById(l.frameId),o=n.getParent();o.addClass('cke_dialog_ui_input_file');});CKEDITOR.ui.dialog.labeledElement.call(this,i,j,k,m);},fileButton:function(i,j,k){if(arguments.length<3)return;var l=a.call(this,j),m=this;if(j.validate)this.validate=j.validate;var n=CKEDITOR.tools.extend({},j),o=n.onClick;n.className=(n.className?n.className+' ':'')+'cke_dialog_ui_button';n.onClick=function(p){var q=j['for'];if(!o||o.call(this,p)!==false){i.getContentElement(q[0],q[1]).submit();this.disable();}};i.on('load',function(){i.getContentElement(j['for'][0],j['for'][1])._.buttons.push(m);});CKEDITOR.ui.dialog.button.call(this,i,n,k);},html:(function(){var i=/^\s*<[\w:]+\s+([^>]*)?>/,j=/^(\s*<[\w:]+(?:\s+[^>]*)?)((?:.|\r|\n)+)$/,k=/\/$/;return function(l,m,n){if(arguments.length<3)return;var o=[],p,q=m.html,r,s;if(q.charAt(0)!='<')q='<span>'+q+'</span>';var t=m.focus;if(t){var u=this.focus;this.focus=function(){u.call(this);typeof t=='function'&&t.call(this);this.fire('focus');};if(m.isFocusable){var v=this.isFocusable;this.isFocusable=v;}this.keyboardFocusable=true;}CKEDITOR.ui.dialog.uiElement.call(this,l,m,o,'span',null,null,'');p=o.join('');r=p.match(i);s=q.match(j)||['','',''];if(k.test(s[1])){s[1]=s[1].slice(0,-1);s[2]='/'+s[2];}n.push([s[1],' ',r[1]||'',s[2]].join(''));};})(),fieldset:function(i,j,k,l,m){var n=m.label,o=function(){var p=[];n&&p.push('<legend>'+n+'</legend>');for(var q=0;q<k.length;q++)p.push(k[q]);return p.join('');};this._={children:j};CKEDITOR.ui.dialog.uiElement.call(this,i,m,l,'fieldset',null,null,o);}},true);CKEDITOR.ui.dialog.html.prototype=new CKEDITOR.ui.dialog.uiElement();CKEDITOR.ui.dialog.labeledElement.prototype=CKEDITOR.tools.extend(new CKEDITOR.ui.dialog.uiElement(),{setLabel:function(i){var j=CKEDITOR.document.getById(this._.labelId);
if(j.getChildCount()<1)new CKEDITOR.dom.text(i,CKEDITOR.document).appendTo(j);else j.getChild(0).$.nodeValue=i;return this;},getLabel:function(){var i=CKEDITOR.document.getById(this._.labelId);if(!i||i.getChildCount()<1)return '';else return i.getChild(0).getText();},eventProcessors:f},true);CKEDITOR.ui.dialog.button.prototype=CKEDITOR.tools.extend(new CKEDITOR.ui.dialog.uiElement(),{click:function(){var i=this;if(!i._.disabled)return i.fire('click',{dialog:i._.dialog});i.getElement().$.blur();return false;},enable:function(){this._.disabled=false;var i=this.getElement();i&&i.removeClass('cke_disabled');},disable:function(){this._.disabled=true;this.getElement().addClass('cke_disabled');},isVisible:function(){return this.getElement().getFirst().isVisible();},isEnabled:function(){return!this._.disabled;},eventProcessors:CKEDITOR.tools.extend({},CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,{onClick:function(i,j){this.on('click',j);}},true),accessKeyUp:function(){this.click();},accessKeyDown:function(){this.focus();},keyboardFocusable:true},true);CKEDITOR.ui.dialog.textInput.prototype=CKEDITOR.tools.extend(new CKEDITOR.ui.dialog.labeledElement(),{getInputElement:function(){return CKEDITOR.document.getById(this._.inputId);},focus:function(){var i=this.selectParentTab();setTimeout(function(){var j=i.getInputElement();j&&j.$.focus();},0);},select:function(){var i=this.selectParentTab();setTimeout(function(){var j=i.getInputElement();if(j){j.$.focus();j.$.select();}},0);},accessKeyUp:function(){this.select();},setValue:function(i){!i&&(i='');return CKEDITOR.ui.dialog.uiElement.prototype.setValue.apply(this,arguments);},keyboardFocusable:true},e,true);CKEDITOR.ui.dialog.textarea.prototype=new CKEDITOR.ui.dialog.textInput();CKEDITOR.ui.dialog.select.prototype=CKEDITOR.tools.extend(new CKEDITOR.ui.dialog.labeledElement(),{getInputElement:function(){return this._.select.getElement();},add:function(i,j,k){var l=new CKEDITOR.dom.element('option',this.getDialog().getParentEditor().document),m=this.getInputElement().$;l.$.text=i;l.$.value=j===undefined||j===null?i:j;if(k===undefined||k===null){if(CKEDITOR.env.ie)m.add(l.$);else m.add(l.$,null);}else m.add(l.$,k);return this;},remove:function(i){var j=this.getInputElement().$;j.remove(i);return this;},clear:function(){var i=this.getInputElement().$;while(i.length>0)i.remove(0);return this;},keyboardFocusable:true},e,true);CKEDITOR.ui.dialog.checkbox.prototype=CKEDITOR.tools.extend(new CKEDITOR.ui.dialog.uiElement(),{getInputElement:function(){return this._.checkbox.getElement();
},setValue:function(i,j){this.getInputElement().$.checked=i;!j&&this.fire('change',{value:i});},getValue:function(){return this.getInputElement().$.checked;},accessKeyUp:function(){this.setValue(!this.getValue());},eventProcessors:{onChange:function(i,j){if(!CKEDITOR.env.ie)return f.onChange.apply(this,arguments);else{i.on('load',function(){var k=this._.checkbox.getElement();k.on('propertychange',function(l){l=l.data.$;if(l.propertyName=='checked')this.fire('change',{value:k.$.checked});},this);},this);this.on('change',j);}return null;}},keyboardFocusable:true},e,true);CKEDITOR.ui.dialog.radio.prototype=CKEDITOR.tools.extend(new CKEDITOR.ui.dialog.uiElement(),{setValue:function(i,j){var k=this._.children,l;for(var m=0;m<k.length&&(l=k[m]);m++)l.getElement().$.checked=l.getValue()==i;!j&&this.fire('change',{value:i});},getValue:function(){var i=this._.children;for(var j=0;j<i.length;j++){if(i[j].getElement().$.checked)return i[j].getValue();}return null;},accessKeyUp:function(){var i=this._.children,j;for(j=0;j<i.length;j++){if(i[j].getElement().$.checked){i[j].getElement().focus();return;}}i[0].getElement().focus();},eventProcessors:{onChange:function(i,j){if(!CKEDITOR.env.ie)return f.onChange.apply(this,arguments);else{i.on('load',function(){var k=this._.children,l=this;for(var m=0;m<k.length;m++){var n=k[m].getElement();n.on('propertychange',function(o){o=o.data.$;if(o.propertyName=='checked'&&this.$.checked)l.fire('change',{value:this.getAttribute('value')});});}},this);this.on('change',j);}return null;}},keyboardFocusable:true},e,true);CKEDITOR.ui.dialog.file.prototype=CKEDITOR.tools.extend(new CKEDITOR.ui.dialog.labeledElement(),e,{getInputElement:function(){var i=CKEDITOR.document.getById(this._.frameId).getFrameDocument();return i.$.forms.length>0?new CKEDITOR.dom.element(i.$.forms[0].elements[0]):this.getElement();},submit:function(){this.getInputElement().getParent().$.submit();return this;},getAction:function(){return this.getInputElement().getParent().$.action;},registerEvents:function(i){var j=/^on([A-Z]\w+)/,k,l=function(n,o,p,q){n.on('formLoaded',function(){n.getInputElement().on(p,q,n);});};for(var m in i){if(!(k=m.match(j)))continue;if(this.eventProcessors[m])this.eventProcessors[m].call(this,this._.dialog,i[m]);else l(this,this._.dialog,k[1].toLowerCase(),i[m]);}return this;},reset:function(){var i=this._,j=CKEDITOR.document.getById(i.frameId),k=j.getFrameDocument(),l=i.definition,m=i.buttons,n=this.formLoadedNumber,o=this.formUnloadNumber,p=i.dialog._.editor.lang.dir,q=i.dialog._.editor.langCode;
if(!n){n=this.formLoadedNumber=CKEDITOR.tools.addFunction(function(){this.fire('formLoaded');},this);o=this.formUnloadNumber=CKEDITOR.tools.addFunction(function(){this.getInputElement().clearCustomData();},this);this.getDialog()._.editor.on('destroy',function(){CKEDITOR.tools.removeFunction(n);CKEDITOR.tools.removeFunction(o);});}function r(){k.$.open();if(CKEDITOR.env.isCustomDomain())k.$.domain=document.domain;var s='';if(l.size)s=l.size-(CKEDITOR.env.ie?7:0);k.$.write(['<html dir="'+p+'" lang="'+q+'"><head><title></title></head><body style="margin: 0; overflow: hidden; background: transparent;">','<form enctype="multipart/form-data" method="POST" dir="'+p+'" lang="'+q+'" action="',CKEDITOR.tools.htmlEncode(l.action),'">','<input type="file" name="',CKEDITOR.tools.htmlEncode(l.id||'cke_upload'),'" size="',CKEDITOR.tools.htmlEncode(s>0?s:''),'" />','</form>','</body></html>','<script>window.parent.CKEDITOR.tools.callFunction('+n+');','window.onbeforeunload = function() {window.parent.CKEDITOR.tools.callFunction('+o+')}</script>'].join(''));k.$.close();for(var t=0;t<m.length;t++)m[t].enable();};if(CKEDITOR.env.gecko)setTimeout(r,500);else r();},getValue:function(){return this.getInputElement().$.value||'';},setInitValue:function(){this._.initValue='';},eventProcessors:{onChange:function(i,j){if(!this._.domOnChangeRegistered){this.on('formLoaded',function(){this.getInputElement().on('change',function(){this.fire('change',{value:this.getValue()});},this);},this);this._.domOnChangeRegistered=true;}this.on('change',j);}},keyboardFocusable:true},true);CKEDITOR.ui.dialog.fileButton.prototype=new CKEDITOR.ui.dialog.button();CKEDITOR.ui.dialog.fieldset.prototype=CKEDITOR.tools.clone(CKEDITOR.ui.dialog.hbox.prototype);CKEDITOR.dialog.addUIElement('text',b);CKEDITOR.dialog.addUIElement('password',b);CKEDITOR.dialog.addUIElement('textarea',c);CKEDITOR.dialog.addUIElement('checkbox',c);CKEDITOR.dialog.addUIElement('radio',c);CKEDITOR.dialog.addUIElement('button',c);CKEDITOR.dialog.addUIElement('select',c);CKEDITOR.dialog.addUIElement('file',c);CKEDITOR.dialog.addUIElement('fileButton',c);CKEDITOR.dialog.addUIElement('html',c);CKEDITOR.dialog.addUIElement('fieldset',d);})();
