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