1/*! RESOURCE: /scripts/lib/spectrum.js */ 2(function (factory) { 3 "use strict"; 4if (typeof define === 'function' && define.amd) { 5 define(['jquery'], factory); 6 } 7else if (typeof exports == "object" && typeof module == "object") { 8 module.exports = factory; 9 } 10else { 11 factory(jQuery); 12 } 13})(function($, undefined) { 14 "use strict"; 15 var defaultOpts = { 16 beforeShow: noop, 17 move: noop, 18 change: noop, 19 show: noop, 20 hide: noop, 21 color: false, 22 flat: false, 23 showInput: false, 24 allowEmpty: false, 25 showButtons: true, 26 clickoutFiresChange: false, 27 showInitial: false, 28 showPalette: false, 29 showPaletteOnly: false, 30 hideAfterPaletteSelect: false, 31 togglePaletteOnly: false, 32 showSelectionPalette: true, 33 localStorageKey: false, 34 appendTo: "body", 35 maxSelectionSize: 7, 36 cancelText: "cancel", 37 chooseText: "choose", 38 togglePaletteMoreText: "more", 39 togglePaletteLessText: "less", 40 clearText: "Clear Color Selection", 41 noColorSelectedText: "No Color Selected", 42 preferredFormat: false, 43className: "", 44 containerClassName: "", 45 replacerClassName: "", 46 showAlpha: false, 47 theme: "sp-light", 48 palette: [["#ffffff", "#000000", "#ff0000", "#ff8000", "#ffff00", "#008000", "#0000ff", "#4b0082", "#9400d3"]], 49 selectionPalette: [], 50 disabled: false, 51 offset: null 52 }, 53 spectrums = [], 54IE = !!/msie/i.exec( window.navigator.userAgent ), 55 rgbaSupport = (function() { 56 function contains( str, substr ) { 57 return !!~('' + str).indexOf(substr); 58 } 59 var elem = document.createElement('div'); 60 var style = elem.style; 61 style.cssText = 'background-color:rgba(0,0,0,.5)'; 62 return contains(style.backgroundColor, 'rgba') || contains(style.backgroundColor, 'hsla'); 63 })(), 64 inputTypeColorSupport = (function() { 65var colorInput = $("<input type='color' value='#ffffff' />")[0]; 66 return colorInput.type === "color" && colorInput.value !== "#ffffff"; 67 })(), 68 replaceInput = [ 69 "<div class='sp-replacer'>", 70"<div class='sp-preview'><div class='sp-preview-inner'></div></div>", 71"<div class='sp-dd'>▼</div>", 72"</div>" 73 ].join(''), 74 markup = (function () { 75 var gradientFix = ""; 76 if (IE) { 77 for (var i = 1; i <= 6; i++) { 78gradientFix += "<div class='sp-" + i + "'></div>"; 79 } 80 } 81 return [ 82 "<div class='sp-container sp-hidden'>", 83 "<div class='sp-palette-container'>", 84"<div class='sp-palette sp-thumb sp-cf'></div>", 85 "<div class='sp-palette-button-container sp-cf'>", 86"<button type='button' class='sp-palette-toggle'></button>", 87"</div>", 88"</div>", 89 "<div class='sp-picker-container'>", 90 "<div class='sp-top sp-cf'>", 91"<div class='sp-fill'></div>", 92 "<div class='sp-top-inner'>", 93 "<div class='sp-color'>", 94 "<div class='sp-sat'>", 95 "<div class='sp-val'>", 96"<div class='sp-dragger'></div>", 97"</div>", 98"</div>", 99"</div>", 100 "<div class='sp-clear sp-clear-display'>", 101"</div>", 102 "<div class='sp-hue'>", 103"<div class='sp-slider'></div>", 104 gradientFix, 105"</div>", 106"</div>", 107"<div class='sp-alpha'><div class='sp-alpha-inner'><div class='sp-alpha-handle'></div></div></div>", 108"</div>", 109 "<div class='sp-input-container sp-cf'>", 110"<input class='sp-input' type='text' spellcheck='false' />", 111"</div>", 112"<div class='sp-initial sp-thumb sp-cf'></div>", 113 "<div class='sp-button-container sp-cf'>", 114"<a class='sp-cancel' href='#'></a>", 115"<button type='button' class='sp-choose'></button>", 116"</div>", 117"</div>", 118"</div>" 119 ].join(""); 120 })(); 121 function paletteTemplate (p, color, className, opts) { 122 var html = []; 123 for (var i = 0; i < p.length; i++) { 124 var current = p[i]; 125 if(current) { 126 var tiny = tinycolor(current); 127 var c = tiny.toHsl().l < 0.5 ? "sp-thumb-el sp-thumb-dark" : "sp-thumb-el sp-thumb-light"; 128 c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : ""; 129 var formattedString = tiny.toString(opts.preferredFormat || "rgb"); 130 var swatchStyle = rgbaSupport ? ("background-color:" + tiny.toRgbString()) : "filter:" + tiny.toFilter(); 131html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';" ></span></span>'); 132 } else { 133 var cls = 'sp-clear-display'; 134html.push($('<div />') 135.append($('<span data-color="" style="background-color:transparent;" class="' + cls + '"></span>') 136 .attr('title', opts.noColorSelectedText) 137 ) 138 .html() 139 ); 140 } 141 } 142return "<div class='sp-cf " + className + "'>" + html.join('') + "</div>"; 143 } 144 function hideAll() { 145 for (var i = 0; i < spectrums.length; i++) { 146 if (spectrums[i]) { 147 spectrums[i].hide(); 148 } 149 } 150 } 151 function instanceOptions(o, callbackContext) { 152 var opts = $.extend({}, defaultOpts, o); 153 opts.callbacks = { 154 'move': bind(opts.move, callbackContext), 155 'change': bind(opts.change, callbackContext), 156 'show': bind(opts.show, callbackContext), 157 'hide': bind(opts.hide, callbackContext), 158 'beforeShow': bind(opts.beforeShow, callbackContext) 159 }; 160 return opts; 161 } 162 function spectrum(element, o) { 163 var opts = instanceOptions(o, element), 164 flat = opts.flat, 165 showSelectionPalette = opts.showSelectionPalette, 166 localStorageKey = opts.localStorageKey, 167 theme = opts.theme, 168 callbacks = opts.callbacks, 169 resize = throttle(reflow, 10), 170 visible = false, 171 dragWidth = 0, 172 dragHeight = 0,
vendor: 7,188 bytes, lines 173-329
173 dragHelperHeight = 0, 174 slideHeight = 0, 175 slideWidth = 0, 176 alphaWidth = 0, 177 alphaSlideHelperWidth = 0, 178 slideHelperHeight = 0, 179 currentHue = 0, 180 currentSaturation = 0, 181 currentValue = 0, 182 currentAlpha = 1, 183 palette = [], 184 paletteArray = [], 185 paletteLookup = {}, 186 selectionPalette = opts.selectionPalette.slice(0), 187 maxSelectionSize = opts.maxSelectionSize, 188 draggingClass = "sp-dragging", 189 shiftMovementDirection = null; 190 var doc = element.ownerDocument, 191 body = doc.body, 192 boundElement = $(element), 193 disabled = false, 194 container = $(markup, doc).addClass(theme), 195 pickerContainer = container.find(".sp-picker-container"), 196 dragger = container.find(".sp-color"), 197 dragHelper = container.find(".sp-dragger"), 198 slider = container.find(".sp-hue"), 199 slideHelper = container.find(".sp-slider"), 200 alphaSliderInner = container.find(".sp-alpha-inner"), 201 alphaSlider = container.find(".sp-alpha"), 202 alphaSlideHelper = container.find(".sp-alpha-handle"), 203 textInput = container.find(".sp-input"), 204 paletteContainer = container.find(".sp-palette"), 205 initialColorContainer = container.find(".sp-initial"), 206 cancelButton = container.find(".sp-cancel"), 207 clearButton = container.find(".sp-clear"), 208 chooseButton = container.find(".sp-choose"), 209 toggleButton = container.find(".sp-palette-toggle"), 210 isInput = boundElement.is("input"), 211 isInputTypeColor = isInput && inputTypeColorSupport && boundElement.attr("type") === "color", 212 shouldReplace = isInput && !flat, 213 replacer = (shouldReplace) ? $(replaceInput).addClass(theme).addClass(opts.className).addClass(opts.replacerClassName) : $([]), 214 offsetElement = (shouldReplace) ? replacer : boundElement, 215 previewElement = replacer.find(".sp-preview-inner"), 216 initialColor = opts.color || (isInput && boundElement.val()), 217 colorOnShow = false, 218 preferredFormat = opts.preferredFormat, 219 currentPreferredFormat = preferredFormat, 220 clickoutFiresChange = !opts.showButtons || opts.clickoutFiresChange, 221 isEmpty = !initialColor, 222 allowEmpty = opts.allowEmpty && !isInputTypeColor; 223 function applyOptions() { 224 if (opts.showPaletteOnly) { 225 opts.showPalette = true; 226 } 227 toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText); 228 if (opts.palette) { 229 palette = opts.palette.slice(0); 230 paletteArray = $.isArray(palette[0]) ? palette : [palette]; 231 paletteLookup = {}; 232 for (var i = 0; i < paletteArray.length; i++) { 233 for (var j = 0; j < paletteArray[i].length; j++) { 234 var rgb = tinycolor(paletteArray[i][j]).toRgbString(); 235 paletteLookup[rgb] = true; 236 } 237 } 238 } 239 container.toggleClass("sp-flat", flat); 240 container.toggleClass("sp-input-disabled", !opts.showInput); 241 container.toggleClass("sp-alpha-enabled", opts.showAlpha); 242 container.toggleClass("sp-clear-enabled", allowEmpty); 243 container.toggleClass("sp-buttons-disabled", !opts.showButtons); 244 container.toggleClass("sp-palette-buttons-disabled", !opts.togglePaletteOnly); 245 container.toggleClass("sp-palette-disabled", !opts.showPalette); 246 container.toggleClass("sp-palette-only", opts.showPaletteOnly); 247 container.toggleClass("sp-initial-disabled", !opts.showInitial); 248 container.addClass(opts.className).addClass(opts.containerClassName); 249 reflow(); 250 } 251 function initialize() { 252 if (IE) { 253 container.find("*:not(input)").attr("unselectable", "on"); 254 } 255 applyOptions(); 256 if (shouldReplace) { 257 boundElement.after(replacer).hide(); 258 } 259 if (!allowEmpty) { 260 clearButton.hide(); 261 } 262 if (flat) { 263 boundElement.after(container).hide(); 264 } 265 else { 266 var appendTo = opts.appendTo === "parent" ? boundElement.parent() : $(opts.appendTo); 267 if (appendTo.length !== 1) { 268 appendTo = $("body"); 269 } 270 appendTo.append(container); 271 } 272 updateSelectionPaletteFromStorage(); 273 offsetElement.bind("click.spectrum touchstart.spectrum", function (e) { 274 if (!disabled) { 275 toggle(); 276 } 277 e.stopPropagation(); 278 if (!$(e.target).is("input")) { 279 e.preventDefault(); 280 } 281 }); 282 if(boundElement.is(":disabled") || (opts.disabled === true)) { 283 disable(); 284 } 285 container.click(stopPropagation); 286 textInput.change(setFromTextInput); 287 textInput.bind("paste", function () { 288 setTimeout(setFromTextInput, 1); 289 }); 290 textInput.keydown(function (e) { if (e.keyCode == 13) { setFromTextInput(); } }); 291 cancelButton.text(opts.cancelText); 292 cancelButton.bind("click.spectrum", function (e) { 293 e.stopPropagation(); 294 e.preventDefault(); 295 revert(); 296 hide(); 297 }); 298 clearButton.attr("title", opts.clearText); 299 clearButton.bind("click.spectrum", function (e) { 300 e.stopPropagation(); 301 e.preventDefault(); 302 isEmpty = true; 303 move(); 304 if(flat) { 305 updateOriginalInput(true); 306 } 307 }); 308 chooseButton.text(opts.chooseText); 309 chooseButton.bind("click.spectrum", function (e) { 310 e.stopPropagation(); 311 e.preventDefault(); 312 if (isValid()) { 313 updateOriginalInput(true); 314 hide(); 315 } 316 }); 317 toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText); 318 toggleButton.bind("click.spectrum", function (e) { 319 e.stopPropagation(); 320 e.preventDefault(); 321 opts.showPaletteOnly = !opts.showPaletteOnly; 322 if (!opts.showPaletteOnly && !flat) { 323 container.css('left', '-=' + (pickerContainer.outerWidth(true) + 5)); 324 } 325 applyOptions(); 326 }); 327 draggable(alphaSlider, function (dragX, dragY, e) { 328currentAlpha = (dragX / alphaWidth); 329 isEmpty = false;
330 if (e.shiftKey) { 331currentAlpha = Math.round(currentAlpha * 10) / 10; 332 } 333 move(); 334 }, dragStart, dragStop); 335 draggable(slider, function (dragX, dragY) { 336currentHue = parseFloat(dragY / slideHeight); 337 isEmpty = false; 338 if (!opts.showAlpha) { 339 currentAlpha = 1; 340 } 341 move(); 342 }, dragStart, dragStop); 343 draggable(dragger, function (dragX, dragY, e) { 344 if (!e.shiftKey) { 345 shiftMovementDirection = null; 346 } 347 else if (!shiftMovementDirection) { 348 var oldDragX = currentSaturation * dragWidth; 349 var oldDragY = dragHeight - (currentValue * dragHeight); 350 var furtherFromX = Math.abs(dragX - oldDragX) > Math.abs(dragY - oldDragY); 351 shiftMovementDirection = furtherFromX ? "x" : "y"; 352 } 353 var setSaturation = !shiftMovementDirection || shiftMovementDirection === "x"; 354 var setValue = !shiftMovementDirection || shiftMovementDirection === "y"; 355 if (setSaturation) { 356currentSaturation = parseFloat(dragX / dragWidth); 357 } 358 if (setValue) { 359currentValue = parseFloat((dragHeight - dragY) / dragHeight); 360 } 361 isEmpty = false; 362 if (!opts.showAlpha) { 363 currentAlpha = 1; 364 } 365 move(); 366 }, dragStart, dragStop); 367 if (!!initialColor) { 368 set(initialColor); 369 updateUI(); 370 currentPreferredFormat = preferredFormat || tinycolor(initialColor).format; 371 addColorToSelectionPalette(initialColor); 372 } 373 else { 374 updateUI(); 375 } 376 if (flat) { 377 show(); 378 } 379 function paletteElementClick(e) { 380 if (e.data && e.data.ignore) { 381 set($(e.target).closest(".sp-thumb-el").data("color")); 382 move(); 383 } 384 else { 385 set($(e.target).closest(".sp-thumb-el").data("color")); 386 move(); 387 updateOriginalInput(true); 388 if (opts.hideAfterPaletteSelect) { 389 hide(); 390 } 391 } 392 return false; 393 } 394 var paletteEvent = IE ? "mousedown.spectrum" : "click.spectrum touchstart.spectrum"; 395 paletteContainer.delegate(".sp-thumb-el", paletteEvent, paletteElementClick); 396 initialColorContainer.delegate(".sp-thumb-el:nth-child(1)", paletteEvent, { ignore: true }, paletteElementClick); 397 } 398 function updateSelectionPaletteFromStorage() { 399 if (localStorageKey && window.localStorage) { 400 try { 401 var oldPalette = window.localStorage[localStorageKey].split(",#"); 402 if (oldPalette.length > 1) { 403 delete window.localStorage[localStorageKey]; 404 $.each(oldPalette, function(i, c) { 405 addColorToSelectionPalette(c); 406 }); 407 } 408 } 409 catch(e) { } 410 try { 411 selectionPalette = window.localStorage[localStorageKey].split(";"); 412 } 413 catch (e) { } 414 } 415 } 416 function addColorToSelectionPalette(color) { 417 if (showSelectionPalette) { 418 var rgb = tinycolor(color).toRgbString(); 419 if (!paletteLookup[rgb] && $.inArray(rgb, selectionPalette) === -1) { 420 selectionPalette.push(rgb); 421 while(selectionPalette.length > maxSelectionSize) { 422 selectionPalette.shift(); 423 } 424 } 425 if (localStorageKey && window.localStorage) { 426 try { 427 window.localStorage[localStorageKey] = selectionPalette.join(";"); 428 } 429 catch(e) { } 430 } 431 } 432 } 433 function getUniqueSelectionPalette() { 434 var unique = []; 435 if (opts.showPalette) { 436 for (var i = 0; i < selectionPalette.length; i++) { 437 var rgb = tinycolor(selectionPalette[i]).toRgbString(); 438 if (!paletteLookup[rgb]) { 439 unique.push(selectionPalette[i]); 440 } 441 } 442 } 443 return unique.reverse().slice(0, opts.maxSelectionSize); 444 } 445 function drawPalette() { 446 var currentColor = get(); 447 var html = $.map(paletteArray, function (palette, i) { 448 return paletteTemplate(palette, currentColor, "sp-palette-row sp-palette-row-" + i, opts); 449 }); 450 updateSelectionPaletteFromStorage(); 451 if (selectionPalette) { 452 html.push(paletteTemplate(getUniqueSelectionPalette(), currentColor, "sp-palette-row sp-palette-row-selection", opts)); 453 } 454 paletteContainer.html(html.join("")); 455 } 456 function drawInitial() { 457 if (opts.showInitial) { 458 var initial = colorOnShow; 459 var current = get(); 460 initialColorContainer.html(paletteTemplate([initial, current], current, "sp-palette-row-initial", opts)); 461 } 462 } 463 function dragStart() { 464 if (dragHeight <= 0 || dragWidth <= 0 || slideHeight <= 0) { 465 reflow(); 466 } 467 container.addClass(draggingClass); 468 shiftMovementDirection = null; 469 boundElement.trigger('dragstart.spectrum', [ get() ]); 470 } 471 function dragStop() { 472 container.removeClass(draggingClass); 473 boundElement.trigger('dragstop.spectrum', [ get() ]); 474 } 475 function setFromTextInput() { 476 var value = textInput.val(); 477 if ((value === null || value === "") && allowEmpty) { 478 set(null); 479 updateOriginalInput(true); 480 } 481 else { 482 var tiny = tinycolor(value); 483 if (tiny.isValid()) { 484 set(tiny); 485 updateOriginalInput(true); 486 } 487 else { 488 textInput.addClass("sp-validation-error"); 489 } 490 } 491 }
vendor: 6,310 bytes, lines 492-656
492 function toggle() { 493 if (visible) { 494 hide(); 495 } 496 else { 497 show(); 498 } 499 } 500 function show() { 501 var event = $.Event('beforeShow.spectrum'); 502 if (visible) { 503 reflow(); 504 return; 505 } 506 boundElement.trigger(event, [ get() ]); 507 if (callbacks.beforeShow(get()) === false || event.isDefaultPrevented()) { 508 return; 509 } 510 hideAll(); 511 visible = true; 512 $(doc).bind("click.spectrum", clickout); 513 $(window).bind("resize.spectrum", resize); 514 replacer.addClass("sp-active"); 515 container.removeClass("sp-hidden"); 516 reflow(); 517 updateUI(); 518 colorOnShow = get(); 519 drawInitial(); 520 callbacks.show(colorOnShow); 521 boundElement.trigger('show.spectrum', [ colorOnShow ]); 522 } 523 function clickout(e) { 524 if (e.button == 2) { return; } 525 if (clickoutFiresChange) { 526 updateOriginalInput(true); 527 } 528 else { 529 revert(); 530 } 531 hide(); 532 } 533 function hide() { 534 if (!visible || flat) { return; } 535 visible = false; 536 $(doc).unbind("click.spectrum", clickout); 537 $(window).unbind("resize.spectrum", resize); 538 replacer.removeClass("sp-active"); 539 container.addClass("sp-hidden"); 540 callbacks.hide(get()); 541 boundElement.trigger('hide.spectrum', [ get() ]); 542 } 543 function revert() { 544 set(colorOnShow, true); 545 } 546 function set(color, ignoreFormatChange) { 547 if (tinycolor.equals(color, get())) { 548 updateUI(); 549 return; 550 } 551 var newColor, newHsv; 552 if (!color && allowEmpty) { 553 isEmpty = true; 554 } else { 555 isEmpty = false; 556 newColor = tinycolor(color); 557 newHsv = newColor.toHsv(); 558currentHue = (newHsv.h % 360) / 360; 559 currentSaturation = newHsv.s; 560 currentValue = newHsv.v; 561 currentAlpha = newHsv.a; 562 } 563 updateUI(); 564 if (newColor && newColor.isValid() && !ignoreFormatChange) { 565 currentPreferredFormat = preferredFormat || newColor.getFormat(); 566 } 567 } 568 function get(opts) { 569 opts = opts || { }; 570 if (allowEmpty && isEmpty) { 571 return null; 572 } 573 return tinycolor.fromRatio({ 574 h: currentHue, 575 s: currentSaturation, 576 v: currentValue, 577a: Math.round(currentAlpha * 100) / 100 578 }, { format: opts.format || currentPreferredFormat }); 579 } 580 function isValid() { 581 return !textInput.hasClass("sp-validation-error"); 582 } 583 function move() { 584 updateUI(); 585 callbacks.move(get()); 586 boundElement.trigger('move.spectrum', [ get() ]); 587 } 588 function updateUI() { 589 textInput.removeClass("sp-validation-error"); 590 updateHelperLocations(); 591 var flatColor = tinycolor.fromRatio({ h: currentHue, s: 1, v: 1 }); 592 dragger.css("background-color", flatColor.toHexString()); 593 var format = currentPreferredFormat; 594 if (currentAlpha < 1 && !(currentAlpha === 0 && format === "name")) { 595 if (format === "hex" || format === "hex3" || format === "hex6" || format === "name") { 596 format = "rgb"; 597 } 598 } 599 var realColor = get({ format: format }), 600 displayColor = ''; 601 previewElement.removeClass("sp-clear-display"); 602 previewElement.css('background-color', 'transparent'); 603 if (!realColor && allowEmpty) { 604 previewElement.addClass("sp-clear-display"); 605 } 606 else { 607 var realHex = realColor.toHexString(), 608 realRgb = realColor.toRgbString(); 609 if (rgbaSupport || realColor.alpha === 1) { 610 previewElement.css("background-color", realRgb); 611 } 612 else { 613 previewElement.css("background-color", "transparent"); 614 previewElement.css("filter", realColor.toFilter()); 615 } 616 if (opts.showAlpha) { 617 var rgb = realColor.toRgb(); 618 rgb.a = 0; 619 var realAlpha = tinycolor(rgb).toRgbString(); 620 var gradient = "linear-gradient(left, " + realAlpha + ", " + realHex + ")"; 621 if (IE) { 622 alphaSliderInner.css("filter", tinycolor(realAlpha).toFilter({ gradientType: 1 }, realHex)); 623 } 624 else { 625 alphaSliderInner.css("background", "-webkit-" + gradient); 626 alphaSliderInner.css("background", "-moz-" + gradient); 627 alphaSliderInner.css("background", "-ms-" + gradient); 628 alphaSliderInner.css("background", 629 "linear-gradient(to right, " + realAlpha + ", " + realHex + ")"); 630 } 631 } 632 displayColor = realColor.toString(format); 633 } 634 if (opts.showInput) { 635 textInput.val(displayColor); 636 } 637 if (opts.showPalette) { 638 drawPalette(); 639 } 640 drawInitial(); 641 } 642 function updateHelperLocations() { 643 var s = currentSaturation; 644 var v = currentValue; 645 if(allowEmpty && isEmpty) { 646 alphaSlideHelper.hide(); 647 slideHelper.hide(); 648 dragHelper.hide(); 649 } 650 else { 651 alphaSlideHelper.show(); 652 slideHelper.show(); 653 dragHelper.show(); 654 var dragX = s * dragWidth; 655 var dragY = dragHeight - (v * dragHeight); 656 dragX = Math.max(
657 -dragHelperHeight, 658 Math.min(dragWidth - dragHelperHeight, dragX - dragHelperHeight) 659 ); 660 dragY = Math.max( 661 -dragHelperHeight, 662 Math.min(dragHeight - dragHelperHeight, dragY - dragHelperHeight) 663 ); 664 dragHelper.css({ 665 "top": dragY + "px", 666 "left": dragX + "px" 667 }); 668 var alphaX = currentAlpha * alphaWidth; 669 alphaSlideHelper.css({ 670"left": (alphaX - (alphaSlideHelperWidth / 2)) + "px" 671 }); 672 var slideY = (currentHue) * slideHeight; 673 slideHelper.css({ 674 "top": (slideY - slideHelperHeight) + "px" 675 }); 676 } 677 } 678 function updateOriginalInput(fireCallback) { 679 var color = get(), 680 displayColor = '', 681 hasChanged = !tinycolor.equals(color, colorOnShow); 682 if (color) { 683 displayColor = color.toString(currentPreferredFormat); 684 addColorToSelectionPalette(color); 685 } 686 if (isInput) { 687 boundElement.val(displayColor); 688 } 689 if (fireCallback && hasChanged) { 690 callbacks.change(color); 691 boundElement.trigger('change', [ color ]); 692 } 693 } 694 function reflow() { 695 dragWidth = dragger.width(); 696 dragHeight = dragger.height(); 697 dragHelperHeight = dragHelper.height(); 698 slideWidth = slider.width(); 699 slideHeight = slider.height(); 700 slideHelperHeight = slideHelper.height(); 701 alphaWidth = alphaSlider.width(); 702 alphaSlideHelperWidth = alphaSlideHelper.width(); 703 if (!flat) { 704 container.css("position", "absolute"); 705 if (opts.offset) { 706 container.offset(opts.offset); 707 } else { 708 container.offset(getOffset(container, offsetElement)); 709 } 710 } 711 updateHelperLocations(); 712 if (opts.showPalette) { 713 drawPalette(); 714 } 715 boundElement.trigger('reflow.spectrum'); 716 } 717 function destroy() { 718 boundElement.show(); 719 offsetElement.unbind("click.spectrum touchstart.spectrum"); 720 container.remove(); 721 replacer.remove(); 722 spectrums[spect.id] = null; 723 } 724 function option(optionName, optionValue) { 725 if (optionName === undefined) { 726 return $.extend({}, opts); 727 } 728 if (optionValue === undefined) { 729 return opts[optionName]; 730 } 731 opts[optionName] = optionValue; 732 applyOptions(); 733 } 734 function enable() { 735 disabled = false; 736 boundElement.attr("disabled", false); 737 offsetElement.removeClass("sp-disabled"); 738 } 739 function disable() { 740 hide(); 741 disabled = true; 742 boundElement.attr("disabled", true); 743 offsetElement.addClass("sp-disabled"); 744 } 745 function setOffset(coord) { 746 opts.offset = coord; 747 reflow(); 748 } 749 initialize(); 750 var spect = { 751 show: show, 752 hide: hide, 753 toggle: toggle, 754 reflow: reflow, 755 option: option, 756 enable: enable, 757 disable: disable, 758 offset: setOffset, 759 set: function (c) { 760 set(c); 761 updateOriginalInput(); 762 }, 763 get: get, 764 destroy: destroy, 765 container: container 766 }; 767 spect.id = spectrums.push(spect) - 1; 768 return spect; 769 } 770 function getOffset(picker, input) { 771 var extraY = 0; 772 var dpWidth = picker.outerWidth(); 773 var dpHeight = picker.outerHeight(); 774 var inputHeight = input.outerHeight(); 775 var doc = picker[0].ownerDocument; 776 var docElem = doc.documentElement; 777 var viewWidth = docElem.clientWidth + $(doc).scrollLeft(); 778 var viewHeight = docElem.clientHeight + $(doc).scrollTop(); 779 var offset = input.offset(); 780 offset.top += inputHeight; 781 offset.left -= 782 Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? 783 Math.abs(offset.left + dpWidth - viewWidth) : 0); 784 offset.top -= 785 Math.min(offset.top, ((offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? 786 Math.abs(dpHeight + inputHeight - extraY) : extraY)); 787 return offset; 788 } 789 function noop() { 790 } 791 function stopPropagation(e) { 792 e.stopPropagation(); 793 } 794 function bind(func, obj) { 795 var slice = Array.prototype.slice; 796 var args = slice.call(arguments, 2); 797 return function () { 798 return func.apply(obj, args.concat(slice.call(arguments))); 799 }; 800 } 801 function draggable(element, onmove, onstart, onstop) { 802 onmove = onmove || function () { }; 803 onstart = onstart || function () { }; 804 onstop = onstop || function () { }; 805 var doc = document; 806 var dragging = false;
807 var offset = {}; 808 var maxHeight = 0; 809 var maxWidth = 0; 810 var hasTouch = ('ontouchstart' in window); 811 var duringDragEvents = {}; 812 duringDragEvents["selectstart"] = prevent; 813 duringDragEvents["dragstart"] = prevent; 814 duringDragEvents["touchmove mousemove"] = move; 815 duringDragEvents["touchend mouseup"] = stop; 816 function prevent(e) { 817 if (e.stopPropagation) { 818 e.stopPropagation(); 819 } 820 if (e.preventDefault) { 821 e.preventDefault(); 822 } 823 e.returnValue = false; 824 } 825 function move(e) { 826 if (dragging) { 827 if (IE && doc.documentMode < 9 && !e.button) { 828 return stop(); 829 } 830 var touches = e.originalEvent && e.originalEvent.touches; 831 var pageX = touches ? touches[0].pageX : e.pageX; 832 var pageY = touches ? touches[0].pageY : e.pageY; 833 var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth)); 834 var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight)); 835 if (hasTouch) { 836 prevent(e); 837 } 838 onmove.apply(element, [dragX, dragY, e]); 839 } 840 } 841 function start(e) { 842 var rightclick = (e.which) ? (e.which == 3) : (e.button == 2); 843 if (!rightclick && !dragging) { 844 if (onstart.apply(element, arguments) !== false) { 845 dragging = true; 846 maxHeight = $(element).height(); 847 maxWidth = $(element).width(); 848 offset = $(element).offset(); 849 $(doc).bind(duringDragEvents); 850 $(doc.body).addClass("sp-dragging"); 851 if (!hasTouch) { 852 move(e); 853 } 854 prevent(e); 855 } 856 } 857 } 858 function stop() { 859 if (dragging) { 860 $(doc).unbind(duringDragEvents); 861 $(doc.body).removeClass("sp-dragging"); 862 onstop.apply(element, arguments); 863 } 864 dragging = false; 865 } 866 $(element).bind("touchstart mousedown", start); 867 } 868 function throttle(func, wait, debounce) { 869 var timeout; 870 return function () { 871 var context = this, args = arguments; 872 var throttler = function () { 873 timeout = null; 874 func.apply(context, args); 875 }; 876 if (debounce) clearTimeout(timeout); 877 if (debounce || !timeout) timeout = setTimeout(throttler, wait); 878 }; 879 } 880 var dataID = "spectrum.id"; 881 $.fn.spectrum = function (opts, extra) { 882 if (typeof opts == "string") { 883 var returnValue = this; 884 var args = Array.prototype.slice.call( arguments, 1 ); 885 this.each(function () { 886 var spect = spectrums[$(this).data(dataID)]; 887 if (spect) { 888 var method = spect[opts]; 889 if (!method) { 890 throw new Error( "Spectrum: no such method: '" + opts + "'" ); 891 } 892 if (opts == "get") { 893 returnValue = spect.get(); 894 } 895 else if (opts == "container") { 896 returnValue = spect.container; 897 } 898 else if (opts == "option") { 899 returnValue = spect.option.apply(spect, args); 900 } 901 else if (opts == "destroy") { 902 spect.destroy(); 903 $(this).removeData(dataID); 904 } 905 else { 906 method.apply(spect, args); 907 } 908 } 909 }); 910 return returnValue; 911 } 912 return this.spectrum("destroy").each(function () { 913 var options = $.extend({}, opts, $(this).data()); 914 var spect = spectrum(this, options); 915 $(this).data(dataID, spect.id); 916 }); 917 }; 918 $.fn.spectrum.load = true; 919 $.fn.spectrum.loadOpts = {}; 920 $.fn.spectrum.draggable = draggable; 921 $.fn.spectrum.defaults = defaultOpts; 922 $.spectrum = { }; 923 $.spectrum.localization = { }; 924 $.spectrum.palettes = { }; 925 $.fn.spectrum.processNativeColorInputs = function () { 926 if (!inputTypeColorSupport) { 927 $("input[type=color]").spectrum({ 928 preferredFormat: "hex6" 929 }); 930 } 931 }; 932 (function() { 933var trimLeft = /^[\s,#]+/, 934trimRight = /\s+$/, 935 tinyCounter = 0, 936 math = Math, 937 mathRound = math.round, 938 mathMin = math.min, 939 mathMax = math.max, 940 mathRandom = math.random; 941 var tinycolor = function tinycolor (color, opts) {
vendor: 29,340 bytes, lines 942-1783
942 color = (color) ? color : ''; 943 opts = opts || { }; 944 if (color instanceof tinycolor) { 945 return color; 946 } 947 if (!(this instanceof tinycolor)) { 948 return new tinycolor(color, opts); 949 } 950 var rgb = inputToRGB(color); 951 this._originalInput = color, 952 this._r = rgb.r, 953 this._g = rgb.g, 954 this._b = rgb.b, 955 this._a = rgb.a, 956this._roundA = mathRound(100*this._a) / 100, 957 this._format = opts.format || rgb.format; 958 this._gradientType = opts.gradientType; 959 if (this._r < 1) { this._r = mathRound(this._r); } 960 if (this._g < 1) { this._g = mathRound(this._g); } 961 if (this._b < 1) { this._b = mathRound(this._b); } 962 this._ok = rgb.ok; 963 this._tc_id = tinyCounter++; 964 }; 965 tinycolor.prototype = { 966 isDark: function() { 967 return this.getBrightness() < 128; 968 }, 969 isLight: function() { 970 return !this.isDark(); 971 }, 972 isValid: function() { 973 return this._ok; 974 }, 975 getOriginalInput: function() { 976 return this._originalInput; 977 }, 978 getFormat: function() { 979 return this._format; 980 }, 981 getAlpha: function() { 982 return this._a; 983 }, 984 getBrightness: function() { 985 var rgb = this.toRgb(); 986return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; 987 }, 988 setAlpha: function(value) { 989 this._a = boundAlpha(value); 990this._roundA = mathRound(100*this._a) / 100; 991 return this; 992 }, 993 toHsv: function() { 994 var hsv = rgbToHsv(this._r, this._g, this._b); 995 return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a }; 996 }, 997 toHsvString: function() { 998 var hsv = rgbToHsv(this._r, this._g, this._b); 999 var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100); 1000 return (this._a == 1) ? 1001 "hsv(" + h + ", " + s + "%, " + v + "%)" : 1002 "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")"; 1003 }, 1004 toHsl: function() { 1005 var hsl = rgbToHsl(this._r, this._g, this._b); 1006 return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a }; 1007 }, 1008 toHslString: function() { 1009 var hsl = rgbToHsl(this._r, this._g, this._b); 1010 var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100); 1011 return (this._a == 1) ? 1012 "hsl(" + h + ", " + s + "%, " + l + "%)" : 1013 "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")"; 1014 }, 1015 toHex: function(allow3Char) { 1016 return rgbToHex(this._r, this._g, this._b, allow3Char); 1017 }, 1018 toHexString: function(allow3Char) { 1019 return '#' + this.toHex(allow3Char); 1020 }, 1021 toHex8: function() { 1022 return rgbaToHex(this._r, this._g, this._b, this._a); 1023 }, 1024 toHex8String: function() { 1025 return '#' + this.toHex8(); 1026 }, 1027 toRgb: function() { 1028 return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a }; 1029 }, 1030 toRgbString: function() { 1031 return (this._a == 1) ? 1032 "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" : 1033 "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")"; 1034 }, 1035 toPercentageRgb: function() { 1036 return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a }; 1037 }, 1038 toPercentageRgbString: function() { 1039 return (this._a == 1) ? 1040 "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" : 1041 "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")"; 1042 }, 1043 toName: function() { 1044 if (this._a === 0) { 1045 return "transparent"; 1046 } 1047 if (this._a < 1) { 1048 return false; 1049 } 1050 return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false; 1051 }, 1052 toFilter: function(secondColor) { 1053 var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a); 1054 var secondHex8String = hex8String; 1055 var gradientType = this._gradientType ? "GradientType = 1, " : ""; 1056 if (secondColor) { 1057 var s = tinycolor(secondColor); 1058 secondHex8String = s.toHex8String(); 1059 } 1060 return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")"; 1061 }, 1062 toString: function(format) { 1063 var formatSet = !!format; 1064 format = format || this._format; 1065 var formattedString = false; 1066 var hasAlpha = this._a < 1 && this._a >= 0; 1067 var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "name"); 1068 if (needsAlphaFormat) { 1069 if (format === "name" && this._a === 0) { 1070 return this.toName(); 1071 } 1072 return this.toRgbString(); 1073 } 1074 if (format === "rgb") { 1075 formattedString = this.toRgbString(); 1076 } 1077 if (format === "prgb") { 1078 formattedString = this.toPercentageRgbString(); 1079 } 1080 if (format === "hex" || format === "hex6") { 1081 formattedString = this.toHexString(); 1082 } 1083 if (format === "hex3") { 1084 formattedString = this.toHexString(true); 1085 } 1086 if (format === "hex8") { 1087 formattedString = this.toHex8String(); 1088 } 1089 if (format === "name") { 1090 formattedString = this.toName(); 1091 } 1092 if (format === "hsl") { 1093 formattedString = this.toHslString(); 1094 } 1095 if (format === "hsv") { 1096 formattedString = this.toHsvString(); 1097 } 1098 return formattedString || this.toHexString(); 1099 }, 1100 _applyModification: function(fn, args) { 1101 var color = fn.apply(null, [this].concat([].slice.call(args))); 1102 this._r = color._r; 1103 this._g = color._g; 1104 this._b = color._b; 1105 this.setAlpha(color._a); 1106 return this; 1107 }, 1108 lighten: function() { 1109 return this._applyModification(lighten, arguments); 1110 }, 1111 brighten: function() { 1112 return this._applyModification(brighten, arguments); 1113 }, 1114 darken: function() { 1115 return this._applyModification(darken, arguments); 1116 }, 1117 desaturate: function() { 1118 return this._applyModification(desaturate, arguments); 1119 }, 1120 saturate: function() { 1121 return this._applyModification(saturate, arguments); 1122 }, 1123 greyscale: function() { 1124 return this._applyModification(greyscale, arguments); 1125 }, 1126 spin: function() { 1127 return this._applyModification(spin, arguments); 1128 }, 1129 _applyCombination: function(fn, args) { 1130 return fn.apply(null, [this].concat([].slice.call(args))); 1131 }, 1132 analogous: function() { 1133 return this._applyCombination(analogous, arguments); 1134 }, 1135 complement: function() { 1136 return this._applyCombination(complement, arguments); 1137 }, 1138 monochromatic: function() { 1139 return this._applyCombination(monochromatic, arguments); 1140 }, 1141 splitcomplement: function() { 1142 return this._applyCombination(splitcomplement, arguments); 1143 }, 1144 triad: function() { 1145 return this._applyCombination(triad, arguments); 1146 }, 1147 tetrad: function() { 1148 return this._applyCombination(tetrad, arguments); 1149 } 1150 }; 1151 tinycolor.fromRatio = function(color, opts) { 1152 if (typeof color == "object") { 1153 var newColor = {}; 1154 for (var i in color) { 1155 if (color.hasOwnProperty(i)) { 1156 if (i === "a") { 1157 newColor[i] = color[i]; 1158 } 1159 else { 1160 newColor[i] = convertToPercentage(color[i]); 1161 } 1162 } 1163 } 1164 color = newColor; 1165 } 1166 return tinycolor(color, opts); 1167 }; 1168 function inputToRGB(color) { 1169 var rgb = { r: 0, g: 0, b: 0 }; 1170 var a = 1; 1171 var ok = false; 1172 var format = false; 1173 if (typeof color == "string") { 1174 color = stringInputToObject(color); 1175 } 1176 if (typeof color == "object") { 1177 if (color.hasOwnProperty("r") && color.hasOwnProperty("g") && color.hasOwnProperty("b")) { 1178 rgb = rgbToRgb(color.r, color.g, color.b); 1179 ok = true; 1180 format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb"; 1181 } 1182 else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("v")) { 1183 color.s = convertToPercentage(color.s); 1184 color.v = convertToPercentage(color.v); 1185 rgb = hsvToRgb(color.h, color.s, color.v); 1186 ok = true; 1187 format = "hsv"; 1188 } 1189 else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("l")) { 1190 color.s = convertToPercentage(color.s); 1191 color.l = convertToPercentage(color.l); 1192 rgb = hslToRgb(color.h, color.s, color.l); 1193 ok = true; 1194 format = "hsl"; 1195 } 1196 if (color.hasOwnProperty("a")) { 1197 a = color.a; 1198 } 1199 } 1200 a = boundAlpha(a); 1201 return { 1202 ok: ok, 1203 format: color.format || format, 1204 r: mathMin(255, mathMax(rgb.r, 0)), 1205 g: mathMin(255, mathMax(rgb.g, 0)), 1206 b: mathMin(255, mathMax(rgb.b, 0)), 1207 a: a 1208 }; 1209 } 1210 function rgbToRgb(r, g, b){ 1211 return { 1212 r: bound01(r, 255) * 255, 1213 g: bound01(g, 255) * 255, 1214 b: bound01(b, 255) * 255 1215 }; 1216 } 1217 function rgbToHsl(r, g, b) { 1218 r = bound01(r, 255); 1219 g = bound01(g, 255); 1220 b = bound01(b, 255); 1221 var max = mathMax(r, g, b), min = mathMin(r, g, b); 1222var h, s, l = (max + min) / 2; 1223 if(max == min) { 1224h = s = 0; 1225 } 1226 else { 1227 var d = max - min; 1228s = l > 0.5 ? d / (2 - max - min) : d / (max + min); 1229 switch(max) { 1230case r: h = (g - b) / d + (g < b ? 6 : 0); break; 1231case g: h = (b - r) / d + 2; break; 1232case b: h = (r - g) / d + 4; break; 1233 } 1234h /= 6; 1235 } 1236 return { h: h, s: s, l: l }; 1237 } 1238 function hslToRgb(h, s, l) { 1239 var r, g, b; 1240 h = bound01(h, 360); 1241 s = bound01(s, 100); 1242 l = bound01(l, 100); 1243 function hue2rgb(p, q, t) { 1244 if(t < 0) t += 1; 1245 if(t > 1) t -= 1; 1246if(t < 1/6) return p + (q - p) * 6 * t; 1247if(t < 1/2) return q; 1248if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; 1249 return p; 1250 } 1251 if(s === 0) { 1252r = g = b = l; 1253 } 1254 else { 1255 var q = l < 0.5 ? l * (1 + s) : l + s - l * s; 1256 var p = 2 * l - q; 1257r = hue2rgb(p, q, h + 1/3); 1258 g = hue2rgb(p, q, h); 1259b = hue2rgb(p, q, h - 1/3); 1260 } 1261 return { r: r * 255, g: g * 255, b: b * 255 }; 1262 } 1263 function rgbToHsv(r, g, b) { 1264 r = bound01(r, 255); 1265 g = bound01(g, 255); 1266 b = bound01(b, 255); 1267 var max = mathMax(r, g, b), min = mathMin(r, g, b); 1268 var h, s, v = max; 1269 var d = max - min; 1270s = max === 0 ? 0 : d / max; 1271 if(max == min) { 1272h = 0; 1273 } 1274 else { 1275 switch(max) { 1276case r: h = (g - b) / d + (g < b ? 6 : 0); break; 1277case g: h = (b - r) / d + 2; break; 1278case b: h = (r - g) / d + 4; break; 1279 } 1280h /= 6; 1281 } 1282 return { h: h, s: s, v: v }; 1283 } 1284 function hsvToRgb(h, s, v) { 1285 h = bound01(h, 360) * 6; 1286 s = bound01(s, 100); 1287 v = bound01(v, 100); 1288 var i = math.floor(h), 1289 f = h - i, 1290 p = v * (1 - s), 1291 q = v * (1 - f * s), 1292 t = v * (1 - (1 - f) * s), 1293 mod = i % 6, 1294 r = [v, q, p, p, t, v][mod], 1295 g = [t, v, v, q, p, p][mod], 1296 b = [p, p, t, v, v, q][mod]; 1297 return { r: r * 255, g: g * 255, b: b * 255 }; 1298 } 1299 function rgbToHex(r, g, b, allow3Char) { 1300 var hex = [ 1301 pad2(mathRound(r).toString(16)), 1302 pad2(mathRound(g).toString(16)), 1303 pad2(mathRound(b).toString(16)) 1304 ]; 1305 if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) { 1306 return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0); 1307 } 1308 return hex.join(""); 1309 } 1310 function rgbaToHex(r, g, b, a) { 1311 var hex = [ 1312 pad2(convertDecimalToHex(a)), 1313 pad2(mathRound(r).toString(16)), 1314 pad2(mathRound(g).toString(16)), 1315 pad2(mathRound(b).toString(16)) 1316 ]; 1317 return hex.join(""); 1318 } 1319 tinycolor.equals = function (color1, color2) { 1320 if (!color1 || !color2) { return false; } 1321 return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString(); 1322 }; 1323 tinycolor.random = function() { 1324 return tinycolor.fromRatio({ 1325 r: mathRandom(), 1326 g: mathRandom(), 1327 b: mathRandom() 1328 }); 1329 }; 1330 function desaturate(color, amount) { 1331 amount = (amount === 0) ? 0 : (amount || 10); 1332 var hsl = tinycolor(color).toHsl(); 1333hsl.s -= amount / 100; 1334 hsl.s = clamp01(hsl.s); 1335 return tinycolor(hsl); 1336 } 1337 function saturate(color, amount) { 1338 amount = (amount === 0) ? 0 : (amount || 10); 1339 var hsl = tinycolor(color).toHsl(); 1340hsl.s += amount / 100; 1341 hsl.s = clamp01(hsl.s); 1342 return tinycolor(hsl); 1343 } 1344 function greyscale(color) { 1345 return tinycolor(color).desaturate(100); 1346 } 1347 function lighten (color, amount) { 1348 amount = (amount === 0) ? 0 : (amount || 10); 1349 var hsl = tinycolor(color).toHsl(); 1350hsl.l += amount / 100; 1351 hsl.l = clamp01(hsl.l); 1352 return tinycolor(hsl); 1353 } 1354 function brighten(color, amount) { 1355 amount = (amount === 0) ? 0 : (amount || 10); 1356 var rgb = tinycolor(color).toRgb(); 1357rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100)))); 1358rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100)))); 1359rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100)))); 1360 return tinycolor(rgb); 1361 } 1362 function darken (color, amount) { 1363 amount = (amount === 0) ? 0 : (amount || 10); 1364 var hsl = tinycolor(color).toHsl(); 1365hsl.l -= amount / 100; 1366 hsl.l = clamp01(hsl.l); 1367 return tinycolor(hsl); 1368 } 1369 function spin(color, amount) { 1370 var hsl = tinycolor(color).toHsl(); 1371 var hue = (mathRound(hsl.h) + amount) % 360; 1372 hsl.h = hue < 0 ? 360 + hue : hue; 1373 return tinycolor(hsl); 1374 } 1375 function complement(color) { 1376 var hsl = tinycolor(color).toHsl(); 1377 hsl.h = (hsl.h + 180) % 360; 1378 return tinycolor(hsl); 1379 } 1380 function triad(color) { 1381 var hsl = tinycolor(color).toHsl(); 1382 var h = hsl.h; 1383 return [ 1384 tinycolor(color), 1385 tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }), 1386 tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l }) 1387 ]; 1388 } 1389 function tetrad(color) { 1390 var hsl = tinycolor(color).toHsl(); 1391 var h = hsl.h; 1392 return [ 1393 tinycolor(color), 1394 tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }), 1395 tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }), 1396 tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l }) 1397 ]; 1398 } 1399 function splitcomplement(color) { 1400 var hsl = tinycolor(color).toHsl(); 1401 var h = hsl.h; 1402 return [ 1403 tinycolor(color), 1404 tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}), 1405 tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l}) 1406 ]; 1407 } 1408 function analogous(color, results, slices) { 1409 results = results || 6; 1410 slices = slices || 30; 1411 var hsl = tinycolor(color).toHsl(); 1412var part = 360 / slices; 1413 var ret = [tinycolor(color)]; 1414 for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) { 1415 hsl.h = (hsl.h + part) % 360; 1416 ret.push(tinycolor(hsl)); 1417 } 1418 return ret; 1419 } 1420 function monochromatic(color, results) { 1421 results = results || 6; 1422 var hsv = tinycolor(color).toHsv(); 1423 var h = hsv.h, s = hsv.s, v = hsv.v; 1424 var ret = []; 1425var modification = 1 / results; 1426 while (results--) { 1427 ret.push(tinycolor({ h: h, s: s, v: v})); 1428 v = (v + modification) % 1; 1429 } 1430 return ret; 1431 } 1432 tinycolor.mix = function(color1, color2, amount) { 1433 amount = (amount === 0) ? 0 : (amount || 50); 1434 var rgb1 = tinycolor(color1).toRgb(); 1435 var rgb2 = tinycolor(color2).toRgb(); 1436var p = amount / 100; 1437 var w = p * 2 - 1; 1438 var a = rgb2.a - rgb1.a; 1439 var w1; 1440 if (w * a == -1) { 1441 w1 = w; 1442 } else { 1443w1 = (w + a) / (1 + w * a); 1444 } 1445w1 = (w1 + 1) / 2; 1446 var w2 = 1 - w1; 1447 var rgba = { 1448 r: rgb2.r * w1 + rgb1.r * w2, 1449 g: rgb2.g * w1 + rgb1.g * w2, 1450 b: rgb2.b * w1 + rgb1.b * w2, 1451 a: rgb2.a * p + rgb1.a * (1 - p) 1452 }; 1453 return tinycolor(rgba); 1454 }; 1455 tinycolor.readability = function(color1, color2) { 1456 var c1 = tinycolor(color1); 1457 var c2 = tinycolor(color2); 1458 var rgb1 = c1.toRgb(); 1459 var rgb2 = c2.toRgb(); 1460 var brightnessA = c1.getBrightness(); 1461 var brightnessB = c2.getBrightness(); 1462 var colorDiff = ( 1463 Math.max(rgb1.r, rgb2.r) - Math.min(rgb1.r, rgb2.r) + 1464 Math.max(rgb1.g, rgb2.g) - Math.min(rgb1.g, rgb2.g) + 1465 Math.max(rgb1.b, rgb2.b) - Math.min(rgb1.b, rgb2.b) 1466 ); 1467 return { 1468 brightness: Math.abs(brightnessA - brightnessB), 1469 color: colorDiff 1470 }; 1471 }; 1472 tinycolor.isReadable = function(color1, color2) { 1473 var readability = tinycolor.readability(color1, color2); 1474 return readability.brightness > 125 && readability.color > 500; 1475 }; 1476 tinycolor.mostReadable = function(baseColor, colorList) { 1477 var bestColor = null; 1478 var bestScore = 0; 1479 var bestIsReadable = false; 1480 for (var i=0; i < colorList.length; i++) { 1481 var readability = tinycolor.readability(baseColor, colorList[i]); 1482 var readable = readability.brightness > 125 && readability.color > 500; 1483var score = 3 * (readability.brightness / 125) + (readability.color / 500); 1484 if ((readable && ! bestIsReadable) || 1485 (readable && bestIsReadable && score > bestScore) || 1486 ((! readable) && (! bestIsReadable) && score > bestScore)) { 1487 bestIsReadable = readable; 1488 bestScore = score; 1489 bestColor = tinycolor(colorList[i]); 1490 } 1491 } 1492 return bestColor; 1493 }; 1494 var names = tinycolor.names = { 1495 aliceblue: "f0f8ff", 1496 antiquewhite: "faebd7", 1497 aqua: "0ff", 1498 aquamarine: "7fffd4", 1499 azure: "f0ffff", 1500 beige: "f5f5dc", 1501 bisque: "ffe4c4", 1502 black: "000", 1503 blanchedalmond: "ffebcd", 1504 blue: "00f", 1505 blueviolet: "8a2be2", 1506 brown: "a52a2a", 1507 burlywood: "deb887", 1508 burntsienna: "ea7e5d", 1509 cadetblue: "5f9ea0", 1510 chartreuse: "7fff00", 1511 chocolate: "d2691e", 1512 coral: "ff7f50", 1513 cornflowerblue: "6495ed", 1514 cornsilk: "fff8dc", 1515 crimson: "dc143c", 1516 cyan: "0ff", 1517 darkblue: "00008b", 1518 darkcyan: "008b8b", 1519 darkgoldenrod: "b8860b", 1520 darkgray: "a9a9a9", 1521 darkgreen: "006400", 1522 darkgrey: "a9a9a9", 1523 darkkhaki: "bdb76b", 1524 darkmagenta: "8b008b", 1525 darkolivegreen: "556b2f", 1526 darkorange: "ff8c00", 1527 darkorchid: "9932cc", 1528 darkred: "8b0000", 1529 darksalmon: "e9967a", 1530 darkseagreen: "8fbc8f", 1531 darkslateblue: "483d8b", 1532 darkslategray: "2f4f4f", 1533 darkslategrey: "2f4f4f", 1534 darkturquoise: "00ced1", 1535 darkviolet: "9400d3", 1536 deeppink: "ff1493", 1537 deepskyblue: "00bfff", 1538 dimgray: "696969", 1539 dimgrey: "696969", 1540 dodgerblue: "1e90ff", 1541 firebrick: "b22222", 1542 floralwhite: "fffaf0", 1543 forestgreen: "228b22", 1544 fuchsia: "f0f", 1545 gainsboro: "dcdcdc", 1546 ghostwhite: "f8f8ff", 1547 gold: "ffd700", 1548 goldenrod: "daa520", 1549 gray: "808080", 1550 green: "008000", 1551 greenyellow: "adff2f", 1552 grey: "808080", 1553 honeydew: "f0fff0", 1554 hotpink: "ff69b4", 1555 indianred: "cd5c5c", 1556 indigo: "4b0082", 1557 ivory: "fffff0", 1558 khaki: "f0e68c", 1559 lavender: "e6e6fa", 1560 lavenderblush: "fff0f5", 1561 lawngreen: "7cfc00", 1562 lemonchiffon: "fffacd", 1563 lightblue: "add8e6", 1564 lightcoral: "f08080", 1565 lightcyan: "e0ffff", 1566 lightgoldenrodyellow: "fafad2", 1567 lightgray: "d3d3d3", 1568 lightgreen: "90ee90", 1569 lightgrey: "d3d3d3", 1570 lightpink: "ffb6c1", 1571 lightsalmon: "ffa07a", 1572 lightseagreen: "20b2aa", 1573 lightskyblue: "87cefa", 1574 lightslategray: "789", 1575 lightslategrey: "789", 1576 lightsteelblue: "b0c4de", 1577 lightyellow: "ffffe0", 1578 lime: "0f0", 1579 limegreen: "32cd32", 1580 linen: "faf0e6", 1581 magenta: "f0f", 1582 maroon: "800000", 1583 mediumaquamarine: "66cdaa", 1584 mediumblue: "0000cd", 1585 mediumorchid: "ba55d3", 1586 mediumpurple: "9370db", 1587 mediumseagreen: "3cb371", 1588 mediumslateblue: "7b68ee", 1589 mediumspringgreen: "00fa9a", 1590 mediumturquoise: "48d1cc", 1591 mediumvioletred: "c71585", 1592 midnightblue: "191970", 1593 mintcream: "f5fffa", 1594 mistyrose: "ffe4e1", 1595 moccasin: "ffe4b5", 1596 navajowhite: "ffdead", 1597 navy: "000080", 1598 oldlace: "fdf5e6", 1599 olive: "808000", 1600 olivedrab: "6b8e23", 1601 orange: "ffa500", 1602 orangered: "ff4500", 1603 orchid: "da70d6", 1604 palegoldenrod: "eee8aa", 1605 palegreen: "98fb98", 1606 paleturquoise: "afeeee", 1607 palevioletred: "db7093", 1608 papayawhip: "ffefd5", 1609 peachpuff: "ffdab9", 1610 peru: "cd853f", 1611 pink: "ffc0cb", 1612 plum: "dda0dd", 1613 powderblue: "b0e0e6", 1614 purple: "800080", 1615 rebeccapurple: "663399", 1616 red: "f00", 1617 rosybrown: "bc8f8f", 1618 royalblue: "4169e1", 1619 saddlebrown: "8b4513", 1620 salmon: "fa8072", 1621 sandybrown: "f4a460", 1622 seagreen: "2e8b57", 1623 seashell: "fff5ee", 1624 sienna: "a0522d", 1625 silver: "c0c0c0", 1626 skyblue: "87ceeb", 1627 slateblue: "6a5acd", 1628 slategray: "708090", 1629 slategrey: "708090", 1630 snow: "fffafa", 1631 springgreen: "00ff7f", 1632 steelblue: "4682b4", 1633 tan: "d2b48c", 1634 teal: "008080", 1635 thistle: "d8bfd8", 1636 tomato: "ff6347", 1637 turquoise: "40e0d0", 1638 violet: "ee82ee", 1639 wheat: "f5deb3", 1640 white: "fff", 1641 whitesmoke: "f5f5f5", 1642 yellow: "ff0", 1643 yellowgreen: "9acd32" 1644 }; 1645 var hexNames = tinycolor.hexNames = flip(names); 1646 function flip(o) { 1647 var flipped = { }; 1648 for (var i in o) { 1649 if (o.hasOwnProperty(i)) { 1650 flipped[o[i]] = i; 1651 } 1652 } 1653 return flipped; 1654 } 1655 function boundAlpha(a) { 1656 a = parseFloat(a); 1657 if (isNaN(a) || a < 0 || a > 1) { 1658 a = 1; 1659 } 1660 return a; 1661 } 1662 function bound01(n, max) { 1663 if (isOnePointZero(n)) { n = "100%"; } 1664 var processPercent = isPercentage(n); 1665 n = mathMin(max, mathMax(0, parseFloat(n))); 1666 if (processPercent) { 1667n = parseInt(n * max, 10) / 100; 1668 } 1669 if ((math.abs(n - max) < 0.000001)) { 1670 return 1; 1671 } 1672return (n % max) / parseFloat(max); 1673 } 1674 function clamp01(val) { 1675 return mathMin(1, mathMax(0, val)); 1676 } 1677 function parseIntFromHex(val) { 1678 return parseInt(val, 16); 1679 } 1680 function isOnePointZero(n) { 1681 return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1; 1682 } 1683 function isPercentage(n) { 1684 return typeof n === "string" && n.indexOf('%') != -1; 1685 } 1686 function pad2(c) { 1687 return c.length == 1 ? '0' + c : '' + c; 1688 } 1689 function convertToPercentage(n) { 1690 if (n <= 1) { 1691 n = (n * 100) + "%"; 1692 } 1693 return n; 1694 } 1695 function convertDecimalToHex(d) { 1696 return Math.round(parseFloat(d) * 255).toString(16); 1697 } 1698 function convertHexToDecimal(h) { 1699return (parseIntFromHex(h) / 255); 1700 } 1701 var matchers = (function() { 1702 var CSS_INTEGER = "[-\\+]?\\d+%?"; 1703 var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?"; 1704 var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")"; 1705 var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; 1706 var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; 1707 return { 1708 rgb: new RegExp("rgb" + PERMISSIVE_MATCH3), 1709 rgba: new RegExp("rgba" + PERMISSIVE_MATCH4), 1710 hsl: new RegExp("hsl" + PERMISSIVE_MATCH3), 1711 hsla: new RegExp("hsla" + PERMISSIVE_MATCH4), 1712 hsv: new RegExp("hsv" + PERMISSIVE_MATCH3), 1713 hsva: new RegExp("hsva" + PERMISSIVE_MATCH4), 1714hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/, 1715hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/, 1716hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/ 1717 }; 1718 })(); 1719 function stringInputToObject(color) { 1720 color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase(); 1721 var named = false; 1722 if (names[color]) { 1723 color = names[color]; 1724 named = true; 1725 } 1726 else if (color == 'transparent') { 1727 return { r: 0, g: 0, b: 0, a: 0, format: "name" }; 1728 } 1729 var match; 1730 if ((match = matchers.rgb.exec(color))) { 1731 return { r: match[1], g: match[2], b: match[3] }; 1732 } 1733 if ((match = matchers.rgba.exec(color))) { 1734 return { r: match[1], g: match[2], b: match[3], a: match[4] }; 1735 } 1736 if ((match = matchers.hsl.exec(color))) { 1737 return { h: match[1], s: match[2], l: match[3] }; 1738 } 1739 if ((match = matchers.hsla.exec(color))) { 1740 return { h: match[1], s: match[2], l: match[3], a: match[4] }; 1741 } 1742 if ((match = matchers.hsv.exec(color))) { 1743 return { h: match[1], s: match[2], v: match[3] }; 1744 } 1745 if ((match = matchers.hsva.exec(color))) { 1746 return { h: match[1], s: match[2], v: match[3], a: match[4] }; 1747 } 1748 if ((match = matchers.hex8.exec(color))) { 1749 return { 1750 a: convertHexToDecimal(match[1]), 1751 r: parseIntFromHex(match[2]), 1752 g: parseIntFromHex(match[3]), 1753 b: parseIntFromHex(match[4]), 1754 format: named ? "name" : "hex8" 1755 }; 1756 } 1757 if ((match = matchers.hex6.exec(color))) { 1758 return { 1759 r: parseIntFromHex(match[1]), 1760 g: parseIntFromHex(match[2]), 1761 b: parseIntFromHex(match[3]), 1762 format: named ? "name" : "hex" 1763 }; 1764 } 1765 if ((match = matchers.hex3.exec(color))) { 1766 return { 1767 r: parseIntFromHex(match[1] + '' + match[1]), 1768 g: parseIntFromHex(match[2] + '' + match[2]), 1769 b: parseIntFromHex(match[3] + '' + match[3]), 1770 format: named ? "name" : "hex" 1771 }; 1772 } 1773 return false; 1774 } 1775 window.tinycolor = tinycolor; 1776 })(); 1777 $(function () { 1778 if ($.fn.spectrum.load) { 1779 $.fn.spectrum.processNativeColorInputs(); 1780 } 1781 }); 1782}); 1783;
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.