demo20230512/Scripts/kendo/2014.2.716/kendo.colorpicker.min.js
2023-05-12 10:20:28 +08:00

16 lines
18 KiB
JavaScript

/**
* Copyright 2014 Telerik AD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
!function(e,define){define(["./kendo.core.min","./kendo.popup.min","./kendo.slider.min","./kendo.userevents.min"],e)}(function(){return function(e,t,n){function i(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 r(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,i){if(null==e||"transparent"==e)return null;if(e instanceof D)return e;var r=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(r)return new M(t(r[1],16),t(r[2],16),t(r[3],16),1);if(r=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(e))return new M(t(r[1]+r[1],16),t(r[2]+r[2],16),t(r[3]+r[3],16),1);if(r=/^rgb\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/.exec(e))return new M(t(r[1],10),t(r[2],10),t(r[3],10),1);if(r=/^rgba\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9.]+)\s*\)/.exec(e))return new M(t(r[1],10),t(r[2],10),t(r[3],10),parseFloat(r[4]));if(r=/^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(r[1])/100,parseFloat(r[2])/100,parseFloat(r[3])/100,1);if(r=/^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(r[1])/100,parseFloat(r[2])/100,parseFloat(r[3])/100,parseFloat(r[4]));if(!i)throw Error("Cannot parse color: "+e);return n}function s(e,t,n){var i,r;return e=Array.prototype.slice.call(e),i=e.length,r=e.indexOf(t),0>r?0>n?e[i-1]:e[0]:(r+=n,0>r?r+=i:r%=i,e[r])}function l(e){e.preventDefault()}function u(e,t){return function(){return e.apply(t,arguments)}}var c=window.kendo,d=c.Class,f=c.ui,p=f.Widget,h=c.keys,g="background-color",m="k-state-selected",v="000000,7f7f7f,880015,ed1c24,ff7f27,fff200,22b14c,00a2e8,3f48cc,a349a4,ffffff,c3c3c3,b97a57,ffaec9,ffc90e,efe4b0,b5e61d,99d9ea,7092be,c8bfe7",_="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",y={apply:"Apply",cancel:"Cancel"},b=".kendoColorTools",w="click"+b,k="keydown"+b,x=c.support.browser,C=x.msie&&9>x.version,F=p.extend({init:function(e,t){var n,i=this;p.fn.init.call(i,e,t),e=i.element,t=i.options,i._value=t.value=o(t.value),i._tabIndex=e.attr("tabIndex")||0,n=i._ariaId=t.ariaId,n&&e.attr("aria-labelledby",n),t._standalone&&(i._triggerSelect=i._triggerChange)},options:{name:"ColorSelector",value:null,_standalone:!0},events:["change","select","cancel"],color:function(e){return e!==n&&(this._value=o(e),this._updateUI(this._value)),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),e(".k-disabled-overlay",this.wrapper).remove(),t||this.wrapper.append("<div class='k-disabled-overlay'></div>"),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()}),this.element.trigger("change"))},_triggerSelect:function(e){i(this,"select",e)},_triggerChange:function(e){i(this,"change",e)},destroy:function(){this.element&&this.element.off(b),this.wrapper&&this.wrapper.off(b).find("*").off(b),this.wrapper=null,p.fn.destroy.call(this)},_updateUI:e.noop,_selectOnHide:function(){return null},_cancel:function(){this.trigger("cancel")}}),S=F.extend({init:function(t,n){var i,r,a,s,l=this;if(F.fn.init.call(l,t,n),t=l.wrapper=l.element,n=l.options,i=n.palette,"websafe"==i?(i=_,n.columns=18):"basic"==i&&(i=v),"string"==typeof i&&(i=i.split(",")),e.isArray(i)&&(i=e.map(i,function(e){return o(e)})),l._selectedID=(n.ariaId||c.guid())+"_selected",t.addClass("k-widget k-colorpalette").attr("role","grid").attr("aria-readonly","true").append(e(l._template({colors:i,columns:n.columns,tileSize:n.tileSize,value:l._value,id:n.ariaId}))).on(w,".k-item",function(t){l._select(e(t.currentTarget).css(g))}).attr("tabIndex",l._tabIndex).on(k,u(l._keydown,l)),r=n.tileSize){if(/number|string/.test(typeof r))a=s=parseFloat(r);else{if("object"!=typeof r)throw Error("Unsupported value for the 'tileSize' argument");a=parseFloat(r.width),s=parseFloat(r.height)}t.find(".k-item").css({width:a,height:s})}},focus:function(){this.wrapper.focus()},options:{name:"ColorPalette",columns:10,tileSize:null,palette:"basic"},_onEnable:function(e){e?this.wrapper.attr("tabIndex",this._tabIndex):this.wrapper.removeAttr("tabIndex")},_keydown:function(t){var n,i,r=this.wrapper,a=r.find(".k-item"),u=a.filter("."+m).get(0),c=t.keyCode;if(c==h.LEFT?n=s(a,u,-1):c==h.RIGHT?n=s(a,u,1):c==h.DOWN?n=s(a,u,this.options.columns):c==h.UP?n=s(a,u,-this.options.columns):c==h.ENTER?(l(t),u&&this._select(e(u).css(g))):c==h.ESC&&this._cancel(),n){l(t),this._current(n);try{i=o(n.css(g)),this._triggerSelect(i)}catch(d){}}},_current:function(t){this.wrapper.find("."+m).removeClass(m).attr("aria-selected",!1).removeAttr("id"),e(t).addClass(m).attr("aria-selected",!0).attr("id",this._selectedID),this.element.removeAttr("aria-activedescendant").attr("aria-activedescendant",this._selectedID)},_updateUI:function(t){var i=null;this.wrapper.find(".k-item").each(function(){var r=o(e(this).css(g));return r&&r.equals(t)?(i=this,!1):n}),this._current(i)},_template:c.template('<table class="k-palette k-reset" role="presentation"><tr role="row"># for (var i = 0; i < colors.length; ++i) { ## var selected = colors[i].equals(value); ## if (i && i % columns == 0) { # </tr><tr role="row"> # } #<td role="gridcell" unselectable="on" style="background-color:#= colors[i].toCss() #"#= selected ? " aria-selected=true" : "" # #=(id && i === 0) ? "id=\\""+id+"\\" " : "" # class="k-item#= selected ? " '+m+'" : "" #" aria-label="#= colors[i].toCss() #"></td># } #</tr></table>')}),T=F.extend({init:function(t,n){var i=this;F.fn.init.call(i,t,n),n=i.options,t=i.element,i.wrapper=t.addClass("k-widget k-flatcolorpicker").append(i._template(n)),i._hueElements=e(".k-hsv-rectangle, .k-transparency-slider .k-slider-track",t),i._selectedColor=e(".k-selected-color-display",t),i._colorAsText=e("input.k-color-value",t),i._sliders(),i._hsvArea(),i._updateUI(i._value||new E(1,0,0,1)),t.find("input.k-color-value").on(k,function(t){var n,r,a=this;if(t.keyCode==h.ENTER)try{n=o(a.value),r=i.color(),i._select(n,n.equals(r))}catch(s){e(a).addClass("k-state-error")}else i.options.autoupdate&&setTimeout(function(){var e=o(a.value,!0);e&&i._updateUI(e,!0)},10)}).end().on(w,".k-controls button.apply",function(){i._select(i._getHSV())}).on(w,".k-controls button.cancel",function(){i._updateUI(i.color()),i._cancel()}),C&&i._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,F.fn.destroy.call(this)},options:{name:"FlatColorPicker",opacity:!1,buttons:!1,input:!0,preview:!0,autoupdate:!0,messages:y},_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,i=n.element;n._hueSlider=i.find(".k-hue-slider").kendoSlider({min:0,max:359,tickPlacement:"none",showButtons:!1,slide:e,change:e}).data("kendoSlider"),n._opacitySlider=i.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 i=this.offset,r=e-i.left,a=n-i.top,o=this.width,s=this.height;r=0>r?0:r>o?o:r,a=0>a?0:a>s?s:a,t._svChange(r/o,1-a/s)}var t=this,n=t.element,i=n.find(".k-hsv-rectangle"),r=i.find(".k-draghandle").attr("tabIndex",0).on(k,u(t._keydown,t));t._hsvEvents=new c.UserEvents(i,{global:!0,press:function(t){this.offset=c.getOffset(i),this.width=i.width(),this.height=i.height(),r.focus(),e.call(this,t.x.location,t.y.location)},start:function(){i.addClass("k-dragging"),r.focus()},move:function(t){t.preventDefault(),e.call(this,t.x.location,t.y.location)},end:function(){i.removeClass("k-dragging")}}),t._hsvRect=i,t._hsvHandle=r},_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",this._tabIndex):t.removeAttr("tabIndex")},_keydown:function(e){function t(t,n){var r=i._getHSV();r[t]+=n*(e.shiftKey?.01:.05),0>r[t]&&(r[t]=0),r[t]>1&&(r[t]=1),i._updateUI(r),l(e)}function n(t){var n=i._getHSV();n.h+=t*(e.shiftKey?1:5),0>n.h&&(n.h=0),n.h>359&&(n.h=359),i._updateUI(n),l(e)}var i=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&&i._opacitySlider?"a":"v",1);break;case h.DOWN:t(e.ctrlKey&&i._opacitySlider?"a":"v",-1);break;case h.ENTER:i._select(i._getHSV());break;case h.F2:i.wrapper.find("input.k-color-value").focus().select();break;case h.ESC:i._cancel()}},focus:function(){this._hsvHandle.focus()},_getHSV:function(e,t,n,i){var r=this._hsvRect,a=r.width(),o=r.height(),s=this._hsvHandle.position();return null==e&&(e=this._hueSlider.value()),null==t&&(t=s.left/a),null==n&&(n=1-s.top/o),null==i&&(i=this._opacitySlider?this._opacitySlider.value()/100:1),new I(e,t,n,i)},_svChange:function(e,t){var n=this._getHSV(null,e,t,null);this._updateUI(n)},_updateUI:function(e,t){var n=this,i=n._hsvRect;e&&(this._colorAsText.removeClass("k-state-error"),n._selectedColor.css(g,e.toDisplay()),t||n._colorAsText.val(n._opacitySlider?e.toCssRgba():e.toCss()),n._triggerSelect(e),e=e.toHSV(),n._hsvHandle.css({left:e.s*i.width()+"px",top:(1-e.v)*i.height()+"px"}),n._hueElements.css(g,new I(e.h,1,1,1).toCss()),n._hueSlider.value(e.h),n._opacitySlider&&n._opacitySlider.value(100*e.a))},_selectOnHide:function(){return this.options.buttons?null:this._getHSV()},_template:c.template('# if (preview) { #<div class="k-selected-color"><div class="k-selected-color-display"><input class="k-color-value" #= !data.input ? \'style="visibility: hidden;"\' : "" #></div></div># } #<div class="k-hsv-rectangle"><div class="k-hsv-gradient"></div><div class="k-draghandle"></div></div><input class="k-hue-slider" /># if (opacity) { #<input class="k-transparency-slider" /># } ## if (buttons) { #<div unselectable="on" class="k-controls"><button class="k-button k-primary apply">#: messages.apply #</button> <button class="k-button cancel">#: messages.cancel #</button></div># } #')}),D=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 C?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 M(e.r,e.g,e.b,e.a)),e}}),E=D.extend({init:function(e,t,n,i){this.r=e,this.g=t,this.b=n,this.a=i},toHSV:function(){var e,t,n=this.r,i=this.g,r=this.b,a=Math.min(n,i,r),o=Math.max(n,i,r),s=o,l=o-a;return 0===l?new I(0,0,s,this.a):(0!==o?(t=l/o,e=n==o?(i-r)/l:i==o?2+(r-n)/l:4+(n-i)/l,e*=60,0>e&&(e+=360)):(t=0,e=-1),new I(e,t,s,this.a))},toBytes:function(){return new M(255*this.r,255*this.g,255*this.b,this.a)}}),M=E.extend({init:function(e,t,n,i){this.r=Math.round(e),this.g=Math.round(t),this.b=Math.round(n),this.a=i},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 r(this.r,2)+r(this.g,2)+r(this.b,2)},toBytes:function(){return this}}),I=D.extend({init:function(e,t,n,i){this.h=e,this.s=t,this.v=n,this.a=i},toRGB:function(){var e,t,n,i,r,a,o,s,l=this.h,u=this.s,c=this.v;if(0===u)t=n=i=c;else switch(l/=60,e=Math.floor(l),r=l-e,a=c*(1-u),o=c*(1-u*r),s=c*(1-u*(1-r)),e){case 0:t=c,n=s,i=a;break;case 1:t=o,n=c,i=a;break;case 2:t=a,n=c,i=s;break;case 3:t=a,n=o,i=c;break;case 4:t=s,n=a,i=c;break;default:t=c,n=a,i=o}return new E(t,n,i,this.a)},toBytes:function(){return this.toRGB().toBytes()}}),A=p.extend({init:function(t,n){var i,r,a,s=this;p.fn.init.call(s,t,n),n=s.options,t=s.element,i=t.attr("value")||t.val(),i=i?o(i,!0):o(n.value,!0),s._value=n.value=i,r=s.wrapper=e(s._template(n)),t.hide().after(r),t.is("input")&&t.appendTo(r),s._tabIndex=t.attr("tabIndex")||0,s.enable(!t.attr("disabled")),a=t.attr("accesskey"),a&&(t.attr("accesskey",null),r.attr("accesskey",a)),s.bind("activate",function(e){e.isDefaultPrevented()||s.toggle()}),s._updateUI(i)},destroy:function(){this.wrapper.off(b).find("*").off(b),this._popup&&(this._selector.destroy(),this._popup.destroy()),this._selector=this._popup=this.wrapper=null,p.fn.destroy.call(this)},enable:function(e){var t=this,n=t.wrapper,i=n.children(".k-picker-wrap"),r=i.find(".k-select");0===arguments.length&&(e=!0),t.element.attr("disabled",!e),n.attr("aria-disabled",!e),r.off(b).on("mousedown"+b,l),n.addClass("k-state-disabled").removeAttr("tabIndex").add("*",n).off(b),e&&n.removeClass("k-state-disabled").attr("tabIndex",t._tabIndex).on("mouseenter"+b,function(){i.addClass("k-state-hover")}).on("mouseleave"+b,function(){i.removeClass("k-state-hover")}).on("focus"+b,function(){i.addClass("k-state-focused")}).on("blur"+b,function(){i.removeClass("k-state-focused")}).on(k,u(t._keydown,t)).on(w,".k-icon",u(t.toggle,t)).on(w,t.options.toolIcon?".k-tool-icon":".k-selected-color",function(){t.trigger("activate")})},_template:c.template('<span role="textbox" aria-haspopup="true" class="k-widget k-colorpicker k-header"><span class="k-picker-wrap k-state-default"># if (toolIcon) { #<span class="k-tool-icon #= toolIcon #"><span class="k-selected-color"></span></span># } else { #<span class="k-selected-color"></span># } #<span class="k-select" unselectable="on"><span class="k-icon k-i-arrow-s" unselectable="on"></span></span></span></span>'),options:{name:"ColorPicker",palette:null,columns:10,toolIcon:null,value:null,messages:y,opacity:!1,buttons:!0,preview:!0,ARIATemplate:'Current selected color is #=data || ""#'},events:["activate","change","select","open","close"],open:function(){this._getPopup().open()},close:function(){this._getPopup().close()},toggle:function(){this._getPopup().toggle()},color:F.fn.color,value:F.fn.value,_select:F.fn._select,_triggerSelect:F.fn._triggerSelect,_isInputTypeColor:function(){var e=this.element[0];return/^input$/i.test(e.tagName)&&/^color$/i.test(e.type)},_updateUI:function(e){var t="";e&&(t=this._isInputTypeColor()||1==e.a?e.toCss():e.toCssRgba(),this.element.val(t)),this._ariaTemplate||(this._ariaTemplate=c.template(this.options.ARIATemplate)),this.wrapper.attr("aria-label",this._ariaTemplate(t)),this._triggerSelect(e),this.wrapper.find(".k-selected-color").css(g,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,i,r,a,s=this,l=s._popup;return l||(t=s.options,i=t.palette?S:T,t._standalone=!1,delete t.select,delete t.change,delete t.cancel,r=c.guid(),a=s._selector=new i(e('<div id="'+r+'"/>').appendTo(document.body),t),s.wrapper.attr("aria-owns",r),s._popup=l=a.wrapper.kendoPopup({anchor:s.wrapper}).data("kendoPopup"),a.bind({select:function(e){s._updateUI(o(e.value))},change:function(){s._select(a.color()),s.close()},cancel:function(){s.close()}}),l.bind({close:function(e){if(s.trigger("close"))return e.preventDefault(),n;s.wrapper.children(".k-picker-wrap").removeClass("k-state-focused");var t=a._selectOnHide();t?s._select(t):(s.wrapper.focus(),s._updateUI(s.color()))},open:function(e){s.trigger("open")?e.preventDefault():s.wrapper.children(".k-picker-wrap").addClass("k-state-focused")},activate:function(){a._select(s.color(),!0),a.focus(),s.wrapper.children(".k-picker-wrap").addClass("k-state-focused")}})),l}});f.plugin(S),f.plugin(T),f.plugin(A),c.parseColor=o,c.Color={fromBytes:function(e,t,n,i){return new M(e,t,n,null!=i?i:1)},fromRGB:function(e,t,n,i){return new E(e,t,n,null!=i?i:1)},fromHSV:function(e,t,n,i){return new I(e,t,n,null!=i?i:1)}}}(jQuery,parseInt),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});