/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:28
*/
KISSY.add("editor/plugin/color/colorPicker/dialog",function(e,o,r){function h(a){if(e.isArray(a))return a;var b=RegExp;if(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.test(a))return f([b.$1,b.$2,b.$3],function(a){return parseInt(a,16)});if(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test(a))return f([b.$1,b.$2,b.$3],function(a){return parseInt(a+a,16)});if(/^rgb\((.*),(.*),(.*)\)$/i.test(a))return f([b.$1,b.$2,b.$3],function(a){return 0<a.indexOf("%")?2.55*parseFloat(a,10):a|0})}function j(a){var a="0"+
a,b=a.length;return a.slice(b-2,b)}function m(a){a=h(a);return"#"+j(a[0].toString(16))+j(a[1].toString(16))+j(a[2].toString(16))}function p(a){this.editor=a;this._init()}var f=e.map,q=e.DOM;q.addStyleSheet(".ks-editor-color-advanced-picker-left {float:left;display:inline;margin-left:10px;}.ks-editor-color-advanced-picker-right {float:right;width:50px;display:inline;margin:13px 10px 0 0;cursor:crosshair;}.ks-editor-color-advanced-picker-right a {height:2px;line-height:0;fontSize:0;display:block;}.ks-editor-color-advanced-picker-left ul{float:left;}.ks-editor-color-advanced-picker-left li,.ks-editor-color-advanced-picker-left a{overflow:hidden;width:15px;height:16px;line-height:0;fontSize:0;display:block;}.ks-editor-color-advanced-picker-left a:hover{width:13px;height:13px;border:1px solid white;}.ks-editor-color-advanced-indicator {margin-left:10px;*zoom:1;display:inline-block;*display:inline;width:68px;height:24px;vertical-align:middle;line-height:0;overflow:hidden;}",
"ks-editor-color-advanced");var n=function(){function a(a,g,d){for(var c=[],a=b(a),g=b(g),i=(g[0]-a[0])/d,k=(g[1]-a[1])/d,e=(g[2]-a[2])/d,l=0,h=a[0],j=a[1],a=a[2];l<d;l++)c[l]=[h,j,a],h+=i,j+=k,a+=e;c[l]=g;return f(c,function(a){return f(a,function(a){return Math.min(Math.max(0,Math.floor(a)),255)})})}function b(a){var b=h(a);if(void 0===b){c||(c=document.createElement("textarea"),c.style.display="none",q.prepend(c,document.body));try{c.style.color=a}catch(d){return[0,0,0]}document.defaultView?b=
h(document.defaultView.getComputedStyle(c,null).color):(a=c.createTextRange().queryCommandValue("ForeColor"),b=[a&255,(a&65280)>>>8,(a&16711680)>>>16])}return b}var c;return function(b,c){var d=[],e=b.length;void 0===c&&(c=20);if(1==e)d=a(b[0],b[0],c);else if(1<e)for(var i=0,e=e-1;i<e;i++){var k=a(b[i],b[i+1],c[i]||c);i<e-1&&k.pop();d=d.concat(k)}return d}}(),s="<div class='ks-editor-color-advanced-picker'><div class='ks-clear'><div class='ks-editor-color-advanced-picker-left'>"+("<ul>"+f(n("red,orange,yellow,green,cyan,blue,purple".split(","),
5),function(a){return f(n(["white","rgb("+a.join(",")+")","black"],5),function(a){return"<li><a style='background-color:"+m(a)+"' href='#'></a></li>"}).join("")}).join("</ul><ul>")+"</ul>")+"</div><div class='ks-editor-color-advanced-picker-right'></div></div><div style='padding:10px;'><label>颜色值： <input style='width:100px' class='ks-editor-color-advanced-value'/></label><span class='ks-editor-color-advanced-indicator'></span></div></div>",t=o.Utils.addRes,u=o.Utils.destroyRes;e.augment(p,{_init:function(){var a=
this;a.dialog=new r.Dialog({mask:!0,headerContent:"颜色拾取器",bodyContent:s,footerContent:"<div style='padding:5px 20px 20px;'><a class='ks-editor-button ks-editor-color-advanced-ok ks-inline-block'>确定</a>&nbsp;&nbsp;&nbsp;<a class='ks-editor-button  ks-editor-color-advanced-cancel ks-inline-block'>取消</a></div>",autoRender:!0,width:"550px"});var b=a.dialog,c=b.get("body"),f=b.get("footer"),g=c.one(".ks-editor-color-advanced-indicator"),d=c.one(".ks-editor-color-advanced-value"),h=c.one(".ks-editor-color-advanced-picker-left");
c.one(".ks-editor-color-advanced-picker-right");b=f.one(".ks-editor-color-advanced-ok");f=f.one(".ks-editor-color-advanced-cancel");b.on("click",function(b){var c=e.trim(d.val()),f=a.cmd;/^#([a-f0-9]{1,2}){3,3}$/i.test(c)?(a.hide(),setTimeout(function(){a.editor.execCommand(f,d.val())},0),b.halt()):alert("请输入正确的颜色代码")});d.on("change",function(){var a=e.trim(d.val());/^#([a-f0-9]{1,2}){3,3}$/i.test(a)?g.css("background-color",a):alert("请输入正确的颜色代码")});f.on("click",function(b){a.hide();b&&b.halt()});
c.on("click",function(b){b.halt();b=new e.Node(b.target);if("a"==b.nodeName()){var c=m(b.css("background-color"));h.contains(b)&&a._detailColor(c);d.val(c);g.css("background-color",c)}});t.call(a,b,d,f,c,a.dialog);a._detailColor("#FF9900");d.val("#FF9900");g.css("background-color","#FF9900")},_detailColor:function(a){this.dialog.get("body").one(".ks-editor-color-advanced-picker-right").html(f(n(["#ffffff",a,"#000000"],40),function(a){return"<a style='background-color:"+m(a)+"'></a>"}).join(""))},
show:function(a){this.cmd=a;this.dialog.show()},hide:function(){this.dialog.hide()},destroy:function(){u.call(this)}});return p},{requires:["editor","../../overlay/"]});
