/*
* Kendo UI Beta v2013.2.716 (http://kendoui.com)
* Copyright 2013 Telerik AD. All rights reserved.
*
* Kendo UI Beta license terms available at
* http://www.kendoui.com/purchase/license-agreement/kendo-ui-beta.aspx
*/
("function"==typeof define&&define.amd?define:function(e,t){return t()})(["./kendo.core.min","./kendo.popup.min","./kendo.slider.min","./kendo.userevents.min"],function(){!function(e,t,n){function s(e,t,n){n=o(n),n&&!n.equals(e.color())&&("change"==t&&(e._value=n),n=1!=n.a?n.toCssRgba():n.toCss(),e.trigger(t,{value:n}))}function i(e,t,n){for(n||(n="0"),e=e.toString(16);t>e.length;)e="0"+e;return e}function a(e){return parseFloat((+e).toFixed(3))}function o(e,s){if(null==e||"transparent"==e)return null;if(e instanceof H)return e;var i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(i)return new R(t(i[1],16),t(i[2],16),t(i[3],16),1);if(i=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(e))return new R(t(i[1]+i[1],16),t(i[2]+i[2],16),t(i[3]+i[3],16),1);if(i=/^rgb\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/.exec(e))return new R(t(i[1],10),t(i[2],10),t(i[3],10),1);if(i=/^rgba\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9.]+)\s*\)/.exec(e))return new R(t(i[1],10),t(i[2],10),t(i[3],10),parseFloat(i[4]));if(i=/^rgb\(\s*([0-9]*\.?[0-9]+)%\s*,\s*([0-9]*\.?[0-9]+)%\s*,\s*([0-9]*\.?[0-9]+)%\s*\)/.exec(e))return new E(parseFloat(i[1])/100,parseFloat(i[2])/100,parseFloat(i[3])/100,1);if(i=/^rgba\(\s*([0-9]*\.?[0-9]+)%\s*,\s*([0-9]*\.?[0-9]+)%\s*,\s*([0-9]*\.?[0-9]+)%\s*,\s*([0-9.]+)\s*\)/.exec(e))return new E(parseFloat(i[1])/100,parseFloat(i[2])/100,parseFloat(i[3])/100,parseFloat(i[4]));if(!s)throw Error("Cannot parse color: "+e);return n}function r(e,t,n){var s,i;return e=Array.prototype.slice.call(e),s=e.length,i=e.indexOf(t),0>i?0>n?e[s-1]:e[0]:(i+=n,0>i?i+=s:i%=s,e[i])}function l(e){e.preventDefault()}function c(e,t){return function(){return e.apply(t,arguments)}}var u=window.kendo,d=u.Class,p=u.ui,C=p.Widget,h=u.keys,f="background-color",F="k-state-selected",v="000000,7f7f7f,880015,ed1c24,ff7f27,fff200,22b14c,00a2e8,3f48cc,a349a4,ffffff,c3c3c3,b97a57,ffaec9,ffc90e,efe4b0,b5e61d,99d9ea,7092be,c8bfe7",g="FFFFFF,FFCCFF,FF99FF,FF66FF,FF33FF,FF00FF,CCFFFF,CCCCFF,CC99FF,CC66FF,CC33FF,CC00FF,99FFFF,99CCFF,9999FF,9966FF,9933FF,9900FF,FFFFCC,FFCCCC,FF99CC,FF66CC,FF33CC,FF00CC,CCFFCC,CCCCCC,CC99CC,CC66CC,CC33CC,CC00CC,99FFCC,99CCCC,9999CC,9966CC,9933CC,9900CC,FFFF99,FFCC99,FF9999,FF6699,FF3399,FF0099,CCFF99,CCCC99,CC9999,CC6699,CC3399,CC0099,99FF99,99CC99,999999,996699,993399,990099,FFFF66,FFCC66,FF9966,FF6666,FF3366,FF0066,CCFF66,CCCC66,CC9966,CC6666,CC3366,CC0066,99FF66,99CC66,999966,996666,993366,990066,FFFF33,FFCC33,FF9933,FF6633,FF3333,FF0033,CCFF33,CCCC33,CC9933,CC6633,CC3333,CC0033,99FF33,99CC33,999933,996633,993333,990033,FFFF00,FFCC00,FF9900,FF6600,FF3300,FF0000,CCFF00,CCCC00,CC9900,CC6600,CC3300,CC0000,99FF00,99CC00,999900,996600,993300,990000,66FFFF,66CCFF,6699FF,6666FF,6633FF,6600FF,33FFFF,33CCFF,3399FF,3366FF,3333FF,3300FF,00FFFF,00CCFF,0099FF,0066FF,0033FF,0000FF,66FFCC,66CCCC,6699CC,6666CC,6633CC,6600CC,33FFCC,33CCCC,3399CC,3366CC,3333CC,3300CC,00FFCC,00CCCC,0099CC,0066CC,0033CC,0000CC,66FF99,66CC99,669999,666699,663399,660099,33FF99,33CC99,339999,336699,333399,330099,00FF99,00CC99,009999,006699,003399,000099,66FF66,66CC66,669966,666666,663366,660066,33FF66,33CC66,339966,336666,333366,330066,00FF66,00CC66,009966,006666,003366,000066,66FF33,66CC33,669933,666633,663333,660033,33FF33,33CC33,339933,336633,333333,330033,00FF33,00CC33,009933,006633,003333,000033,66FF00,66CC00,669900,666600,663300,660000,33FF00,33CC00,339900,336600,333300,330000,00FF00,00CC00,009900,006600,003300,000000",_={apply:"Apply",cancel:"Cancel"},k=".kendoColorTools",b="click"+k,y="keydown"+k,m=u.support.browser,w=m.msie&&m.version<9,S=C.extend({init:function(e,t){var n,s=this;C.fn.init.call(s,e,t),e=s.element,t=s.options,s._value=t.value=o(t.value),n=s._ariaId=t.ariaId,n&&e.attr("aria-labelledby",n),t._standalone&&(s._triggerSelect=s._triggerChange)},options:{name:"ColorSelector",value:null,_standalone:!0},events:["change","select","cancel"],color:function(e){return e!==n&&this._updateUI(this._value=o(e)),this._value},value:function(e){return e=this.color(e),e&&(e=this.options.opacity?e.toCssRgba():e.toCss()),e||null},enable:function(t){0===arguments.length&&(t=!0),t?e(".k-disabled-overlay",this.wrapper).remove():this.wrapper.append("
"),this._onEnable(t)},_select:function(e,t){var n=this._value;e=this.color(e),t||(e.equals(n)?this._standalone||this.trigger("cancel"):this.trigger("change",{value:this.value()}))},_triggerSelect:function(e){s(this,"select",e)},_triggerChange:function(e){s(this,"change",e)},destroy:function(){this.element&&this.element.off(k),this.wrapper&&this.wrapper.off(k).find("*").off(k),this.wrapper=null,C.fn.destroy.call(this)},_updateUI:e.noop,_selectOnHide:function(){return null},_cancel:function(){this.trigger("cancel")}}),I=S.extend({init:function(t,n){var s,i,a,r,l=this;if(S.fn.init.call(l,t,n),t=l.wrapper=l.element,n=l.options,s=n.palette,"websafe"==s?(s=g,n.columns=18):"basic"==s&&(s=v),"string"==typeof s&&(s=s.split(",")),e.isArray(s)&&(s=e.map(s,function(e){return o(e)})),t.addClass("k-widget k-colorpalette").append(e(l._template({colors:s,tileSize:n.tileSize,value:l._value,id:n.ariaId}))).on(b,".k-item",function(t){l._select(e(t.currentTarget).css(f))}).attr("tabIndex",0).on(y,c(l._keydown,l)),r=n.tileSize){if(/number|string/.test(typeof r))i=a=parseFloat(r);else{if("object"!=typeof r)throw Error("Unsupported value for the 'tileSize' argument");i=parseFloat(r.width),a=parseFloat(r.height)}t.find(".k-item").css({width:i-2,height:a-2})}n.columns&&t.css("width",n.columns*(i||14))},focus:function(){this.wrapper.focus()},options:{name:"ColorPalette",columns:10,tileSize:null,palette:"basic"},_onEnable:function(e){e?this.wrapper.removeAttr("tabIndex"):this.wrapper.attr("tabIndex",0)},_keydown:function(t){var n,s,i=this,a=i.wrapper,c=a.find(".k-item"),u=c.filter("."+F).get(0),d=t.keyCode;if(d==h.LEFT?n=r(c,u,-1):d==h.RIGHT?n=r(c,u,1):d==h.DOWN?n=r(c,u,i.options.columns):d==h.UP?n=r(c,u,-i.options.columns):d==h.ENTER?(l(t),u&&this._select(e(u).css(f))):d==h.ESC&&this._cancel(),n){l(t),n=e(n),e(u).removeClass(F).removeAttr("aria-selected"),n.addClass(F).attr("aria-selected",!0);try{s=o(n.css(f)),i._triggerSelect(s)}catch(p){}}},_updateUI:function(t){var n=this,s=null;n.wrapper.find(".k-item."+F).removeClass(F).removeAttr("aria-selected"),n.wrapper.find(".k-item").each(function(){var n=o(e(this).css(f));n&&n.equals(t)&&(s=this)}),e(s).addClass(F).attr("aria-selected",!0)},_template:u.template('# for (var i = 0; i < colors.length; i++) { #- '+"
"+"# } #"+"
")}),x=S.extend({init:function(t,n){var s=this;S.fn.init.call(s,t,n),n=s.options,t=s.element,s.wrapper=t.addClass("k-widget k-flatcolorpicker").append(s._template(n)),s._hueElements=e(".k-hsv-rectangle, .k-transparency-slider .k-slider-track",t),s._selectedColor=e(".k-selected-color-display",t),s._colorAsText=e("input.k-color-value",t),s._sliders(),s._hsvArea(),s._updateUI(s._value||new E(1,0,0,1)),t.find("input.k-color-value").on(y,function(t){var n,i;if(t.keyCode==h.ENTER)try{n=o(this.value),i=s.color(),s._select(n,n.equals(i))}catch(a){e(this).addClass("k-state-error")}}).end().on(b,".k-controls button.apply",function(){s._select(s._getHSV())}).on(b,".k-controls button.cancel",function(){s._updateUI(s.color()),s._cancel()}),w&&s._applyIEFilter()},destroy:function(){this._hueSlider.destroy(),this._opacitySlider&&this._opacitySlider.destroy(),this._hueSlider=this._opacitySlider=this._hsvRect=this._hsvHandle=this._hueElements=this._selectedColor=this._colorAsText=null,S.fn.destroy.call(this)},options:{name:"FlatColorPicker",opacity:!1,buttons:!1,input:!0,preview:!0,messages:_},_applyIEFilter:function(){var e=this.element.find(".k-hue-slider .k-slider-track")[0],t=e.currentStyle.backgroundImage;t=t.replace(/^url\([\'\"]?|[\'\"]?\)$/g,""),e.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+t+"', sizingMethod='scale')"},_sliders:function(){function e(e){n._updateUI(n._getHSV(e.value,null,null,null))}function t(e){n._updateUI(n._getHSV(null,null,null,e.value/100))}var n=this,s=n.element;n._hueSlider=s.find(".k-hue-slider").kendoSlider({min:0,max:359,tickPlacement:"none",showButtons:!1,slide:e,change:e}).data("kendoSlider"),n._opacitySlider=s.find(".k-transparency-slider").kendoSlider({min:0,max:100,tickPlacement:"none",showButtons:!1,slide:t,change:t}).data("kendoSlider")},_hsvArea:function(){function e(e,n){var s=this.offset,i=e-s.left,a=n-s.top,o=this.width,r=this.height;i=0>i?0:i>o?o:i,a=0>a?0:a>r?r:a,t._svChange(i/o,1-a/r)}var t=this,n=t.element,s=n.find(".k-hsv-rectangle"),i=s.find(".k-draghandle").attr("tabIndex",0).on(y,c(t._keydown,t));t._hsvEvents=new u.UserEvents(s,{global:!0,press:function(t){this.offset=u.getOffset(s),this.width=s.width(),this.height=s.height(),i.focus(),e.call(this,t.x.location,t.y.location)},start:function(){s.addClass("k-dragging"),i.focus()},move:function(t){t.preventDefault(),e.call(this,t.x.location,t.y.location)},end:function(){s.removeClass("k-dragging")}}),t._hsvRect=s,t._hsvHandle=i},_onEnable:function(e){this._hueSlider.enable(e),this._opacitySlider&&this._opacitySlider.enable(e),this.wrapper.find("input").attr("disabled",!e);var t=this._hsvRect.find(".k-draghandle");e?t.attr("tabIndex",0):t.removeAttr("tabIndex")},_keydown:function(e){function t(t,n){var i=s._getHSV();i[t]+=n*(e.shiftKey?.01:.05),i[t]<0&&(i[t]=0),i[t]>1&&(i[t]=1),s._updateUI(i),l(e)}function n(t){var n=s._getHSV();n.h+=t*(e.shiftKey?1:5),n.h<0&&(n.h=0),n.h>359&&(n.h=359),s._updateUI(n),l(e)}var s=this;switch(e.keyCode){case h.LEFT:e.ctrlKey?n(-1):t("s",-1);break;case h.RIGHT:e.ctrlKey?n(1):t("s",1);break;case h.UP:t(e.ctrlKey&&s._opacitySlider?"a":"v",1);break;case h.DOWN:t(e.ctrlKey&&s._opacitySlider?"a":"v",-1);break;case h.ENTER:s._select(s._getHSV());break;case h.F2:s.wrapper.find("input.k-color-value").focus().select();break;case h.ESC:s._cancel()}},focus:function(){this._hsvHandle.focus()},_getHSV:function(e,t,n,s){var i=this._hsvRect,a=i.width(),o=i.height(),r=this._hsvHandle.position();return null==e&&(e=this._hueSlider.value()),null==t&&(t=r.left/a),null==n&&(n=1-r.top/o),null==s&&(s=this._opacitySlider?this._opacitySlider.value()/100:1),new B(e,t,n,s)},_svChange:function(e,t){var n=this._getHSV(null,e,t,null);this._updateUI(n)},_updateUI:function(e){var t=this,n=t._hsvRect;e&&(this._colorAsText.removeClass("k-state-error"),t._selectedColor.css(f,e.toDisplay()),t._colorAsText.val(t._opacitySlider?e.toCssRgba():e.toCss()),t._triggerSelect(e),e=e.toHSV(),t._hsvHandle.css({left:e.s*n.width()+"px",top:(1-e.v)*n.height()+"px"}),t._hueElements.css(f,new B(e.h,1,1,1).toCss()),t._hueSlider.value(e.h),t._opacitySlider&&t._opacitySlider.value(100*e.a))},_selectOnHide:function(){return this.options.buttons?null:this._getHSV()},_template:u.template('# if (preview) { ## } ## if (opacity) { ## } ## if (buttons) { #
# } #')}),H=d.extend({toHSV:function(){return this},toRGB:function(){return this},toHex:function(){return this.toBytes().toHex()},toBytes:function(){return this},toCss:function(){return"#"+this.toHex()},toCssRgba:function(){var e=this.toBytes();return"rgba("+e.r+", "+e.g+", "+e.b+", "+a(this.a)+")"},toDisplay:function(){return w?this.toCss():this.toCssRgba()},equals:function(e){return e===this||null!==e&&this.toCssRgba()==o(e).toCssRgba()},diff:function(e){if(null==e)return 0/0;var t=this.toBytes();return e=e.toBytes(),Math.sqrt(Math.pow(.3*(t.r-e.r),2)+Math.pow(.59*(t.g-e.g),2)+Math.pow(.11*(t.b-e.b),2))},clone:function(){var e=this.toBytes();return e===this&&(e=new R(e.r,e.g,e.b,e.a)),e}}),E=H.extend({init:function(e,t,n,s){this.r=e,this.g=t,this.b=n,this.a=s},toHSV:function(){var e,t,n=this.r,s=this.g,i=this.b,a=Math.min(n,s,i),o=Math.max(n,s,i),r=o,l=o-a;return 0===l?new B(0,0,r,this.a):(0!==o?(t=l/o,e=n==o?(s-i)/l:s==o?2+(i-n)/l:4+(n-s)/l,e*=60,0>e&&(e+=360)):(t=0,e=-1),new B(e,t,r,this.a))},toBytes:function(){return new R(255*this.r,255*this.g,255*this.b,this.a)}}),R=E.extend({init:function(e,t,n,s){this.r=Math.round(e),this.g=Math.round(t),this.b=Math.round(n),this.a=s},toRGB:function(){return new E(this.r/255,this.g/255,this.b/255,this.a)},toHSV:function(){return this.toRGB().toHSV()},toHex:function(){return i(this.r,2)+i(this.g,2)+i(this.b,2)},toBytes:function(){return this}}),B=H.extend({init:function(e,t,n,s){this.h=e,this.s=t,this.v=n,this.a=s},toRGB:function(){var e,t,n,s,i,a,o,r,l=this.h,c=this.s,u=this.v;if(0===c)t=n=s=u;else switch(l/=60,e=Math.floor(l),i=l-e,a=u*(1-c),o=u*(1-c*i),r=u*(1-c*(1-i)),e){case 0:t=u,n=r,s=a;break;case 1:t=o,n=u,s=a;break;case 2:t=a,n=u,s=r;break;case 3:t=a,n=o,s=u;break;case 4:t=r,n=a,s=u;break;default:t=u,n=a,s=o}return new E(t,n,s,this.a)},toBytes:function(){return this.toRGB().toBytes()}}),T=C.extend({init:function(t,n){var s,i,a,r=this;C.fn.init.call(r,t,n),n=r.options,t=r.element,s=t.val()?o(t.val(),!0):o(n.value,!0),r._value=n.value=s,i=r.wrapper=e(r._template(n)),t.hide().after(i),t.is("input")&&t.appendTo(i),r.enable(!t.attr("disabled")),a=t.attr("accesskey"),a&&(t.attr("accesskey",null),i.attr("accesskey",a)),r.bind("activate",function(e){e.isDefaultPrevented()||r.toggle()}),r._updateUI(s)},destroy:function(){this.wrapper.add("*").off(k),this._popup&&(this._selector.destroy(),this._popup.destroy()),this._selector=this._popup=this.wrapper=null,C.fn.destroy.call(this)},enable:function(e){var t=this,n=t.wrapper,s=n.children(".k-picker-wrap"),i=s.find(".k-select");0===arguments.length&&(e=!0),t.element.attr("disabled",!e),n.attr("disabled",!e),i.off(k).on("mousedown"+k,l),e?n.removeClass("k-state-disabled").attr("tabIndex",0).on("mouseenter"+k,function(){s.addClass("k-state-hover")}).on("mouseleave"+k,function(){s.removeClass("k-state-hover")}).on("focus"+k,function(){s.addClass("k-state-focused")}).on("blur"+k,function(){s.removeClass("k-state-focused")}).on(y,c(t._keydown,t)).on(b,".k-icon",c(t.toggle,t)).on(b,t.options.toolIcon?".k-tool-icon":".k-selected-color",function(){t.trigger("activate")}):n.addClass("k-state-disabled").removeAttr("tabIndex").add("*",n).off(k)},_template:u.template(''),options:{name:"ColorPicker",palette:null,columns:10,toolIcon:null,value:null,messages:_,opacity:!1,buttons:!0,preview:!0},events:["activate","change","select","open","close"],open:function(){this._getPopup().open()},close:function(){this._getPopup().close()},toggle:function(){this._getPopup().toggle()},color:S.fn.color,value:S.fn.value,_select:S.fn._select,_triggerSelect:S.fn._triggerSelect,_isInputTypeColor:function(){var e=this.element[0];return/^input$/i.test(e.tagName)&&/^color$/i.test(e.type)},_updateUI:function(e){e&&(this._isInputTypeColor()||1==e.a?this.element.val(e.toCss()):this.element.val(e.toCssRgba())),this._triggerSelect(e),this.wrapper.find(".k-selected-color").css(f,e?e.toDisplay():"transparent")},_keydown:function(e){var t=e.keyCode;this._getPopup().visible()?(t==h.ESC?this._selector._cancel():this._selector._keydown(e),l(e)):(t==h.ENTER||t==h.DOWN)&&(this.open(),l(e))},_getPopup:function(){var t,s,i,a=this,r=a._popup;return r||(t=this.options,s=t.palette?I:x,t._standalone=!1,delete t.select,delete t.change,delete t.cancel,i=this._selector=new s(e("").appendTo(document.body),t),a._popup=r=i.wrapper.kendoPopup({anchor:a.wrapper}).data("kendoPopup"),i.bind({select:function(e){a._updateUI(o(e.value))},change:function(){a._select(i.color()),a.close()},cancel:function(){a.close()}}),r.bind({close:function(e){if(a.trigger("close"))return e.preventDefault(),n;a.wrapper.children(".k-picker-wrap").removeClass("k-state-focused");var t=i._selectOnHide();t?a._select(t):(a.wrapper.focus(),a._updateUI(a.color()))},open:function(e){a.trigger("open")?e.preventDefault():a.wrapper.children(".k-picker-wrap").addClass("k-state-focused")},activate:function(){i._select(a.color(),!0),i.focus(),a.wrapper.children(".k-picker-wrap").addClass("k-state-focused")}})),r}});p.plugin(I),p.plugin(x),p.plugin(T),u.parseColor=o,u.Color={fromBytes:function(e,t,n,s){return new R(e,t,n,null!=s?s:1)},fromRGB:function(e,t,n,s){return new E(e,t,n,null!=s?s:1)},fromHSV:function(e,t,n,s){return new B(e,t,n,null!=s?s:1)}}}(jQuery,parseInt)});