1/* 2 * jQuery Color Animations v@VERSION 3 * http://jquery.org/ 4 * 5 * Copyright 2011 John Resig 6 * Dual licensed under the MIT or GPL Version 2 licenses. 7 * http://jquery.org/license 8 */ 9/* 10 * jQuery Color Animations v@VERSION 11 * http://jquery.org/ 12 * 13 * Copyright 2011 John Resig 14 * Dual licensed under the MIT or GPL Version 2 licenses. 15 * http://jquery.org/license 16 * 17 * Date: @DATE 18 */ 19 20(function( jQuery, undefined ){ 21 var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color outlineColor".split(" "), 22 23 // plusequals test for += 100 -= 100 24 rplusequals = /^([\-+])=\s*(\d+\.?\d*)/, 25 // a set of RE's that can match strings and generate color tuples. 26 stringParsers = [{ 27 re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, 28 parse: function( execResult ) { 29 return [ 30 execResult[ 1 ], 31 execResult[ 2 ], 32 execResult[ 3 ], 33 execResult[ 4 ] 34 ]; 35 } 36 }, { 37 re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, 38 parse: function( execResult ) { 39 return [ 40 2.55 * execResult[1], 41 2.55 * execResult[2], 42 2.55 * execResult[3], 43 execResult[ 4 ] 44 ]; 45 } 46 }, { 47 re: /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/, 48 parse: function( execResult ) { 49 return [ 50 parseInt( execResult[ 1 ], 16 ), 51 parseInt( execResult[ 2 ], 16 ), 52 parseInt( execResult[ 3 ], 16 ) 53 ]; 54 } 55 }, { 56 re: /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/, 57 parse: function( execResult ) { 58 return [ 59 parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ), 60 parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ), 61 parseInt( execResult[ 3 ] + execResult[ 3 ], 16 ) 62 ]; 63 } 64 }, { 65 re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, 66 space: "hsla", 67 parse: function( execResult ) { 68 return [ 69 execResult[1], 70 execResult[2] / 100, 71 execResult[3] / 100, 72 execResult[4] 73 ]; 74 } 75 }], 76 77 // jQuery.Color( ) 78 color = jQuery.Color = function( color, green, blue, alpha ) { 79 return new jQuery.Color.fn.parse( color, green, blue, alpha ); 80 }, 81 spaces = { 82 rgba: { 83 cache: "_rgba", 84 props: { 85 red: { 86 idx: 0, 87 type: "byte", 88 empty: true 89 }, 90 green: { 91 idx: 1, 92 type: "byte", 93 empty: true 94 }, 95 blue: { 96 idx: 2, 97 type: "byte", 98 empty: true 99 }, 100 alpha: { 101 idx: 3, 102 type: "percent", 103 def: 1 104 } 105 } 106 }, 107 hsla: { 108 cache: "_hsla", 109 props: { 110 hue: { 111 idx: 0, 112 type: "degrees", 113 empty: true 114 }, 115 saturation: { 116 idx: 1, 117 type: "percent", 118 empty: true 119 }, 120 lightness: { 121 idx: 2, 122 type: "percent", 123 empty: true 124 } 125 } 126 } 127 }, 128 propTypes = { 129 "byte": { 130 floor: true, 131 min: 0, 132 max: 255 133 }, 134 "percent": { 135 min: 0, 136 max: 1 137 }, 138 "degrees": { 139 mod: 360, 140 floor: true 141 } 142 }, 143 rgbaspace = spaces.rgba.props, 144 support = color.support = {}, 145 146 // colors = jQuery.Color.names 147 colors, 148 149 // local aliases of functions called often 150 each = jQuery.each; 151 152 spaces.hsla.props.alpha = rgbaspace.alpha; 153 154 function clamp( value, prop, alwaysAllowEmpty ) { 155 var type = propTypes[ prop.type ] || {}, 156 allowEmpty = prop.empty || alwaysAllowEmpty; 157 158 if ( allowEmpty && value == null ) { 159 return null; 160 } 161 if ( prop.def && value == null ) { 162 return prop.def; 163 } 164 if ( type.floor ) { 165 value = ~~value; 166 } else { 167 value = parseFloat( value ); 168 } 169 if ( value == null || isNaN( value ) ) { 170 return prop.def; 171 } 172 if ( type.mod ) { 173 value = value % type.mod; 174 // -10 -> 350 175 return value < 0 ? type.mod + value : value; 176 } 177 178 // for now all property types without mod have min and max 179 return type.min > value ? type.min : type.max < value ? type.max : value; 180 } 181 182 function stringParse( string ) { 183 var inst = color(), 184 rgba = inst._rgba = []; 185 186 string = string.toLowerCase(); 187 188 each( stringParsers, function( i, parser ) { 189 var match = parser.re.exec( string ), 190 values = match && parser.parse( match ), 191 parsed, 192 spaceName = parser.space || "rgba", 193 cache = spaces[ spaceName ].cache; 194 195 196 if ( values ) { 197 parsed = inst[ spaceName ]( values ); 198 199 // if this was an rgba parse the assignment might happen twice 200 // oh well.... 201 inst[ cache ] = parsed[ cache ]; 202 rgba = inst._rgba = parsed._rgba; 203 204 // exit each( stringParsers ) here because we matched 205 return false; 206 } 207 }); 208 209 // Found a stringParser that handled it 210 if ( rgba.length !== 0 ) { 211 212 // if this came from a parsed string, force "transparent" when alpha is 0 213 // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
214 if ( Math.max.apply( Math, rgba ) === 0 ) { 215 jQuery.extend( rgba, colors.transparent ); 216 } 217 return inst; 218 } 219 220 // named colors / default - filter back through parse function 221 if ( string = colors[ string ] ) { 222 return string; 223 } 224 } 225 226 color.fn = color.prototype = { 227 constructor: color, 228 parse: function( red, green, blue, alpha ) { 229 if ( red === undefined ) { 230 this._rgba = [ null, null, null, null ]; 231 return this; 232 } 233 if ( red instanceof jQuery || red.nodeType ) { 234 red = red instanceof jQuery ? red.css( green ) : jQuery( red ).css( green ); 235 green = undefined; 236 } 237 238 var inst = this, 239 type = jQuery.type( red ), 240 rgba = this._rgba = [], 241 source; 242 243 // more than 1 argument specified - assume ( red, green, blue, alpha ) 244 if ( green !== undefined ) { 245 red = [ red, green, blue, alpha ]; 246 type = "array"; 247 } 248 249 if ( type === "string" ) { 250 return this.parse( stringParse( red ) || colors._default ); 251 } 252 253 if ( type === "array" ) { 254 each( rgbaspace, function( key, prop ) { 255 rgba[ prop.idx ] = clamp( red[ prop.idx ], prop ); 256 }); 257 return this; 258 } 259 260 if ( type === "object" ) { 261 if ( red instanceof color ) { 262 each( spaces, function( spaceName, space ) { 263 if ( red[ space.cache ] ) { 264 inst[ space.cache ] = red[ space.cache ].slice(); 265 } 266 }); 267 } else { 268 each( spaces, function( spaceName, space ) { 269 each( space.props, function( key, prop ) { 270 var cache = space.cache; 271 272 // if the cache doesn't exist, and we know how to convert 273 if ( !inst[ cache ] && space.to ) { 274 275 // if the value was null, we don't need to copy it 276 // if the key was alpha, we don't need to copy it either 277 if ( red[ key ] == null || key === "alpha") { 278 return; 279 } 280 inst[ cache ] = space.to( inst._rgba ); 281 } 282 283 // this is the only case where we allow nulls for ALL properties. 284 // call clamp with alwaysAllowEmpty 285 inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true ); 286 }); 287 }); 288 } 289 return this; 290 } 291 }, 292 is: function( compare ) { 293 var is = color( compare ), 294 same = true, 295 myself = this; 296 297 each( spaces, function( _, space ) { 298 var isCache = is[ space.cache ], 299 localCache; 300 if (isCache) { 301 localCache = myself[ space.cache ] || space.to && space.to( myself._rgba ) || []; 302 each( space.props, function( _, prop ) { 303 if ( isCache[ prop.idx ] != null ) { 304 same = ( isCache[ prop.idx ] == localCache[ prop.idx ] ); 305 return same; 306 } 307 }); 308 } 309 return same; 310 }); 311 return same; 312 }, 313 _space: function() { 314 var used = [], 315 inst = this; 316 each( spaces, function( spaceName, space ) { 317 if ( inst[ space.cache ] ) { 318 used.push( spaceName ); 319 } 320 }); 321 return used.pop(); 322 }, 323 transition: function( other, distance ) { 324 var end = color( other ), 325 spaceName = end._space(), 326 space = spaces[ spaceName ], 327 start = this[ space.cache ] || space.to( this._rgba ), 328 result = start.slice(); 329 330 end = end[ space.cache ]; 331 each( space.props, function( key, prop ) { 332 var index = prop.idx, 333 startValue = start[ index ], 334 endValue = end[ index ], 335 type = propTypes[ prop.type ] || {}; 336 337 // if null, don't override start value 338 if ( endValue === null ) { 339 return; 340 } 341 // if null - use end 342 if ( startValue === null ) { 343 result[ index ] = endValue; 344 } else { 345 if ( type.mod ) { 346 if ( endValue - startValue > type.mod / 2 ) { 347 startValue += type.mod; 348 } else if ( startValue - endValue > type.mod / 2 ) { 349 startValue -= type.mod; 350 } 351 } 352 result[ prop.idx ] = clamp( ( endValue - startValue ) * distance + startValue, prop ); 353 } 354 }); 355 return this[ spaceName ]( result ); 356 }, 357 blend: function( opaque ) { 358 // if we are already opaque - return ourself 359 if ( this._rgba[ 3 ] === 1 ) { 360 return this; 361 } 362 363 var rgb = this._rgba.slice(), 364 a = rgb.pop(), 365 blend = color( opaque )._rgba; 366 367 return color( jQuery.map( rgb, function( v, i ) { 368 return ( 1 - a ) * blend[ i ] + a * v; 369 })); 370 }, 371 toRgbaString: function() { 372 var prefix = "rgba(", 373 rgba = jQuery.map( this._rgba, function( v, i ) { 374 return v == null ? ( i > 2 ? 1 : 0 ) : v; 375 }); 376 377 if ( rgba[ 3 ] === 1 ) { 378 rgba.pop(); 379 prefix = "rgb("; 380 } 381 382 return prefix + rgba.join(",") + ")"; 383 }, 384 toHslaString: function() { 385 var prefix = "hsla(", 386 hsla = jQuery.map( this.hsla(), function( v, i ) { 387 if ( v == null ) { 388 v = i > 2 ? 1 : 0; 389 } 390 391 // catch 1 and 2 392 if ( i && i < 3 ) { 393 v = Math.round( v * 100 ) + "%"; 394 } 395 return v; 396 }); 397 398 if ( hsla[ 3 ] == 1 ) { 399 hsla.pop(); 400 prefix = "hsl("; 401 } 402 return prefix + hsla.join(",") + ")"; 403 }, 404 toHexString: function( includeAlpha ) { 405 var rgba = this._rgba.slice(), 406 alpha = rgba.pop(); 407 408 if ( includeAlpha ) { 409 rgba.push( ~~( alpha * 255 ) ); 410 } 411 412 return "#" + jQuery.map( rgba, function( v, i ) { 413 414 // default to 0 when nulls exist 415 v = ( v || 0 ).toString( 16 ); 416 return v.length == 1 ? "0" + v : v; 417 }).join(""); 418 }, 419 toString: function() { 420 return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString(); 421 } 422 }; 423 color.fn.parse.prototype = color.fn; 424 425 // hsla conversions adapted from:
426 // http://www.google.com/codesearch/p#OAMlx_jo-ck/src/third_party/WebKit/Source/WebCore/inspector/front-end/Color.js&d=7&l=193 427 428 function hue2rgb( p, q, h ) { 429 h = ( h + 1 ) % 1; 430 if ( h * 6 < 1 ) { 431 return p + (q - p) * 6 * h; 432 } 433 if ( h * 2 < 1) { 434 return q; 435 } 436 if ( h * 3 < 2 ) { 437 return p + (q - p) * ((2/3) - h) * 6; 438 } 439 return p; 440 } 441 442 spaces.hsla.to = function ( rgba ) { 443 if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) { 444 return [ null, null, null, rgba[ 3 ] ]; 445 } 446 var r = rgba[ 0 ] / 255, 447 g = rgba[ 1 ] / 255, 448 b = rgba[ 2 ] / 255, 449 a = rgba[ 3 ], 450 max = Math.max( r, g, b ), 451 min = Math.min( r, g, b ), 452 diff = max - min, 453 add = max + min, 454 l = add * 0.5, 455 h, s; 456 457 if ( min === max ) { 458 h = 0; 459 } else if ( r === max ) { 460 h = ( 60 * ( g - b ) / diff ) + 360; 461 } else if ( g === max ) { 462 h = ( 60 * ( b - r ) / diff ) + 120; 463 } else { 464 h = ( 60 * ( r - g ) / diff ) + 240; 465 } 466 467 if ( l === 0 || l === 1 ) { 468 s = l; 469 } else if ( l <= 0.5 ) { 470 s = diff / add; 471 } else { 472 s = diff / ( 2 - add ); 473 } 474 return [ Math.round(h) % 360, s, l, a == null ? 1 : a ]; 475 }; 476 477 spaces.hsla.from = function ( hsla ) { 478 if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) { 479 return [ null, null, null, hsla[ 3 ] ]; 480 } 481 var h = hsla[ 0 ] / 360, 482 s = hsla[ 1 ], 483 l = hsla[ 2 ], 484 a = hsla[ 3 ], 485 q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s, 486 p = 2 * l - q, 487 r, g, b; 488 489 return [ 490 Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ), 491 Math.round( hue2rgb( p, q, h ) * 255 ), 492 Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ), 493 a 494 ]; 495 }; 496 497 498 each( spaces, function( spaceName, space ) { 499 var props = space.props, 500 cache = space.cache, 501 to = space.to, 502 from = space.from; 503 504 // makes rgba() and hsla() 505 color.fn[ spaceName ] = function( value ) { 506 507 // generate a cache for this space if it doesn't exist 508 if ( to && !this[ cache ] ) { 509 this[ cache ] = to( this._rgba ); 510 } 511 if ( value === undefined ) { 512 return this[ cache ].slice(); 513 } 514 515 var type = jQuery.type( value ), 516 arr = ( type === "array" || type === "object" ) ? value : arguments, 517 local = this[ cache ].slice(), 518 ret; 519 520 each( props, function( key, prop ) { 521 var val = arr[ type === "object" ? key : prop.idx ]; 522 if ( val == null ) { 523 val = local[ prop.idx ]; 524 } 525 local[ prop.idx ] = clamp( val, prop ); 526 }); 527 528 if ( from ) { 529 ret = color( from( local ) ); 530 ret[ cache ] = local; 531 return ret; 532 } else { 533 return color( local ); 534 } 535 }; 536 537 // makes red() green() blue() alpha() hue() saturation() lightness() 538 each( props, function( key, prop ) { 539 // alpha is included in more than one space 540 if ( color.fn[ key ] ) { 541 return; 542 } 543 color.fn[ key ] = function( value ) { 544 var vtype = jQuery.type( value ), 545 fn = ( key === 'alpha' ? ( this._hsla ? 'hsla' : 'rgba' ) : spaceName ), 546 local = this[ fn ](), 547 cur = local[ prop.idx ], 548 match; 549 550 if ( vtype === "undefined" ) { 551 return cur; 552 } 553 554 if ( vtype === "function" ) { 555 value = value.call( this, cur ); 556 vtype = jQuery.type( value ); 557 } 558 if ( value == null && prop.empty ) { 559 return this; 560 } 561 if ( vtype === "string" ) { 562 match = rplusequals.exec( value ); 563 if ( match ) { 564 value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 ); 565 } 566 } 567 local[ prop.idx ] = value; 568 return this[ fn ]( local ); 569 }; 570 }); 571 }); 572 573 // add .fx.step functions 574 each( stepHooks, function( i, hook ) { 575 jQuery.cssHooks[ hook ] = { 576 set: function( elem, value ) { 577 var parsed; 578 579 if ( jQuery.type( value ) !== 'string' || ( parsed = stringParse( value ) ) ) 580 { 581 value = color( parsed || value ); 582 if ( !support.rgba && value._rgba[ 3 ] !== 1 ) { 583 var backgroundColor, 584 curElem = hook === "backgroundColor" ? elem.parentNode : elem; 585 do { 586 backgroundColor = jQuery.curCSS( curElem, "backgroundColor" ); 587 } while ( 588 ( backgroundColor === "" || backgroundColor === "transparent" ) && 589 ( curElem = curElem.parentNode ) && 590 curElem.style 591 ); 592 593 value = value.blend( backgroundColor && backgroundColor !== "transparent" ? 594 backgroundColor : 595 "_default" ); 596 } 597 598 value = value.toRgbaString(); 599 } 600 elem.style[ hook ] = value; 601 } 602 }; 603 jQuery.fx.step[ hook ] = function( fx ) { 604 if ( !fx.colorInit ) { 605 fx.start = color( fx.elem, hook ); 606 fx.end = color( fx.end ); 607 fx.colorInit = true; 608 } 609 jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) ); 610 }; 611 }); 612 613 // detect rgba support 614 jQuery(function() { 615 var div = document.createElement( "div" ), 616 div_style = div.style; 617 618 div_style.cssText = "background-color:rgba(1,1,1,.5)"; 619 support.rgba = div_style.backgroundColor.indexOf( "rgba" ) > -1; 620 }); 621 622 // Some named colors to work with 623 // From Interface by Stefan Petre 624 // http://interface.eyecon.ro/ 625 colors = jQuery.Color.names = { 626 aqua: "#00ffff", 627 azure: "#f0ffff", 628 beige: "#f5f5dc", 629 black: "#000000", 630 blue: "#0000ff", 631 brown: "#a52a2a", 632 cyan: "#00ffff", 633 darkblue: "#00008b", 634 darkcyan: "#008b8b", 635 darkgrey: "#a9a9a9", 636 darkgreen: "#006400", 637 darkkhaki: "#bdb76b", 638 darkmagenta: "#8b008b", 639 darkolivegreen: "#556b2f", 640 darkorange: "#ff8c00", 641 darkorchid: "#9932cc", 642 darkred: "#8b0000", 643 darksalmon: "#e9967a", 644 darkviolet: "#9400d3", 645 fuchsia: "#ff00ff", 646 gold: "#ffd700", 647 green: "#008000", 648 indigo: "#4b0082", 649 khaki: "#f0e68c", 650 lightblue: "#add8e6", 651 lightcyan: "#e0ffff", 652 lightgreen: "#90ee90", 653 lightgrey: "#d3d3d3", 654 lightpink: "#ffb6c1", 655 lightyellow: "#ffffe0", 656 lime: "#00ff00", 657 magenta: "#ff00ff", 658 maroon: "#800000", 659 navy: "#000080", 660 olive: "#808000", 661 orange: "#ffa500", 662 pink: "#ffc0cb", 663 purple: "#800080", 664 violet: "#800080", 665 red: "#ff0000", 666 silver: "#c0c0c0", 667 white: "#ffffff", 668 yellow: "#ffff00", 669 transparent: [ null, null, null, 0 ], 670 _default: "#ffffff" 671 }; 672})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.