|
1 |
| -// Spectrum Colorpicker v1.8.0 |
| 1 | +// Spectrum Colorpicker v1.8.1 |
2 | 2 | // https://github.com/bgrins/spectrum
|
3 | 3 | // Author: Brian Grinstead
|
4 | 4 | // License: MIT
|
|
140 | 140 | c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : "";
|
141 | 141 | var formattedString = tiny.toString(opts.preferredFormat || "rgb");
|
142 | 142 | var swatchStyle = rgbaSupport ? ("background-color:" + tiny.toRgbString()) : "filter:" + tiny.toFilter();
|
143 |
| - html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';" /></span>'); |
| 143 | + html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';"></span></span>'); |
144 | 144 | } else {
|
145 | 145 | var cls = 'sp-clear-display';
|
146 | 146 | html.push($('<div />')
|
|
304 | 304 |
|
305 | 305 | updateSelectionPaletteFromStorage();
|
306 | 306 |
|
307 |
| - offsetElement.bind("click.spectrum touchstart.spectrum", function (e) { |
| 307 | + offsetElement.on("click.spectrum touchstart.spectrum", function (e) { |
308 | 308 | if (!disabled) {
|
309 | 309 | toggle();
|
310 | 310 | }
|
|
325 | 325 |
|
326 | 326 | // Handle user typed input
|
327 | 327 | textInput.change(setFromTextInput);
|
328 |
| - textInput.bind("paste", function () { |
| 328 | + textInput.on("paste", function () { |
329 | 329 | setTimeout(setFromTextInput, 1);
|
330 | 330 | });
|
331 | 331 | textInput.keydown(function (e) { if (e.keyCode == 13) { setFromTextInput(); } });
|
332 | 332 |
|
333 | 333 | cancelButton.text(opts.cancelText);
|
334 |
| - cancelButton.bind("click.spectrum", function (e) { |
| 334 | + cancelButton.on("click.spectrum", function (e) { |
335 | 335 | e.stopPropagation();
|
336 | 336 | e.preventDefault();
|
337 | 337 | revert();
|
338 | 338 | hide();
|
339 | 339 | });
|
340 | 340 |
|
341 | 341 | clearButton.attr("title", opts.clearText);
|
342 |
| - clearButton.bind("click.spectrum", function (e) { |
| 342 | + clearButton.on("click.spectrum", function (e) { |
343 | 343 | e.stopPropagation();
|
344 | 344 | e.preventDefault();
|
345 | 345 | isEmpty = true;
|
|
352 | 352 | });
|
353 | 353 |
|
354 | 354 | chooseButton.text(opts.chooseText);
|
355 |
| - chooseButton.bind("click.spectrum", function (e) { |
| 355 | + chooseButton.on("click.spectrum", function (e) { |
356 | 356 | e.stopPropagation();
|
357 | 357 | e.preventDefault();
|
358 | 358 |
|
|
367 | 367 | });
|
368 | 368 |
|
369 | 369 | toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
|
370 |
| - toggleButton.bind("click.spectrum", function (e) { |
| 370 | + toggleButton.on("click.spectrum", function (e) { |
371 | 371 | e.stopPropagation();
|
372 | 372 | e.preventDefault();
|
373 | 373 |
|
|
462 | 462 | else {
|
463 | 463 | set($(e.target).closest(".sp-thumb-el").data("color"));
|
464 | 464 | move();
|
465 |
| - updateOriginalInput(true); |
| 465 | + |
| 466 | + // If the picker is going to close immediately, a palette selection |
| 467 | + // is a change. Otherwise, it's a move only. |
466 | 468 | if (opts.hideAfterPaletteSelect) {
|
| 469 | + updateOriginalInput(true); |
467 | 470 | hide();
|
| 471 | + } else { |
| 472 | + updateOriginalInput(); |
468 | 473 | }
|
469 | 474 | }
|
470 | 475 |
|
471 | 476 | return false;
|
472 | 477 | }
|
473 | 478 |
|
474 | 479 | var paletteEvent = IE ? "mousedown.spectrum" : "click.spectrum touchstart.spectrum";
|
475 |
| - paletteContainer.delegate(".sp-thumb-el", paletteEvent, paletteElementClick); |
476 |
| - initialColorContainer.delegate(".sp-thumb-el:nth-child(1)", paletteEvent, { ignore: true }, paletteElementClick); |
| 480 | + paletteContainer.on(paletteEvent, ".sp-thumb-el", paletteElementClick); |
| 481 | + initialColorContainer.on(paletteEvent, ".sp-thumb-el:nth-child(1)", { ignore: true }, paletteElementClick); |
477 | 482 | }
|
478 | 483 |
|
479 | 484 | function updateSelectionPaletteFromStorage() {
|
|
580 | 585 |
|
581 | 586 | if ((value === null || value === "") && allowEmpty) {
|
582 | 587 | set(null);
|
583 |
| - updateOriginalInput(true); |
| 588 | + move(); |
| 589 | + updateOriginalInput(); |
584 | 590 | }
|
585 | 591 | else {
|
586 | 592 | var tiny = tinycolor(value);
|
587 | 593 | if (tiny.isValid()) {
|
588 | 594 | set(tiny);
|
589 |
| - updateOriginalInput(true); |
| 595 | + move(); |
| 596 | + updateOriginalInput(); |
590 | 597 | }
|
591 | 598 | else {
|
592 | 599 | textInput.addClass("sp-validation-error");
|
|
620 | 627 | hideAll();
|
621 | 628 | visible = true;
|
622 | 629 |
|
623 |
| - $(doc).bind("keydown.spectrum", onkeydown); |
624 |
| - $(doc).bind("click.spectrum", clickout); |
625 |
| - $(window).bind("resize.spectrum", resize); |
| 630 | + $(doc).on("keydown.spectrum", onkeydown); |
| 631 | + $(doc).on("click.spectrum", clickout); |
| 632 | + $(window).on("resize.spectrum", resize); |
626 | 633 | replacer.addClass("sp-active");
|
627 | 634 | container.removeClass("sp-hidden");
|
628 | 635 |
|
|
665 | 672 | if (!visible || flat) { return; }
|
666 | 673 | visible = false;
|
667 | 674 |
|
668 |
| - $(doc).unbind("keydown.spectrum", onkeydown); |
669 |
| - $(doc).unbind("click.spectrum", clickout); |
670 |
| - $(window).unbind("resize.spectrum", resize); |
| 675 | + $(doc).off("keydown.spectrum", onkeydown); |
| 676 | + $(doc).off("click.spectrum", clickout); |
| 677 | + $(window).off("resize.spectrum", resize); |
671 | 678 |
|
672 | 679 | replacer.removeClass("sp-active");
|
673 | 680 | container.addClass("sp-hidden");
|
|
678 | 685 |
|
679 | 686 | function revert() {
|
680 | 687 | set(colorOnShow, true);
|
| 688 | + updateOriginalInput(true); |
681 | 689 | }
|
682 | 690 |
|
683 | 691 | function set(color, ignoreFormatChange) {
|
|
719 | 727 | h: currentHue,
|
720 | 728 | s: currentSaturation,
|
721 | 729 | v: currentValue,
|
722 |
| - a: Math.round(currentAlpha * 100) / 100 |
| 730 | + a: Math.round(currentAlpha * 1000) / 1000 |
723 | 731 | }, { format: opts.format || currentPreferredFormat });
|
724 | 732 | }
|
725 | 733 |
|
|
909 | 917 |
|
910 | 918 | function destroy() {
|
911 | 919 | boundElement.show();
|
912 |
| - offsetElement.unbind("click.spectrum touchstart.spectrum"); |
| 920 | + offsetElement.off("click.spectrum touchstart.spectrum"); |
913 | 921 | container.remove();
|
914 | 922 | replacer.remove();
|
915 | 923 | spectrums[spect.id] = null;
|
|
988 | 996 | var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
|
989 | 997 | var viewHeight = docElem.clientHeight + $(doc).scrollTop();
|
990 | 998 | var offset = input.offset();
|
991 |
| - offset.top += inputHeight; |
| 999 | + var offsetLeft = offset.left; |
| 1000 | + var offsetTop = offset.top; |
992 | 1001 |
|
993 |
| - offset.left -= |
994 |
| - Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? |
995 |
| - Math.abs(offset.left + dpWidth - viewWidth) : 0); |
| 1002 | + offsetTop += inputHeight; |
996 | 1003 |
|
997 |
| - offset.top -= |
998 |
| - Math.min(offset.top, ((offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? |
| 1004 | + offsetLeft -= |
| 1005 | + Math.min(offsetLeft, (offsetLeft + dpWidth > viewWidth && viewWidth > dpWidth) ? |
| 1006 | + Math.abs(offsetLeft + dpWidth - viewWidth) : 0); |
| 1007 | + |
| 1008 | + offsetTop -= |
| 1009 | + Math.min(offsetTop, ((offsetTop + dpHeight > viewHeight && viewHeight > dpHeight) ? |
999 | 1010 | Math.abs(dpHeight + inputHeight - extraY) : extraY));
|
1000 | 1011 |
|
1001 |
| - return offset; |
| 1012 | + return { |
| 1013 | + top: offsetTop, |
| 1014 | + bottom: offset.bottom, |
| 1015 | + left: offsetLeft, |
| 1016 | + right: offset.right, |
| 1017 | + width: offset.width, |
| 1018 | + height: offset.height |
| 1019 | + }; |
1002 | 1020 | }
|
1003 | 1021 |
|
1004 | 1022 | /**
|
|
1091 | 1109 | maxWidth = $(element).width();
|
1092 | 1110 | offset = $(element).offset();
|
1093 | 1111 |
|
1094 |
| - $(doc).bind(duringDragEvents); |
| 1112 | + $(doc).on(duringDragEvents); |
1095 | 1113 | $(doc.body).addClass("sp-dragging");
|
1096 | 1114 |
|
1097 | 1115 | move(e);
|
|
1103 | 1121 |
|
1104 | 1122 | function stop() {
|
1105 | 1123 | if (dragging) {
|
1106 |
| - $(doc).unbind(duringDragEvents); |
| 1124 | + $(doc).off(duringDragEvents); |
1107 | 1125 | $(doc.body).removeClass("sp-dragging");
|
1108 | 1126 |
|
1109 | 1127 | // Wait a tick before notifying observers to allow the click event
|
|
1115 | 1133 | dragging = false;
|
1116 | 1134 | }
|
1117 | 1135 |
|
1118 |
| - $(element).bind("touchstart mousedown", start); |
| 1136 | + $(element).on("touchstart mousedown", start); |
1119 | 1137 | }
|
1120 | 1138 |
|
1121 | 1139 | function throttle(func, wait, debounce) {
|
|
1178 | 1196 |
|
1179 | 1197 | // Initializing a new instance of spectrum
|
1180 | 1198 | return this.spectrum("destroy").each(function () {
|
1181 |
| - var options = $.extend({}, opts, $(this).data()); |
| 1199 | + var options = $.extend({}, $(this).data(), opts); |
1182 | 1200 | var spect = spectrum(this, options);
|
1183 | 1201 | $(this).data(dataID, spect.id);
|
1184 | 1202 | });
|
|
1239 | 1257 | }
|
1240 | 1258 |
|
1241 | 1259 | var rgb = inputToRGB(color);
|
1242 |
| - this._originalInput = color, |
1243 |
| - this._r = rgb.r, |
1244 |
| - this._g = rgb.g, |
1245 |
| - this._b = rgb.b, |
1246 |
| - this._a = rgb.a, |
1247 |
| - this._roundA = mathRound(100*this._a) / 100, |
1248 |
| - this._format = opts.format || rgb.format; |
| 1260 | + this._originalInput = color; |
| 1261 | + this._r = rgb.r; |
| 1262 | + this._g = rgb.g; |
| 1263 | + this._b = rgb.b; |
| 1264 | + this._a = rgb.a; |
| 1265 | + this._roundA = mathRound(1000 * this._a) / 1000; |
| 1266 | + this._format = opts.format || rgb.format; |
1249 | 1267 | this._gradientType = opts.gradientType;
|
1250 | 1268 |
|
1251 | 1269 | // Don't let the range of [0,255] come back in [0,1].
|
|
1285 | 1303 | },
|
1286 | 1304 | setAlpha: function(value) {
|
1287 | 1305 | this._a = boundAlpha(value);
|
1288 |
| - this._roundA = mathRound(100*this._a) / 100; |
| 1306 | + this._roundA = mathRound(1000 * this._a) / 1000; |
1289 | 1307 | return this;
|
1290 | 1308 | },
|
1291 | 1309 | toHsv: function() {
|
|
0 commit comments