Difference between revisions of "Template:Fudan-CHINA/jQueryAnimateColors"

 
Line 1: Line 1:
(function(a,b){function m(a,b,c){var d=h[b.type]||{};return a==null?c||!b.def?null:b.def:(a=d.floor?~~a:parseFloat(a),isNaN(a)?b.def:d.mod?(a+d.mod)%d.mod:0>a?0:d.max<a?d.max:a)}function n(b){var c=f(),d=c._rgba=[];return b=b.toLowerCase(),l(e,function(a,e){var f,h=e.re.exec(b),i=h&&e.parse(h),j=e.space||"rgba";if(i)return f=c[j](i),c[g[j].cache]=f[g[j].cache],d=c._rgba=f._rgba,!1}),d.length?(d.join()==="0,0,0,0"&&a.extend(d,k.transparent),c):k[b]}function o(a,b,c){return c=(c+1)%1,c*6<1?a+(b-a)*c*6:c*2<1?b:c*3<2?a+(b-a)*(2/3-c)*6:a}var c="backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",d=/^([\-+])=\s*(\d+\.?\d*)/,e=[{re:/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(a){return[a[1],a[2],a[3],a[4]]}},{re:/rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(a){return[a[1]*2.55,a[2]*2.55,a[3]*2.55,a[4]]}},{re:/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,parse:function(a){return[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16)]}},{re:/#([a-f0-9])([a-f0-9])([a-f0-9])/,parse:function(a){return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)]}},{re:/hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,space:"hsla",parse:function(a){return[a[1],a[2]/100,a[3]/100,a[4]]}}],f=a.Color=function(b,c,d,e){return new a.Color.fn.parse(b,c,d,e)},g={rgba:{props:{red:{idx:0,type:"byte"},green:{idx:1,type:"byte"},blue:{idx:2,type:"byte"}}},hsla:{props:{hue:{idx:0,type:"degrees"},saturation:{idx:1,type:"percent"},lightness:{idx:2,type:"percent"}}}},h={"byte":{floor:!0,max:255},percent:{max:1},degrees:{mod:360,floor:!0}},i=f.support={},j=a("<p>")[0],k,l=a.each;j.style.cssText="background-color:rgba(1,1,1,.5)",i.rgba=j.style.backgroundColor.indexOf("rgba")>-1,l(g,function(a,b){b.cache="_"+a,b.props.alpha={idx:3,type:"percent",def:1}}),f.fn=a.extend(f.prototype,{parse:function(c,d,e,h){if(c===b)return this._rgba=[null,null,null,null],this;if(c.jquery||c.nodeType)c=a(c).css(d),d=b;var i=this,j=a.type(c),o=this._rgba=[];d!==b&&(c=[c,d,e,h],j="array");if(j==="string")return this.parse(n(c)||k._default);if(j==="array")return l(g.rgba.props,function(a,b){o[b.idx]=m(c[b.idx],b)}),this;if(j==="object")return c instanceof f?l(g,function(a,b){c[b.cache]&&(i[b.cache]=c[b.cache].slice())}):l(g,function(b,d){var e=d.cache;l(d.props,function(a,b){if(!i[e]&&d.to){if(a==="alpha"||c[a]==null)return;i[e]=d.to(i._rgba)}i[e][b.idx]=m(c[a],b,!0)}),i[e]&&a.inArray(null,i[e].slice(0,3))<0&&(i[e][3]=1,d.from&&(i._rgba=d.from(i[e])))}),this},is:function(a){var b=f(a),c=!0,d=this;return l(g,function(a,e){var f,g=b[e.cache];return g&&(f=d[e.cache]||e.to&&e.to(d._rgba)||[],l(e.props,function(a,b){if(g[b.idx]!=null)return c=g[b.idx]===f[b.idx],c})),c}),c},_space:function(){var a=[],b=this;return l(g,function(c,d){b[d.cache]&&a.push(c)}),a.pop()},transition:function(a,b){var c=f(a),d=c._space(),e=g[d],i=this.alpha()===0?f("transparent"):this,j=i[e.cache]||e.to(i._rgba),k=j.slice();return c=c[e.cache],l(e.props,function(a,d){var e=d.idx,f=j[e],g=c[e],i=h[d.type]||{};if(g===null)return;f===null?k[e]=g:(i.mod&&(g-f>i.mod/2?f+=i.mod:f-g>i.mod/2&&(f-=i.mod)),k[e]=m((g-f)*b+f,d))}),this[d](k)},blend:function(b){if(this._rgba[3]===1)return this;var c=this._rgba.slice(),d=c.pop(),e=f(b)._rgba;return f(a.map(c,function(a,b){return(1-d)*e[b]+d*a}))},toRgbaString:function(){var b="rgba(",c=a.map(this._rgba,function(a,b){return a==null?b>2?1:0:a});return c[3]===1&&(c.pop(),b="rgb("),b+c.join()+")"},toHslaString:function(){var b="hsla(",c=a.map(this.hsla(),function(a,b){return a==null&&(a=b>2?1:0),b&&b<3&&(a=Math.round(a*100)+"%"),a});return c[3]===1&&(c.pop(),b="hsl("),b+c.join()+")"},toHexString:function(b){var c=this._rgba.slice(),d=c.pop();return b&&c.push(~~(d*255)),"#"+a.map(c,function(a){return a=(a||0).toString(16),a.length===1?"0"+a:a}).join("")},toString:function(){return this._rgba[3]===0?"transparent":this.toRgbaString()}}),f.fn.parse.prototype=f.fn,g.hsla.to=function(a){if(a[0]==null||a[1]==null||a[2]==null)return[null,null,null,a[3]];var b=a[0]/255,c=a[1]/255,d=a[2]/255,e=a[3],f=Math.max(b,c,d),g=Math.min(b,c,d),h=f-g,i=f+g,j=i*.5,k,l;return g===f?k=0:b===f?k=60*(c-d)/h+360:c===f?k=60*(d-b)/h+120:k=60*(b-c)/h+240,h===0?l=0:j<=.5?l=h/i:l=h/(2-i),[Math.round(k)%360,l,j,e==null?1:e]},g.hsla.from=function(a){if(a[0]==null||a[1]==null||a[2]==null)return[null,null,null,a[3]];var b=a[0]/360,c=a[1],d=a[2],e=a[3],f=d<=.5?d*(1+c):d+c-d*c,g=2*d-f;return[Math.round(o(g,f,b+1/3)*255),Math.round(o(g,f,b)*255),Math.round(o(g,f,b-1/3)*255),e]},l(g,function(c,e){var g=e.props,h=e.cache,i=e.to,j=e.from;f.fn[c]=function(c){i&&!this[h]&&(this[h]=i(this._rgba));if(c===b)return this[h].slice();var d,e=a.type(c),k=e==="array"||e==="object"?c:arguments,n=this[h].slice();return l(g,function(a,b){var c=k[e==="object"?a:b.idx];c==null&&(c=n[b.idx]),n[b.idx]=m(c,b)}),j?(d=f(j(n)),d[h]=n,d):f(n)},l(g,function(b,e){if(f.fn[b])return;f.fn[b]=function(f){var g=a.type(f),h=b==="alpha"?this._hsla?"hsla":"rgba":c,i=this[h](),j=i[e.idx],k;return g==="undefined"?j:(g==="function"&&(f=f.call(this,j),g=a.type(f)),f==null&&e.empty?this:(g==="string"&&(k=d.exec(f),k&&(f=j+parseFloat(k[2])*(k[1]==="+"?1:-1))),i[e.idx]=f,this[h](i)))}})}),f.hook=function(b){var c=b.split(" ");l(c,function(b,c){a.cssHooks[c]={set:function(b,d){var e,g,h="";if(d!=="transparent"&&(a.type(d)!=="string"||(e=n(d)))){d=f(e||d);if(!i.rgba&&d._rgba[3]!==1){g=c==="backgroundColor"?b.parentNode:b;while((h===""||h==="transparent")&&g&&g.style)try{h=a.css(g,"backgroundColor"),g=g.parentNode}catch(j){}d=d.blend(h&&h!=="transparent"?h:"_default")}d=d.toRgbaString()}try{b.style[c]=d}catch(j){}}},a.fx.step[c]=function(b){b.colorInit||(b.start=f(b.elem,c),b.end=f(b.end),b.colorInit=!0),a.cssHooks[c].set(b.elem,b.start.transition(b.end,b.pos))}})},f.hook(c),a.cssHooks.borderColor={expand:function(a){var b={};return l(["Top","Right","Bottom","Left"],function(c,d){b["border"+d+"Color"]=a}),b}},k=a.Color.names={aqua:"#00ffff",black:"#000000",blue:"#0000ff",fuchsia:"#ff00ff",gray:"#808080",green:"#008000",lime:"#00ff00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#ff0000",silver:"#c0c0c0",teal:"#008080",white:"#ffffff",yellow:"#ffff00",transparent:[null,null,null,0],_default:"#ffffff"}})(jQuery);
+
/*!
 +
* jQuery Color Animations v@VERSION
 +
* https://github.com/jquery/jquery-color
 +
*
 +
* Copyright jQuery Foundation and other contributors
 +
* Released under the MIT license.
 +
* http://jquery.org/license
 +
*
 +
* Date: @DATE
 +
*/
 +
 
 +
( function( root, factory ) {
 +
if ( typeof define === "function" && define.amd ) {
 +
 
 +
// AMD. Register as an anonymous module.
 +
define( [ "jquery" ], factory );
 +
} else if ( typeof exports === "object" ) {
 +
module.exports = factory( require( "jquery" ) );
 +
} else {
 +
factory( root.jQuery );
 +
}
 +
} )( this, function( jQuery, undefined ) {
 +
 
 +
var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor " +
 +
"borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
 +
 
 +
class2type = {},
 +
toString = class2type.toString,
 +
 
 +
// plusequals test for += 100 -= 100
 +
rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
 +
 
 +
// a set of RE's that can match strings and generate color tuples.
 +
stringParsers = [ {
 +
re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
 +
parse: function( execResult ) {
 +
return [
 +
execResult[ 1 ],
 +
execResult[ 2 ],
 +
execResult[ 3 ],
 +
execResult[ 4 ]
 +
];
 +
}
 +
}, {
 +
re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
 +
parse: function( execResult ) {
 +
return [
 +
execResult[ 1 ] * 2.55,
 +
execResult[ 2 ] * 2.55,
 +
execResult[ 3 ] * 2.55,
 +
execResult[ 4 ]
 +
];
 +
}
 +
}, {
 +
 
 +
// this regex ignores A-F because it's compared against an already lowercased string
 +
re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
 +
parse: function( execResult ) {
 +
return [
 +
parseInt( execResult[ 1 ], 16 ),
 +
parseInt( execResult[ 2 ], 16 ),
 +
parseInt( execResult[ 3 ], 16 )
 +
];
 +
}
 +
}, {
 +
 
 +
// this regex ignores A-F because it's compared against an already lowercased string
 +
re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
 +
parse: function( execResult ) {
 +
return [
 +
parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
 +
parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
 +
parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
 +
];
 +
}
 +
}, {
 +
re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
 +
space: "hsla",
 +
parse: function( execResult ) {
 +
return [
 +
execResult[ 1 ],
 +
execResult[ 2 ] / 100,
 +
execResult[ 3 ] / 100,
 +
execResult[ 4 ]
 +
];
 +
}
 +
} ],
 +
 
 +
// jQuery.Color( )
 +
color = jQuery.Color = function( color, green, blue, alpha ) {
 +
return new jQuery.Color.fn.parse( color, green, blue, alpha );
 +
},
 +
spaces = {
 +
rgba: {
 +
props: {
 +
red: {
 +
idx: 0,
 +
type: "byte"
 +
},
 +
green: {
 +
idx: 1,
 +
type: "byte"
 +
},
 +
blue: {
 +
idx: 2,
 +
type: "byte"
 +
}
 +
}
 +
},
 +
 
 +
hsla: {
 +
props: {
 +
hue: {
 +
idx: 0,
 +
type: "degrees"
 +
},
 +
saturation: {
 +
idx: 1,
 +
type: "percent"
 +
},
 +
lightness: {
 +
idx: 2,
 +
type: "percent"
 +
}
 +
}
 +
}
 +
},
 +
propTypes = {
 +
"byte": {
 +
floor: true,
 +
max: 255
 +
},
 +
"percent": {
 +
max: 1
 +
},
 +
"degrees": {
 +
mod: 360,
 +
floor: true
 +
}
 +
},
 +
 
 +
// colors = jQuery.Color.names
 +
colors,
 +
 
 +
// local aliases of functions called often
 +
each = jQuery.each;
 +
 
 +
// define cache name and alpha properties
 +
// for rgba and hsla spaces
 +
each( spaces, function( spaceName, space ) {
 +
space.cache = "_" + spaceName;
 +
space.props.alpha = {
 +
idx: 3,
 +
type: "percent",
 +
def: 1
 +
};
 +
} );
 +
 
 +
// Populate the class2type map
 +
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
 +
function( i, name ) {
 +
class2type[ "[object " + name + "]" ] = name.toLowerCase();
 +
} );
 +
 
 +
function getType( obj ) {
 +
if ( obj == null ) {
 +
return obj + "";
 +
}
 +
 
 +
return typeof obj === "object" ?
 +
class2type[ toString.call( obj ) ] || "object" :
 +
typeof obj;
 +
}
 +
 
 +
function clamp( value, prop, allowEmpty ) {
 +
var type = propTypes[ prop.type ] || {};
 +
 
 +
if ( value == null ) {
 +
return ( allowEmpty || !prop.def ) ? null : prop.def;
 +
}
 +
 
 +
// ~~ is an short way of doing floor for positive numbers
 +
value = type.floor ? ~~value : parseFloat( value );
 +
 
 +
if ( type.mod ) {
 +
 
 +
// we add mod before modding to make sure that negatives values
 +
// get converted properly: -10 -> 350
 +
return ( value + type.mod ) % type.mod;
 +
}
 +
 
 +
// for now all property types without mod have min and max
 +
return Math.min( type.max, Math.max( 0, value ) );
 +
}
 +
 
 +
function stringParse( string ) {
 +
var inst = color(),
 +
rgba = inst._rgba = [];
 +
 
 +
string = string.toLowerCase();
 +
 
 +
each( stringParsers, function( i, parser ) {
 +
var parsed,
 +
match = parser.re.exec( string ),
 +
values = match && parser.parse( match ),
 +
spaceName = parser.space || "rgba";
 +
 
 +
if ( values ) {
 +
parsed = inst[ spaceName ]( values );
 +
 
 +
// if this was an rgba parse the assignment might happen twice
 +
// oh well....
 +
inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
 +
rgba = inst._rgba = parsed._rgba;
 +
 
 +
// exit each( stringParsers ) here because we matched
 +
return false;
 +
}
 +
} );
 +
 
 +
// Found a stringParser that handled it
 +
if ( rgba.length ) {
 +
 
 +
// if this came from a parsed string, force "transparent" when alpha is 0
 +
// chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
 +
if ( rgba.join() === "0,0,0,0" ) {
 +
jQuery.extend( rgba, colors.transparent );
 +
}
 +
return inst;
 +
}
 +
 
 +
// named colors
 +
return colors[ string ];
 +
}
 +
 
 +
color.fn = jQuery.extend( color.prototype, {
 +
parse: function( red, green, blue, alpha ) {
 +
if ( red === undefined ) {
 +
this._rgba = [ null, null, null, null ];
 +
return this;
 +
}
 +
if ( red.jquery || red.nodeType ) {
 +
red = jQuery( red ).css( green );
 +
green = undefined;
 +
}
 +
 
 +
var inst = this,
 +
type = getType( red ),
 +
rgba = this._rgba = [];
 +
 
 +
// more than 1 argument specified - assume ( red, green, blue, alpha )
 +
if ( green !== undefined ) {
 +
red = [ red, green, blue, alpha ];
 +
type = "array";
 +
}
 +
 
 +
if ( type === "string" ) {
 +
return this.parse( stringParse( red ) || colors._default );
 +
}
 +
 
 +
if ( type === "array" ) {
 +
each( spaces.rgba.props, function( key, prop ) {
 +
rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
 +
} );
 +
return this;
 +
}
 +
 
 +
if ( type === "object" ) {
 +
if ( red instanceof color ) {
 +
each( spaces, function( spaceName, space ) {
 +
if ( red[ space.cache ] ) {
 +
inst[ space.cache ] = red[ space.cache ].slice();
 +
}
 +
} );
 +
} else {
 +
each( spaces, function( spaceName, space ) {
 +
var cache = space.cache;
 +
each( space.props, function( key, prop ) {
 +
 
 +
// if the cache doesn't exist, and we know how to convert
 +
if ( !inst[ cache ] && space.to ) {
 +
 
 +
// if the value was null, we don't need to copy it
 +
// if the key was alpha, we don't need to copy it either
 +
if ( key === "alpha" || red[ key ] == null ) {
 +
return;
 +
}
 +
inst[ cache ] = space.to( inst._rgba );
 +
}
 +
 
 +
// this is the only case where we allow nulls for ALL properties.
 +
// call clamp with alwaysAllowEmpty
 +
inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
 +
} );
 +
 
 +
// everything defined but alpha?
 +
if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
 +
 
 +
// use the default of 1
 +
if ( inst[ cache ][ 3 ] == null ) {
 +
inst[ cache ][ 3 ] = 1;
 +
}
 +
 
 +
if ( space.from ) {
 +
inst._rgba = space.from( inst[ cache ] );
 +
}
 +
}
 +
} );
 +
}
 +
return this;
 +
}
 +
},
 +
is: function( compare ) {
 +
var is = color( compare ),
 +
same = true,
 +
inst = this;
 +
 
 +
each( spaces, function( _, space ) {
 +
var localCache,
 +
isCache = is[ space.cache ];
 +
if ( isCache ) {
 +
localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
 +
each( space.props, function( _, prop ) {
 +
if ( isCache[ prop.idx ] != null ) {
 +
same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
 +
return same;
 +
}
 +
} );
 +
}
 +
return same;
 +
} );
 +
return same;
 +
},
 +
_space: function() {
 +
var used = [],
 +
inst = this;
 +
each( spaces, function( spaceName, space ) {
 +
if ( inst[ space.cache ] ) {
 +
used.push( spaceName );
 +
}
 +
} );
 +
return used.pop();
 +
},
 +
transition: function( other, distance ) {
 +
var end = color( other ),
 +
spaceName = end._space(),
 +
space = spaces[ spaceName ],
 +
startColor = this.alpha() === 0 ? color( "transparent" ) : this,
 +
start = startColor[ space.cache ] || space.to( startColor._rgba ),
 +
result = start.slice();
 +
 
 +
end = end[ space.cache ];
 +
each( space.props, function( key, prop ) {
 +
var index = prop.idx,
 +
startValue = start[ index ],
 +
endValue = end[ index ],
 +
type = propTypes[ prop.type ] || {};
 +
 
 +
// if null, don't override start value
 +
if ( endValue === null ) {
 +
return;
 +
}
 +
 
 +
// if null - use end
 +
if ( startValue === null ) {
 +
result[ index ] = endValue;
 +
} else {
 +
if ( type.mod ) {
 +
if ( endValue - startValue > type.mod / 2 ) {
 +
startValue += type.mod;
 +
} else if ( startValue - endValue > type.mod / 2 ) {
 +
startValue -= type.mod;
 +
}
 +
}
 +
result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
 +
}
 +
} );
 +
return this[ spaceName ]( result );
 +
},
 +
blend: function( opaque ) {
 +
 
 +
// if we are already opaque - return ourself
 +
if ( this._rgba[ 3 ] === 1 ) {
 +
return this;
 +
}
 +
 
 +
var rgb = this._rgba.slice(),
 +
a = rgb.pop(),
 +
blend = color( opaque )._rgba;
 +
 
 +
return color( jQuery.map( rgb, function( v, i ) {
 +
return ( 1 - a ) * blend[ i ] + a * v;
 +
} ) );
 +
},
 +
toRgbaString: function() {
 +
var prefix = "rgba(",
 +
rgba = jQuery.map( this._rgba, function( v, i ) {
 +
                if ( v != null ) {
 +
                    return v;
 +
                }
 +
return i > 2 ? 1 : 0;
 +
} );
 +
 
 +
if ( rgba[ 3 ] === 1 ) {
 +
rgba.pop();
 +
prefix = "rgb(";
 +
}
 +
 
 +
return prefix + rgba.join() + ")";
 +
},
 +
toHslaString: function() {
 +
var prefix = "hsla(",
 +
hsla = jQuery.map( this.hsla(), function( v, i ) {
 +
if ( v == null ) {
 +
v = i > 2 ? 1 : 0;
 +
}
 +
 
 +
// catch 1 and 2
 +
if ( i && i < 3 ) {
 +
v = Math.round( v * 100 ) + "%";
 +
}
 +
return v;
 +
} );
 +
 
 +
if ( hsla[ 3 ] === 1 ) {
 +
hsla.pop();
 +
prefix = "hsl(";
 +
}
 +
return prefix + hsla.join() + ")";
 +
},
 +
toHexString: function( includeAlpha ) {
 +
var rgba = this._rgba.slice(),
 +
alpha = rgba.pop();
 +
 
 +
if ( includeAlpha ) {
 +
rgba.push( ~~( alpha * 255 ) );
 +
}
 +
 
 +
return "#" + jQuery.map( rgba, function( v ) {
 +
 
 +
// default to 0 when nulls exist
 +
return ( "0" + ( v || 0 ).toString( 16 ) ).substr( -2 );
 +
} ).join( "" );
 +
},
 +
toString: function() {
 +
return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
 +
}
 +
} );
 +
color.fn.parse.prototype = color.fn;
 +
 
 +
// hsla conversions adapted from:
 +
// https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
 +
 
 +
function hue2rgb( p, q, h ) {
 +
h = ( h + 1 ) % 1;
 +
if ( h * 6 < 1 ) {
 +
return p + ( q - p ) * h * 6;
 +
}
 +
if ( h * 2 < 1 ) {
 +
return q;
 +
}
 +
if ( h * 3 < 2 ) {
 +
return p + ( q - p ) * ( ( 2 / 3 ) - h ) * 6;
 +
}
 +
return p;
 +
}
 +
 
 +
spaces.hsla.to = function( rgba ) {
 +
if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
 +
return [ null, null, null, rgba[ 3 ] ];
 +
}
 +
var r = rgba[ 0 ] / 255,
 +
g = rgba[ 1 ] / 255,
 +
b = rgba[ 2 ] / 255,
 +
a = rgba[ 3 ],
 +
max = Math.max( r, g, b ),
 +
min = Math.min( r, g, b ),
 +
diff = max - min,
 +
add = max + min,
 +
l = add * 0.5,
 +
h, s;
 +
 
 +
if ( min === max ) {
 +
h = 0;
 +
} else if ( r === max ) {
 +
h = ( 60 * ( g - b ) / diff ) + 360;
 +
} else if ( g === max ) {
 +
h = ( 60 * ( b - r ) / diff ) + 120;
 +
} else {
 +
h = ( 60 * ( r - g ) / diff ) + 240;
 +
}
 +
 
 +
// chroma (diff) == 0 means greyscale which, by definition, saturation = 0%
 +
// otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)
 +
if ( diff === 0 ) {
 +
s = 0;
 +
} else if ( l <= 0.5 ) {
 +
s = diff / add;
 +
} else {
 +
s = diff / ( 2 - add );
 +
}
 +
return [ Math.round( h ) % 360, s, l, a == null ? 1 : a ];
 +
};
 +
 
 +
spaces.hsla.from = function( hsla ) {
 +
if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
 +
return [ null, null, null, hsla[ 3 ] ];
 +
}
 +
var h = hsla[ 0 ] / 360,
 +
s = hsla[ 1 ],
 +
l = hsla[ 2 ],
 +
a = hsla[ 3 ],
 +
q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
 +
p = 2 * l - q;
 +
 
 +
return [
 +
Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
 +
Math.round( hue2rgb( p, q, h ) * 255 ),
 +
Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
 +
a
 +
];
 +
};
 +
 
 +
 
 +
each( spaces, function( spaceName, space ) {
 +
var props = space.props,
 +
cache = space.cache,
 +
to = space.to,
 +
from = space.from;
 +
 
 +
// makes rgba() and hsla()
 +
color.fn[ spaceName ] = function( value ) {
 +
 
 +
// generate a cache for this space if it doesn't exist
 +
if ( to && !this[ cache ] ) {
 +
this[ cache ] = to( this._rgba );
 +
}
 +
if ( value === undefined ) {
 +
return this[ cache ].slice();
 +
}
 +
 
 +
var ret,
 +
type = getType( value ),
 +
arr = ( type === "array" || type === "object" ) ? value : arguments,
 +
local = this[ cache ].slice();
 +
 
 +
each( props, function( key, prop ) {
 +
var val = arr[ type === "object" ? key : prop.idx ];
 +
if ( val == null ) {
 +
val = local[ prop.idx ];
 +
}
 +
local[ prop.idx ] = clamp( val, prop );
 +
} );
 +
 
 +
if ( from ) {
 +
ret = color( from( local ) );
 +
ret[ cache ] = local;
 +
return ret;
 +
} else {
 +
return color( local );
 +
}
 +
};
 +
 
 +
// makes red() green() blue() alpha() hue() saturation() lightness()
 +
each( props, function( key, prop ) {
 +
 
 +
// alpha is included in more than one space
 +
if ( color.fn[ key ] ) {
 +
return;
 +
}
 +
color.fn[ key ] = function( value ) {
 +
var local, cur, match, fn,
 +
vtype = getType( value );
 +
 
 +
if ( key === "alpha" ) {
 +
fn = this._hsla ? "hsla" : "rgba";
 +
} else {
 +
fn = spaceName;
 +
}
 +
local = this[ fn ]();
 +
cur = local[ prop.idx ];
 +
 
 +
if ( vtype === "undefined" ) {
 +
return cur;
 +
}
 +
 
 +
if ( vtype === "function" ) {
 +
value = value.call( this, cur );
 +
vtype = getType( value );
 +
}
 +
if ( value == null && prop.empty ) {
 +
return this;
 +
}
 +
if ( vtype === "string" ) {
 +
match = rplusequals.exec( value );
 +
if ( match ) {
 +
value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
 +
}
 +
}
 +
local[ prop.idx ] = value;
 +
return this[ fn ]( local );
 +
};
 +
} );
 +
} );
 +
 
 +
// add cssHook and .fx.step function for each named hook.
 +
// accept a space separated string of properties
 +
color.hook = function( hook ) {
 +
var hooks = hook.split( " " );
 +
each( hooks, function( i, hook ) {
 +
jQuery.cssHooks[ hook ] = {
 +
set: function( elem, value ) {
 +
var parsed;
 +
 
 +
if ( value !== "transparent" && ( getType( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) {
 +
value = color( parsed || value );
 +
value = value.toRgbaString();
 +
}
 +
elem.style[ hook ] = value;
 +
}
 +
};
 +
jQuery.fx.step[ hook ] = function( fx ) {
 +
if ( !fx.colorInit ) {
 +
fx.start = color( fx.elem, hook );
 +
fx.end = color( fx.end );
 +
fx.colorInit = true;
 +
}
 +
jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
 +
};
 +
} );
 +
 
 +
};
 +
 
 +
color.hook( stepHooks );
 +
 
 +
jQuery.cssHooks.borderColor = {
 +
expand: function( value ) {
 +
var expanded = {};
 +
 
 +
each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
 +
expanded[ "border" + part + "Color" ] = value;
 +
} );
 +
return expanded;
 +
}
 +
};
 +
 
 +
// Basic color names only.
 +
// Usage of any of the other color names requires adding yourself or including
 +
// jquery.color.svg-names.js.
 +
colors = jQuery.Color.names = {
 +
 
 +
// 4.1. Basic color keywords
 +
aqua: "#00ffff",
 +
black: "#000000",
 +
blue: "#0000ff",
 +
fuchsia: "#ff00ff",
 +
gray: "#808080",
 +
green: "#008000",
 +
lime: "#00ff00",
 +
maroon: "#800000",
 +
navy: "#000080",
 +
olive: "#808000",
 +
purple: "#800080",
 +
red: "#ff0000",
 +
silver: "#c0c0c0",
 +
teal: "#008080",
 +
white: "#ffffff",
 +
yellow: "#ffff00",
 +
 
 +
// 4.2.3. "transparent" color keyword
 +
transparent: [ null, null, null, 0 ],
 +
 
 +
_default: "#ffffff"
 +
};
 +
 
 +
} );

Latest revision as of 08:08, 22 September 2018

/*!

* jQuery Color Animations v@VERSION
* https://github.com/jquery/jquery-color
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* Date: @DATE
*/

( function( root, factory ) { if ( typeof define === "function" && define.amd ) {

// AMD. Register as an anonymous module. define( [ "jquery" ], factory ); } else if ( typeof exports === "object" ) { module.exports = factory( require( "jquery" ) ); } else { factory( root.jQuery ); } } )( this, function( jQuery, undefined ) {

var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor " + "borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",

class2type = {}, toString = class2type.toString,

// plusequals test for += 100 -= 100 rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,

// a set of RE's that can match strings and generate color tuples. stringParsers = [ { re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/, parse: function( execResult ) { return [ execResult[ 1 ], execResult[ 2 ], execResult[ 3 ], execResult[ 4 ] ]; } }, { re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/, parse: function( execResult ) { return [ execResult[ 1 ] * 2.55, execResult[ 2 ] * 2.55, execResult[ 3 ] * 2.55, execResult[ 4 ] ]; } }, {

// this regex ignores A-F because it's compared against an already lowercased string re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/, parse: function( execResult ) { return [ parseInt( execResult[ 1 ], 16 ), parseInt( execResult[ 2 ], 16 ), parseInt( execResult[ 3 ], 16 ) ]; } }, {

// this regex ignores A-F because it's compared against an already lowercased string re: /#([a-f0-9])([a-f0-9])([a-f0-9])/, parse: function( execResult ) { return [ parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ), parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ), parseInt( execResult[ 3 ] + execResult[ 3 ], 16 ) ]; } }, { re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/, space: "hsla", parse: function( execResult ) { return [ execResult[ 1 ], execResult[ 2 ] / 100, execResult[ 3 ] / 100, execResult[ 4 ] ]; } } ],

// jQuery.Color( ) color = jQuery.Color = function( color, green, blue, alpha ) { return new jQuery.Color.fn.parse( color, green, blue, alpha ); }, spaces = { rgba: { props: { red: { idx: 0, type: "byte" }, green: { idx: 1, type: "byte" }, blue: { idx: 2, type: "byte" } } },

hsla: { props: { hue: { idx: 0, type: "degrees" }, saturation: { idx: 1, type: "percent" }, lightness: { idx: 2, type: "percent" } } } }, propTypes = { "byte": { floor: true, max: 255 }, "percent": { max: 1 }, "degrees": { mod: 360, floor: true } },

// colors = jQuery.Color.names colors,

// local aliases of functions called often each = jQuery.each;

// define cache name and alpha properties // for rgba and hsla spaces each( spaces, function( spaceName, space ) { space.cache = "_" + spaceName; space.props.alpha = { idx: 3, type: "percent", def: 1 }; } );

// Populate the class2type map jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ), function( i, name ) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); } );

function getType( obj ) { if ( obj == null ) { return obj + ""; }

return typeof obj === "object" ? class2type[ toString.call( obj ) ] || "object" : typeof obj; }

function clamp( value, prop, allowEmpty ) { var type = propTypes[ prop.type ] || {};

if ( value == null ) { return ( allowEmpty || !prop.def ) ? null : prop.def; }

// ~~ is an short way of doing floor for positive numbers value = type.floor ? ~~value : parseFloat( value );

if ( type.mod ) {

// we add mod before modding to make sure that negatives values // get converted properly: -10 -> 350 return ( value + type.mod ) % type.mod; }

// for now all property types without mod have min and max return Math.min( type.max, Math.max( 0, value ) ); }

function stringParse( string ) { var inst = color(), rgba = inst._rgba = [];

string = string.toLowerCase();

each( stringParsers, function( i, parser ) { var parsed, match = parser.re.exec( string ), values = match && parser.parse( match ), spaceName = parser.space || "rgba";

if ( values ) { parsed = inst[ spaceName ]( values );

// if this was an rgba parse the assignment might happen twice // oh well.... inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ]; rgba = inst._rgba = parsed._rgba;

// exit each( stringParsers ) here because we matched return false; } } );

// Found a stringParser that handled it if ( rgba.length ) {

// if this came from a parsed string, force "transparent" when alpha is 0 // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0) if ( rgba.join() === "0,0,0,0" ) { jQuery.extend( rgba, colors.transparent ); } return inst; }

// named colors return colors[ string ]; }

color.fn = jQuery.extend( color.prototype, { parse: function( red, green, blue, alpha ) { if ( red === undefined ) { this._rgba = [ null, null, null, null ]; return this; } if ( red.jquery || red.nodeType ) { red = jQuery( red ).css( green ); green = undefined; }

var inst = this, type = getType( red ), rgba = this._rgba = [];

// more than 1 argument specified - assume ( red, green, blue, alpha ) if ( green !== undefined ) { red = [ red, green, blue, alpha ]; type = "array"; }

if ( type === "string" ) { return this.parse( stringParse( red ) || colors._default ); }

if ( type === "array" ) { each( spaces.rgba.props, function( key, prop ) { rgba[ prop.idx ] = clamp( red[ prop.idx ], prop ); } ); return this; }

if ( type === "object" ) { if ( red instanceof color ) { each( spaces, function( spaceName, space ) { if ( red[ space.cache ] ) { inst[ space.cache ] = red[ space.cache ].slice(); } } ); } else { each( spaces, function( spaceName, space ) { var cache = space.cache; each( space.props, function( key, prop ) {

// if the cache doesn't exist, and we know how to convert if ( !inst[ cache ] && space.to ) {

// if the value was null, we don't need to copy it // if the key was alpha, we don't need to copy it either if ( key === "alpha" || red[ key ] == null ) { return; } inst[ cache ] = space.to( inst._rgba ); }

// this is the only case where we allow nulls for ALL properties. // call clamp with alwaysAllowEmpty inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true ); } );

// everything defined but alpha? if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {

// use the default of 1 if ( inst[ cache ][ 3 ] == null ) { inst[ cache ][ 3 ] = 1; }

if ( space.from ) { inst._rgba = space.from( inst[ cache ] ); } } } ); } return this; } }, is: function( compare ) { var is = color( compare ), same = true, inst = this;

each( spaces, function( _, space ) { var localCache, isCache = is[ space.cache ]; if ( isCache ) { localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || []; each( space.props, function( _, prop ) { if ( isCache[ prop.idx ] != null ) { same = ( isCache[ prop.idx ] === localCache[ prop.idx ] ); return same; } } ); } return same; } ); return same; }, _space: function() { var used = [], inst = this; each( spaces, function( spaceName, space ) { if ( inst[ space.cache ] ) { used.push( spaceName ); } } ); return used.pop(); }, transition: function( other, distance ) { var end = color( other ), spaceName = end._space(), space = spaces[ spaceName ], startColor = this.alpha() === 0 ? color( "transparent" ) : this, start = startColor[ space.cache ] || space.to( startColor._rgba ), result = start.slice();

end = end[ space.cache ]; each( space.props, function( key, prop ) { var index = prop.idx, startValue = start[ index ], endValue = end[ index ], type = propTypes[ prop.type ] || {};

// if null, don't override start value if ( endValue === null ) { return; }

// if null - use end if ( startValue === null ) { result[ index ] = endValue; } else { if ( type.mod ) { if ( endValue - startValue > type.mod / 2 ) { startValue += type.mod; } else if ( startValue - endValue > type.mod / 2 ) { startValue -= type.mod; } } result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop ); } } ); return this[ spaceName ]( result ); }, blend: function( opaque ) {

// if we are already opaque - return ourself if ( this._rgba[ 3 ] === 1 ) { return this; }

var rgb = this._rgba.slice(), a = rgb.pop(), blend = color( opaque )._rgba;

return color( jQuery.map( rgb, function( v, i ) { return ( 1 - a ) * blend[ i ] + a * v; } ) ); }, toRgbaString: function() { var prefix = "rgba(", rgba = jQuery.map( this._rgba, function( v, i ) {

               if ( v != null ) {
                   return v;
               }

return i > 2 ? 1 : 0; } );

if ( rgba[ 3 ] === 1 ) { rgba.pop(); prefix = "rgb("; }

return prefix + rgba.join() + ")"; }, toHslaString: function() { var prefix = "hsla(", hsla = jQuery.map( this.hsla(), function( v, i ) { if ( v == null ) { v = i > 2 ? 1 : 0; }

// catch 1 and 2 if ( i && i < 3 ) { v = Math.round( v * 100 ) + "%"; } return v; } );

if ( hsla[ 3 ] === 1 ) { hsla.pop(); prefix = "hsl("; } return prefix + hsla.join() + ")"; }, toHexString: function( includeAlpha ) { var rgba = this._rgba.slice(), alpha = rgba.pop();

if ( includeAlpha ) { rgba.push( ~~( alpha * 255 ) ); }

return "#" + jQuery.map( rgba, function( v ) {

// default to 0 when nulls exist return ( "0" + ( v || 0 ).toString( 16 ) ).substr( -2 ); } ).join( "" ); }, toString: function() { return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString(); } } ); color.fn.parse.prototype = color.fn;

// hsla conversions adapted from: // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021

function hue2rgb( p, q, h ) { h = ( h + 1 ) % 1; if ( h * 6 < 1 ) { return p + ( q - p ) * h * 6; } if ( h * 2 < 1 ) { return q; } if ( h * 3 < 2 ) { return p + ( q - p ) * ( ( 2 / 3 ) - h ) * 6; } return p; }

spaces.hsla.to = function( rgba ) { if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) { return [ null, null, null, rgba[ 3 ] ]; } var r = rgba[ 0 ] / 255, g = rgba[ 1 ] / 255, b = rgba[ 2 ] / 255, a = rgba[ 3 ], max = Math.max( r, g, b ), min = Math.min( r, g, b ), diff = max - min, add = max + min, l = add * 0.5, h, s;

if ( min === max ) { h = 0; } else if ( r === max ) { h = ( 60 * ( g - b ) / diff ) + 360; } else if ( g === max ) { h = ( 60 * ( b - r ) / diff ) + 120; } else { h = ( 60 * ( r - g ) / diff ) + 240; }

// chroma (diff) == 0 means greyscale which, by definition, saturation = 0% // otherwise, saturation is based on the ratio of chroma (diff) to lightness (add) if ( diff === 0 ) { s = 0; } else if ( l <= 0.5 ) { s = diff / add; } else { s = diff / ( 2 - add ); } return [ Math.round( h ) % 360, s, l, a == null ? 1 : a ]; };

spaces.hsla.from = function( hsla ) { if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) { return [ null, null, null, hsla[ 3 ] ]; } var h = hsla[ 0 ] / 360, s = hsla[ 1 ], l = hsla[ 2 ], a = hsla[ 3 ], q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s, p = 2 * l - q;

return [ Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ), Math.round( hue2rgb( p, q, h ) * 255 ), Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ), a ]; };


each( spaces, function( spaceName, space ) { var props = space.props, cache = space.cache, to = space.to, from = space.from;

// makes rgba() and hsla() color.fn[ spaceName ] = function( value ) {

// generate a cache for this space if it doesn't exist if ( to && !this[ cache ] ) { this[ cache ] = to( this._rgba ); } if ( value === undefined ) { return this[ cache ].slice(); }

var ret, type = getType( value ), arr = ( type === "array" || type === "object" ) ? value : arguments, local = this[ cache ].slice();

each( props, function( key, prop ) { var val = arr[ type === "object" ? key : prop.idx ]; if ( val == null ) { val = local[ prop.idx ]; } local[ prop.idx ] = clamp( val, prop ); } );

if ( from ) { ret = color( from( local ) ); ret[ cache ] = local; return ret; } else { return color( local ); } };

// makes red() green() blue() alpha() hue() saturation() lightness() each( props, function( key, prop ) {

// alpha is included in more than one space if ( color.fn[ key ] ) { return; } color.fn[ key ] = function( value ) { var local, cur, match, fn, vtype = getType( value );

if ( key === "alpha" ) { fn = this._hsla ? "hsla" : "rgba"; } else { fn = spaceName; } local = this[ fn ](); cur = local[ prop.idx ];

if ( vtype === "undefined" ) { return cur; }

if ( vtype === "function" ) { value = value.call( this, cur ); vtype = getType( value ); } if ( value == null && prop.empty ) { return this; } if ( vtype === "string" ) { match = rplusequals.exec( value ); if ( match ) { value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 ); } } local[ prop.idx ] = value; return this[ fn ]( local ); }; } ); } );

// add cssHook and .fx.step function for each named hook. // accept a space separated string of properties color.hook = function( hook ) { var hooks = hook.split( " " ); each( hooks, function( i, hook ) { jQuery.cssHooks[ hook ] = { set: function( elem, value ) { var parsed;

if ( value !== "transparent" && ( getType( value ) !== "string" || ( parsed = stringParse( value ) ) ) ) { value = color( parsed || value ); value = value.toRgbaString(); } elem.style[ hook ] = value; } }; jQuery.fx.step[ hook ] = function( fx ) { if ( !fx.colorInit ) { fx.start = color( fx.elem, hook ); fx.end = color( fx.end ); fx.colorInit = true; } jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) ); }; } );

};

color.hook( stepHooks );

jQuery.cssHooks.borderColor = { expand: function( value ) { var expanded = {};

each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) { expanded[ "border" + part + "Color" ] = value; } ); return expanded; } };

// Basic color names only. // Usage of any of the other color names requires adding yourself or including // jquery.color.svg-names.js. colors = jQuery.Color.names = {

// 4.1. Basic color keywords aqua: "#00ffff", black: "#000000", blue: "#0000ff", fuchsia: "#ff00ff", gray: "#808080", green: "#008000", lime: "#00ff00", maroon: "#800000", navy: "#000080", olive: "#808000", purple: "#800080", red: "#ff0000", silver: "#c0c0c0", teal: "#008080", white: "#ffffff", yellow: "#ffff00",

// 4.2.3. "transparent" color keyword transparent: [ null, null, null, 0 ],

_default: "#ffffff" };

} );