CKEDITOR.dialog.add("colordialog",function(e){function t(){m.getById(k).removeStyle("background-color"),s.getContentElement("picker","selectedColor").setValue(""),l()}function o(e){var t;"td"==(e=e.data.getTarget()).getName()&&(t=e.getChild(0).getHtml())&&(l(),(d=e).setAttribute("aria-selected",!0),d.addClass("cke_colordialog_selected"),s.getContentElement("picker","selectedColor").setValue(t))}function l(){d&&(d.removeClass("cke_colordialog_selected"),d.removeAttribute("aria-selected"),d=null)}function a(e){!e.name&&(e=new CKEDITOR.event(e));var t,o=!/mouse/.test(e.name),l=e.data.getTarget();"td"==l.getName()&&(t=l.getChild(0).getHtml())&&(n(e),o?u=l:p=l,o&&l.addClass(function(e){e=e.replace(/^#/,"");for(var t=0,o=[];2>=t;t++)o[t]=parseInt(e.substr(2*t,2),16);return 165<=.2126*o[0]+.7152*o[1]+.0722*o[2]}(t)?"cke_colordialog_focused_light":"cke_colordialog_focused_dark"),c(t))}function r(){u&&(u.removeClass("cke_colordialog_focused_light"),u.removeClass("cke_colordialog_focused_dark")),c(!1),u=null}function n(e){(e=!/mouse/.test(e.name)&&u)&&(e.removeClass("cke_colordialog_focused_light"),e.removeClass("cke_colordialog_focused_dark")),u||p||c(!1)}function c(e){e?(m.getById(C).setStyle("background-color",e),m.getById(y).setHtml(e)):(m.getById(C).removeStyle("background-color"),m.getById(y).setHtml("&nbsp;"))}function i(t){var l=t.data,a=l.getTarget(),r=l.getKeystroke(),n="rtl"==e.lang.dir;switch(r){case 38:(t=a.getParent().getPrevious())&&(t=t.getChild([a.getIndex()])).focus(),l.preventDefault();break;case 40:(t=a.getParent().getNext())&&(t=t.getChild([a.getIndex()]))&&1==t.type&&t.focus(),l.preventDefault();break;case 32:case 13:o(t),l.preventDefault();break;case n?37:39:(t=a.getNext())?1==t.type&&(t.focus(),l.preventDefault(!0)):(t=a.getParent().getNext())&&(t=t.getChild([0]))&&1==t.type&&(t.focus(),l.preventDefault(!0));break;case n?39:37:(t=a.getPrevious())?(t.focus(),l.preventDefault(!0)):(t=a.getParent().getPrevious())&&((t=t.getLast()).focus(),l.preventDefault(!0))}}var s,d,g,u,p,f=CKEDITOR.dom.element,m=CKEDITOR.document,b=e.lang.colordialog,v={type:"html",html:"&nbsp;"},h=function(e){return CKEDITOR.tools.getNextId()+"_"+e},C=h("hicolor"),y=h("hicolortext"),k=h("selhicolor");return function(){function e(e,o){for(var a=e;a<e+3;a++){var r=new f(g.$.insertRow(-1));r.setAttribute("role","row");for(var n=o;n<o+3;n++)for(var c=0;6>c;c++)t(r.$,"#"+l[n]+l[c]+l[a])}}function t(e,t){var l=new f(e.insertCell(-1));l.setAttribute("class","ColorCell cke_colordialog_colorcell"),l.setAttribute("tabIndex",-1),l.setAttribute("role","gridcell"),l.on("keydown",i),l.on("click",o),l.on("focus",a),l.on("blur",n),l.setStyle("background-color",t);var r=h("color_table_cell");l.setAttribute("aria-labelledby",r),l.append(CKEDITOR.dom.element.createFromHtml('<span id="'+r+'" class="cke_voice_label">'+t+"</span>",CKEDITOR.document))}(g=CKEDITOR.dom.element.createFromHtml('<table tabIndex="-1" class="cke_colordialog_table" aria-label="'+b.options+'" role="grid" style="border-collapse:separate;" cellspacing="0"><caption class="cke_voice_label">'+b.options+'</caption><tbody role="presentation"></tbody></table>')).on("mouseover",a),g.on("mouseout",n);var l="00 33 66 99 cc ff".split(" ");e(0,0),e(3,0),e(0,3),e(3,3);var r=new f(g.$.insertRow(-1));r.setAttribute("role","row"),t(r.$,"#000000");for(var c=0;16>c;c++){var s=c.toString(16);t(r.$,"#"+s+s+s+s+s+s)}t(r.$,"#ffffff")}(),CKEDITOR.document.appendStyleSheet(CKEDITOR.getUrl(CKEDITOR.plugins.get("colordialog").path+"dialogs/colordialog.css")),{title:b.title,minWidth:360,minHeight:220,onShow:function(e){if(!e.data.selectionColor||e.data.selectionColor==e.data.automaticTextColor||"#rgba(0, 0, 0, 0)"==e.data.selectionColor&&"back"==e.data.type)t(),r();else{var o,l=e.data.selectionColor;e=this.parts.contents.getElementsByTag("td").toArray(),s.getContentElement("picker","selectedColor").setValue(l),CKEDITOR.tools.array.forEach(e,function(e){o=CKEDITOR.tools.convertRgbToHex(e.getStyle("background-color")),l===o&&(e.focus(),u=e)})}},onLoad:function(){s=this},onHide:function(){t(),r()},contents:[{id:"picker",label:b.title,accessKey:"I",elements:[{type:"hbox",padding:0,widths:["70%","10%","30%"],children:[{type:"html",html:"<div></div>",onLoad:function(){CKEDITOR.document.getById(this.domId).append(g)},focus:function(){(u||this.getElement().getElementsByTag("td").getItem(0)).focus()}},v,{type:"vbox",padding:0,widths:["70%","5%","25%"],children:[{type:"html",html:"<span>"+b.highlight+'</span><div id="'+C+'" style="border: 1px solid; height: 74px; width: 74px;"></div><div id="'+y+'">&nbsp;</div><span>'+b.selected+'</span><div id="'+k+'" style="border: 1px solid; height: 20px; width: 74px;"></div>'},{type:"text",label:b.selected,labelStyle:"display:none",id:"selectedColor",style:"width: 76px;margin-top:4px",onChange:function(){try{m.getById(k).setStyle("background-color",this.getValue())}catch(e){t()}}},v,{type:"button",id:"clear",label:b.clear,onClick:t}]}]}]}]}});