WordPress/wp-admin/js/iris.min.js
2012-11-05 23:00:15 +00:00

4 lines
21 KiB
JavaScript

/*! Iris - v0.9.8 - 2012-10-04
* https://github.com/Automattic/Iris
* Copyright (c) 2012 Matt Wiebe; Licensed GPL */
(function(a,b){function h(){if(d)e="filter";else{var b=a('<div id="iris-gradtest" />'),c="linear-gradient(top,#fff,#000)";a.each(f,function(a,d){b.css("backgroundImage",d+c);if(b.css("backgroundImage").match("gradient"))return e=a,!1}),a.browser.webkit&&e===!1&&(b.css("background","-webkit-gradient(linear,0% 0%,0% 100%,from(#fff),to(#000))"),b.css("backgroundImage").match("gradient")&&(e="webkit")),b.remove()}}function i(b,c){return b=b==="top"?"top":"left",c=a.isArray(c)?c:Array.prototype.slice.call(arguments,1),e==="webkit"?k(b,c):f[e]+"linear-gradient("+b+", "+c.join(", ")+")"}function j(b,c){b=b==="top"?"top":"left",c=a.isArray(c)?c:Array.prototype.slice.call(arguments,1);var d=b==="top"?0:1,e=a(this),f=c.length-1,g=parseInt(a.browser.version,10)>=8?"-ms-filter":"filter";g="filter";var h=d===1?"left":"top",i=d===1?"right":"bottom",j=d===1?"height":"width",k='<div class="iris-ie-gradient-shim" style="position:absolute;'+j+":100%;"+h+":%start%;"+i+":%end%;"+g+':%filter%;" data-color:"%color%"></div>',m="";e.css("position")==="static"&&e.css({position:"relative"}),c=l(c),a.each(c,function(a,b){if(a===f)return!1;var e=c[a+1];if(b.stop===e.stop)return;var g=100-parseFloat(e.stop)+"%";b.octoHex=(new Color(b.color)).toIEOctoHex(),e.octoHex=(new Color(e.color)).toIEOctoHex();var h="progid:DXImageTransform.Microsoft.Gradient(GradientType="+d+", StartColorStr='"+b.octoHex+"', EndColorStr='"+e.octoHex+"')";m+=k.replace("%start%",b.stop).replace("%end%",g).replace("%filter%",h)}),e.find(".iris-ie-gradient-shim").remove(),a(m).prependTo(e)}function k(b,c){var d=[];return b=b==="top"?"0% 0%,0% 100%,":"0% 100%,100% 100%,",c=l(c),a.each(c,function(a,b){d.push("color-stop("+parseFloat(b.stop)/100+", "+b.color+")")}),"-webkit-gradient(linear,"+b+d.join(",")+")"}function l(b){var c=[],d=[],e=[],f=b.length-1;return a.each(b,function(a,b){var e=b,f=!1,g=b.match(/1?[0-9]{1,2}%$/);g&&(e=b.replace(/\s?1?[0-9]{1,2}%$/,""),f=g.shift()),c.push(e),d.push(f)}),d[0]===!1&&(d[0]="0%"),d[f]===!1&&(d[f]="100%"),d=m(d),a.each(d,function(a){e[a]={color:c[a],stop:d[a]}}),e}function m(b){var c=0,d=b.length-1,e=0,f=!1,g,h,i,j;if(b.length<=2||a.inArray(!1,b)<0)return b;while(e<b.length-1)!f&&b[e]===!1?(c=e-1,f=!0):f&&b[e]!==!1&&(d=e,e=b.length),e++;h=d-c,j=parseInt(b[c].replace("%"),10),g=(parseFloat(b[d].replace("%"))-j)/h,e=c+1,i=1;while(e<d)b[e]=j+i*g+"%",i++,e++;return m(b)}var c='<div class="iris-picker"><div class="iris-picker-inner"><div class="iris-square"><a class="iris-square-value" href="#"><span class="iris-square-handle ui-slider-handle"></span></a><div class="iris-square-slider iris-horiz-slider"></div><div class="iris-square-slider iris-vert-slider"></div><div class="iris-square-inner iris-square-horiz"></div><div class="iris-square-inner iris-square-vert"></div></div><div class="iris-slider iris-strip"><div class="iris-slider-offset"></div></div></div></div>',d=!!(a.browser.msie&&parseInt(a.browser.version,10)<10),e=!1,f=["-moz-","-webkit-","-o-","-ms-"],g='.iris-picker{display:block;position:relative}.iris-error{background-color:#ffafaf}.iris-border{border-radius:3px;border:1px solid #aaa;width:200px;background-color:#fff}.iris-picker-inner{position:absolute;top:0;right:0;left:0;bottom:0}.iris-border .iris-picker-inner{top:10px;right:10px;left:10px;bottom:10px}.iris-picker .iris-square-inner{position:absolute;left:0;right:0;top:0;bottom:0}.iris-picker .iris-square,.iris-picker .iris-slider,.iris-picker .iris-square-inner{border-radius:3px;-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,0.4);-moz-box-shadow:inset 0 0 5px rgba(0,0,0,0.4);box-shadow:inset 0 0 5px rgba(0,0,0,0.4);height:100%;width:12.5%;float:left;margin-right:5%}.iris-picker .iris-square{width:76%;margin-right:10%;position:relative}.iris-picker .iris-square-inner{width:auto;margin:0}.iris-picker .iris-square .sat,.iris-ie-9 .iris-square,.iris-ie-9 .iris-slider,.iris-ie-9 .iris-square-inner{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;border-radius:0}.iris-picker .iris-square .sat{-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.iris-ie-lt9 .iris-square,.iris-ie-lt9 .iris-slider,.iris-ie-lt9 .iris-square-inner{outline:1px solid #aaa}.iris-ie-lt9 .iris-square .ui-slider-handle{outline:1px solid #aaa;background-color:#fff;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"}.iris-ie-lt9 .iris-square .iris-square-handle{background:none;border:3px solid #fff;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"}.iris-picker .iris-strip{margin-right:0;position:relative}.iris-picker .iris-strip .ui-slider-handle{position:absolute;background:none;right:-3px;left:-3px;border:4px solid #aaa;border-width:4px 3px;width:auto;height:6px;border-radius:4px;box-shadow:0 1px 2px rgba(0,0,0,.2);opacity:.9;z-index:5}.iris-strip .ui-slider-handle:before{content:" ";position:absolute;left:-2px;right:-2px;top:-3px;bottom:-3px;border:2px solid #fff;-webkit-border-radius:3px;border-radius:3px}.iris-picker .iris-slider-offset{position:absolute;top:11px;left:0;right:0;bottom:-3px}.iris-square .iris-horiz-slider{position:absolute;top:-7px;left:-7px;height:1px;width:100%}.iris-square .iris-vert-slider{position:absolute;right:6px;top:7px;width:1px;height:100%}.iris-square .iris-square-slider a{opacity:.3;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";-moz-transition:opacity 300ms;-webkit-transition:opacity 300ms;transition:opacity 300ms}.iris-square .iris-square-slider .ui-slider-handle.active{opacity:1;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"}.iris-dragging .iris-square-slider .ui-slider-handle.active{opacity:0;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"}.iris-picker .ui-slider-handle{background:#f5f5f5;-webkit-border-radius:10px;-moz-border-radius:50%;border-radius:50%;box-shadow:inset #fff 0 1px 1px,inset 0 -1px 1px rgba( 0,0,0,0.4 ),0px 1px 4px 0 rgba( 0,0,0,0.2 ),0 0 2px rgba( 0,0,0,0.3 );display:block;opacity:0.7;position:absolute;z-index:5;height:20px;width:20px;cursor:default;cursor:ns-resize;z-index:5}.iris-horiz-slider .ui-slider-handle{cursor:ew-resize}.iris-square-slider .ui-slider-handle{width:14px;height:14px;opacity:1;background-color:#eee}.iris-picker .iris-square-handle{background:transparent;border:5px solid #aaa;border-color:rgba(128,128,128,.5);box-shadow:none;width:12px;height:12px;position:absolute;left:-10px;top:-10px;cursor:move;opacity:1;z-index:10}.iris-picker .ui-state-focus .iris-square-handle{opacity:.8}.iris-picker .iris-square-handle:hover{border-color:#999}.iris-picker .iris-square-handle:hover::after{border-color:#fff}.iris-picker .iris-square-handle::after{position:absolute;bottom:-4px;right:-4px;left:-4px;top:-4px;border:3px solid #f9f9f9;border-color:rgba(255,255,255,.8);border-radius:50%;content:" "}.iris-picker .iris-square-value{width:8px;height:8px;position:absolute}.iris-ie-lt9 .iris-square-value,.iris-mozilla .iris-square-value{width:1px;height:1px}';if(d&&parseInt(a.browser.version,10)<=7)return a.fn.iris=a.noop;a.fn.gradient=function(b){var c=arguments;return this.each(function(){d?j.apply(this,c):a(this).css("backgroundImage",i.apply(this,c))})},a.fn.raninbowGradient=function(b,c){b=b||"top";var d=a.extend({},{s:100,l:50},c),e="hsl(%h%,"+d.s+"%,"+d.l+"%)",f=0,g=[];while(f<=360)g.push(e.replace("%h%",f)),f+=30;return this.each(function(){a(this).gradient(b,g)})};var n={options:{color:!1,mode:"hsl",controls:{horiz:"s",vert:"l",strip:"h"},hide:!0,border:!0,target:!1,width:200},_inited:!1,_scale:{h:359,s:100,l:100,v:100},_create:function(){var b=this,d=b.element,f=b.options.color||d.val(),g;e===!1&&h(),d.is("input")?(b.options.target?b.picker=a(c).appendTo(b.options.target):b.picker=a(c).insertAfter(d),b._addInputListeners(d)):(d.append(c),b.picker=d.find(".iris-picker"));if(a.browser.mozilla)b.picker.addClass("iris-mozilla");else if(a.browser.msie){var i=parseInt(a.browser.version,10);i===9?b.picker.addClass("iris-ie-9"):i<=8&&b.picker.addClass("iris-ie-lt9")}b.color=(new Color(f)).setHSpace(b.options.mode),b.options.color=b.color.toString(),b.controls={square:b.picker.find(".iris-square"),squareDrag:b.picker.find(".iris-square-value"),horiz:b.picker.find(".iris-square-horiz"),horizSlider:b.picker.find(".iris-horiz-slider"),vert:b.picker.find(".iris-square-vert"),vertSlider:b.picker.find(".iris-vert-slider"),strip:b.picker.find(".iris-strip"),stripSlider:b.picker.find(".iris-strip .iris-slider-offset")},b.options.mode==="hsv"&&b.options.controls.vert==="l"&&(b.options.controls={horiz:"h",vert:"v",strip:"s"}),b.hue=b.color.h(),b.options.hide&&b.picker.hide(),b.options.border&&b.picker.addClass("iris-border"),b._initControls(),b.active="external",b._dimensions(),b._change()},_paint:function(){var a=this;a._paintDimension("top","strip"),a._paintDimension("top","vert"),a._paintDimension("left","horiz")},_paintDimension:function(a,b){var c=this,d=c.color,e=c.options.mode,f=c._getHSpaceColor(),g=c.controls[b],h=c.options.controls,i,j;if(b===c.active||c.active==="square"&&b!=="strip")return;switch(h[b]){case"h":if(e==="hsv"){f=d.clone();switch(b){case"horiz":f[h.vert](100);break;case"vert":f[h.horiz](100);break;case"strip":f.setHSpace("hsl").s(100).l(100)}i=f.toHsl()}else b==="strip"?i={s:f.s,l:f.l}:i={s:100,l:f.l};g.raninbowGradient(a,i);break;case"s":b==="vert"&&c.options.controls.horiz==="h"&&c.options.mode==="hsl"?i=["hsla(0, 0%, "+f.l+"%, 0)","hsla(0, 0%, "+f.l+"%, 1)"]:b==="vert"&&c.options.mode==="hsv"?i=[d.clone().a(0).s(0).toCSS("rgba"),d.clone().a(1).s(0).toCSS("rgba")]:b==="strip"&&c.options.mode==="hsv"?i=[d.clone().s(100).toCSS("hsl"),d.clone().s(0).toCSS("hsl")]:i=["hsl("+f.h+",0%,50%)","hsl("+f.h+",100%,50%)"],g.gradient(a,i);break;case"l":b==="strip"?i=["hsl("+f.h+",100%,100%)","hsl("+f.h+", "+f.s+"%,50%)","hsl("+f.h+",100%,0%)"]:i=["#fff","rgba(255,255,255,0) 50%","rgba(0,0,0,0) 50%","rgba(0,0,0,1)"],g.gradient(a,i);break;case"v":b==="strip"?i=[d.clone().v(100).toCSS(),d.clone().v(0).toCSS()]:i=["rgba(0,0,0,0)","#000"],g.gradient(a,i);break;default:}},_getHSpaceColor:function(){return this.options.mode==="hsv"?this.color.toHsv():this.color.toHsl()},_dimensions:function(a){var b=this.picker.find(".iris-picker-inner"),c=this.controls,d=c.square,e=this.picker.find(".iris-strip"),f="77.5%",g="12%",h=20,i=this.options.border?this.options.width-h:this.options.width,j;a&&(d.css("width",""),e.css("width",""),this.picker.removeAttr("style")),f=i*(parseFloat(f)/100),g=i*(parseFloat(g)/100),j=this.options.border?f+h:f,d.width(f).height(f),e.height(f).width(g),this.picker.css({width:this.options.width,height:j})},_addInputListeners:function(a){var b=this;a.on("change",function(c){var d=new Color(a.val()),e=a.val().replace(/^#/,"");a.removeClass("iris-error"),d.error?e!==""&&a.addClass("iris-error"):b._setOption("color",d.toString())})},_initControls:function(){var b=this,c=b.controls,d=c.square,e=b.options.controls,f=b._scale[e.strip];c.stripSlider.slider({orientation:"vertical",max:f,slide:function(a,c){b.active="strip",e.strip==="h"&&(c.value=f-c.value),b.color[e.strip](c.value),b._change.apply(b,arguments)}}),c.horizSlider.slider({max:b._scale[e.horiz],slide:function(a,c){b.color[e.horiz](c.value),b.active="horiz",b._change.apply(b,arguments)}}),c.vertSlider.slider({max:b._scale[e.vert],orientation:"vertical",slide:function(a,c){b.color[e.vert](c.value),b.active="vert",b._change.apply(b,arguments)}}),c.squareDrag.draggable({containment:"parent",zIndex:1e3,cursor:"move",drag:function(a,c){b._squareDrag(a,c)},start:function(){d.addClass("iris-dragging"),a(this).addClass("ui-state-focus")},stop:function(){d.removeClass("iris-dragging"),a(this).removeClass("ui-state-focus")}}).on("mousedown mouseup",function(c){c.preventDefault();var d="ui-state-focus";c.type==="mousedown"?(b.picker.find("."+d).removeClass(d).blur(),a(this).addClass(d)):a(this).removeClass("ui-state-focus")}),d.mousedown(function(c){if(c.which!==1)return;if(!a(c.target).is("div"))return;var d=b.controls.square.offset(),e={top:c.pageY-d.top,left:c.pageX-d.left};c.preventDefault(),b._squareDrag(c,{position:e}),c.target=b.controls.squareDrag.get(0),b.controls.squareDrag.css(e).trigger(c)}),c.square.mousemove(function(b){var d=a(this),e=d.offset(),f=b.pageX-e.left,g=b.pageY-e.top,h=d.find(".iris-horiz-slider .ui-slider-handle"),i=d.find(".iris-vert-slider .ui-slider-handle");f>c.square.width()-20?i.addClass("active"):i.removeClass("active"),g<20?h.addClass("active"):h.removeClass("active")}),c.square.mouseleave(function(){a(this).find(".iris-square-slider .ui-slider-handle").removeClass("active")})},_squareDrag:function(a,b){var c=this,d=c.options.controls,e=c._squareDimensions(),f=Math.round((e.h-b.position.top)/e.h*c._scale[d.vert]),g=c._scale[d.horiz]-Math.round((e.w-b.position.left)/e.w*c._scale[d.horiz]);c.color[d.horiz](g)[d.vert](f),c.active="square",c._change.apply(c,arguments)},_setOption:function(a,b){var c=this.options[a];if(a==="color"){b=""+b;var d=b.replace(/^#/,""),e=(new Color(b)).setHSpace(this.options.mode);e.error||(this.color=e,this.options.color=this.options[a]=this.color.toString(),this.active="external",this._change())}},_squareDimensions:function(a){var c=this.controls.square,d,e;return a!==b&&c.data("dimensions")?c.data("dimensions"):(e=this.controls.squareDrag,d={w:c.width(),h:c.height()},c.data("dimensions",d),d)},_change:function(b,c){var d=this,e=d.controls,f=d._getHSpaceColor(),g=d.color.toString(),h=["vert","horiz","square","strip"],i=d.options.controls,j=i[d.active]||"external";d.active==="strip"?h=[]:d.active!=="external"&&h.pop(),j==="external"||j==="h"?d.hue=f.h:f.h!==d.hue&&(f.h=d.hue,d.color.h(d.hue)),a.each(h,function(a,b){var c;if(b!==d.active)switch(b){case"strip":c=i.strip==="h"?d._scale[i.strip]-f[i.strip]:f[i.strip],e.stripSlider.slider("value",c);break;case"vert":d.active!=="horiz"&&e.vertSlider.slider("value",f[i.vert]);break;case"horiz":d.active!=="vert"&&e.horizSlider.slider("value",f[i.horiz]);break;case"square":var g=d._squareDimensions(),h={left:f[i.horiz]/d._scale[i.horiz]*g.w,top:g.h-f[i.vert]/d._scale[i.vert]*g.h};d.active==="horiz"?delete h.top:d.active==="vert"&&delete h.left,d.controls.squareDrag.css(h)}}),d.options.color=d.color.toString(),d._inited&&d._trigger("change",{type:d.active},{color:d.color}),d.element.is(":input")&&!d.color.error&&d.element.val(d.color.toString()).removeClass("iris-error"),d._paint(),d._inited=!0,d.active=!1},show:function(){this.picker.show()},hide:function(){this.picker.hide()},toggle:function(){this.picker.toggle()}};a.widget("a8c.iris",n),a('<style id="iris-css">'+g+"</style>").appendTo("head")})(jQuery),function(a,b){var c=function(a,b){return this instanceof c?this._init(a,b):new c(a,b)};c.fn=c.prototype={_color:0,_alpha:1,error:!1,_hsl:{h:0,s:0,l:0},_hsv:{h:0,s:0,v:0},_hSpace:"hsl",_init:function(a){var c="noop";switch(typeof a){case"object":return a.a!==b&&this.a(a.a),c=a.r!==b?"fromRgb":a.l!==b?"fromHsl":a.v!==b?"fromHsv":c,this[c](a);case"string":return this.fromCSS(a);case"number":return this.fromInt(parseInt(a,10))}return this},clone:function(){var a=new c(this.toInt()),b=["_alpha","_hSpace","_hsl","_hsv","error"];for(var d=b.length-1;d>=0;d--)a[b[d]]=this[b[d]];return a},setHSpace:function(a){return this._hSpace=a==="hsv"?"hsv":"hsl",this},noop:function(){return this},fromCSS:function(a){var b,c;return this.error=!1,a.match(/^(rgb|hsl)a?/)?(c=a.replace(/(\s|%)/g,"").replace(/^(rgb|hsl)a?\(/,"").replace(/\);?$/,"").split(","),c.length===4&&this.a(parseFloat(c.pop())),a.match(/^rgb/)?this.fromRgb({r:parseInt(c[0],10),g:parseInt(c[1],10),b:parseInt(c[2],10)}):this.fromHsl({h:parseInt(c[0],10),s:parseInt(c[1],10),l:parseInt(c[2],10)})):this.fromHex(a)},fromRgb:function(a,c){return typeof a!="object"||a.r===b||a.g===b||a.b===b?(this.error=!0,this):(this.error=!1,this.fromInt(parseInt((a.r<<16)+(a.g<<8)+a.b,10),c))},fromHex:function(a){return a=a.replace(/^#/,"").replace(/^0x/,""),a.length===3&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),this.error=!/^[0-9A-F]{6}$/i.test(a),this.fromInt(parseInt(a,16))},fromHsl:function(a){var c,d,e,f,g,h,i,j;return typeof a!="object"||a.h===b||a.s===b||a.l===b?(this.error=!0,this):(this._hsl=a,this._hSpace="hsl",h=a.h/360,i=a.s/100,j=a.l/100,i===0?c=d=e=j:(f=j<.5?j*(1+i):j+i-j*i,g=2*j-f,c=this.hue2rgb(g,f,h+1/3),d=this.hue2rgb(g,f,h),e=this.hue2rgb(g,f,h-1/3)),this.fromRgb({r:c*255,g:d*255,b:e*255},!0))},fromHsv:function(a){var c,d,e,f,g,h,i,j,k,l,m;if(typeof a!="object"||a.h===b||a.s===b||a.v===b)return this.error=!0,this;this._hsv=a,this._hSpace="hsv",c=a.h/360,d=a.s/100,e=a.v/100,i=Math.floor(c*6),j=c*6-i,k=e*(1-d),l=e*(1-j*d),m=e*(1-(1-j)*d);switch(i%6){case 0:f=e,g=m,h=k;break;case 1:f=l,g=e,h=k;break;case 2:f=k,g=e,h=m;break;case 3:f=k,g=l,h=e;break;case 4:f=m,g=k,h=e;break;case 5:f=e,g=k,h=l}return this.fromRgb({r:f*255,g:g*255,b:h*255},!0)},fromInt:function(a,c){return this._color=parseInt(a,10),isNaN(this._color)&&(this._color=0),this._color>16777215?this._color=16777215:this._color<0&&(this._color=0),c===b&&(this._hsv.h=this._hsv.s=this._hsl.h=this._hsl.s=0),this},hue2rgb:function(a,b,c){return c<0&&(c+=1),c>1&&(c-=1),c<1/6?a+(b-a)*6*c:c<.5?b:c<2/3?a+(b-a)*(2/3-c)*6:a},toString:function(){var a=parseInt(this._color,10).toString(16);if(this.error)return"";if(a.length<6)for(var b=6-a.length-1;b>=0;b--)a="0"+a;return"#"+a},toCSS:function(a,b){a=a||"hex",b=parseFloat(b||this._alpha);switch(a){case"rgb":case"rgba":var c=this.toRgb();return b<1?"rgba( "+c.r+", "+c.g+", "+c.b+", "+b+" )":"rgb( "+c.r+", "+c.g+", "+c.b+" )";case"hsl":case"hsla":var d=this.toHsl();return b<1?"hsla( "+d.h+", "+d.s+"%, "+d.l+"%, "+b+" )":"hsl( "+d.h+", "+d.s+"%, "+d.l+"% )";default:return this.toString()}},toRgb:function(){return{r:255&this._color>>16,g:255&this._color>>8,b:255&this._color}},toHsl:function(){var a=this.toRgb(),b=a.r/255,c=a.g/255,d=a.b/255,e=Math.max(b,c,d),f=Math.min(b,c,d),g,h,i=(e+f)/2;if(e===f)g=h=0;else{var j=e-f;h=i>.5?j/(2-e-f):j/(e+f);switch(e){case b:g=(c-d)/j+(c<d?6:0);break;case c:g=(d-b)/j+2;break;case d:g=(b-c)/j+4}g/=6}return g=Math.round(g*360),g===0&&this._hsl.h!==g&&(g=this._hsl.h),h=Math.round(h*100),h===0&&this._hsl.s&&(h=this._hsl.s),{h:g,s:h,l:Math.round(i*100)}},toHsv:function(){var a=this.toRgb(),b=a.r/255,c=a.g/255,d=a.b/255,e=Math.max(b,c,d),f=Math.min(b,c,d),g,h,i=e,j=e-f;h=e===0?0:j/e;if(e===f)g=h=0;else{switch(e){case b:g=(c-d)/j+(c<d?6:0);break;case c:g=(d-b)/j+2;break;case d:g=(b-c)/j+4}g/=6}return g=Math.round(g*360),g===0&&this._hsv.h!==g&&(g=this._hsv.h),h=Math.round(h*100),h===0&&this._hsv.s&&(h=this._hsv.s),{h:g,s:h,v:Math.round(i*100)}},toInt:function(){return this._color},toIEOctoHex:function(){var a=this.toString(),b=parseInt(255*this._alpha,10).toString(16);return b.length===1&&(b="0"+b),"#"+b+a.replace(/^#/,"")},toLuminosity:function(){var a=this.toRgb();return.2126*Math.pow(a.r/255,2.2)+.7152*Math.pow(a.g/255,2.2)+.0722*Math.pow(a.b/255,2.2)},getDistanceLuminosityFrom:function(a){if(a instanceof c){var b=this.toLuminosity(),d=a.toLuminosity();return b>d?(b+.05)/(d+.05):(d+.05)/(b+.05)}throw"getDistanceLuminosityFrom requires a Color object"},getMaxContrastColor:function(){var a=this.toLuminosity(),b=a>=.5?"000000":"ffffff";return new c(b)},getGrayscaleContrastingColor:function(a){if(!a)return this.getMaxContrastColor();var b=a<5?5:a,c=this.getMaxContrastColor();a=c.getDistanceLuminosityFrom(this);if(a<=b)return c;var d=0===c.toInt()?1:-1;while(a>b)c=c.incrementLightness(d),a=c.getDistanceLuminosityFrom(this);return c},getReadableContrastingColor:function(a,d){if(!a instanceof c)return this;var e=d===b?5:d,f=a.getDistanceLuminosityFrom(this),g=a.getMaxContrastColor(),h=g.getDistanceLuminosityFrom(a);if(h<=e)return g;if(f>=e)return this;var i=0===g.toInt()?-1:1;while(f<e){this.incrementLightness(i),f=this.getDistanceLuminosityFrom(a);if(this._color===0||this._color===16777215)break}return this},a:function(a){return a===b?this._alpha:(this._alpha=parseFloat(a),this)},darken:function(a){return a=a||5,this.l(-a,!0)},lighten:function(a){return a=a||5,this.l(a,!0)},saturate:function(a){return a=a||15,this.s(a,!0)},desaturate:function(a){return a=a||15,this.s(-a,!0)},toGrayscale:function(){return this.setHSpace("hsl").s(0)},getComplement:function(){return this.h(180,!0)},getSplitComplement:function(a){a=a||1;var b=180+a*30;return this.h(b,!0)},getAnalog:function(a){a=a||1;var b=a*30;return this.h(b,!0)},getTetrad:function(a){a=a||1;var b=a*60;return this.h(b,!0)},getTriad:function(a){a=a||1;var b=a*120;return this.h(b,!0)},_partial:function(a){var c=d[a];return function(d,e){var f=this._spaceFunc("to",c.space);return d===b?f[a]:(e===!0&&(d=f[a]+d),c.mod&&(d=d%c.mod),c.range&&(d=d<c.range[0]?c.range[0]:d>c.range[1]?c.range[1]:d),f[a]=d,this._spaceFunc("from",c.space,f))}},_spaceFunc:function(a,b,c){var d=b||this._hSpace,e=a+d.charAt(0).toUpperCase()+d.substr(1);return this[e](c)}};var d={h:{mod:360},s:{range:[0,100]},l:{space:"hsl",range:[0,100]},v:{space:"hsv",range:[0,100]},r:{space:"rgb",range:[0,255]},g:{space:"rgb",range:[0,255]},b:{space:"rgb",range:[0,255]}};for(var e in d)d.hasOwnProperty(e)&&(c.fn[e]=c.fn._partial(e));a.Color=c}(typeof exports=="object"&&exports||this);