|
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 | + |
465 | 466 | updateOriginalInput(true);
|
466 | 467 | if (opts.hideAfterPaletteSelect) {
|
467 | 468 | hide();
|
|
472 | 473 | }
|
473 | 474 |
|
474 | 475 | 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); |
| 476 | + paletteContainer.on(paletteEvent, ".sp-thumb-el", paletteElementClick); |
| 477 | + initialColorContainer.on(paletteEvent, ".sp-thumb-el:nth-child(1)", { ignore: true }, paletteElementClick); |
477 | 478 | }
|
478 | 479 |
|
479 | 480 | function updateSelectionPaletteFromStorage() {
|
|
580 | 581 |
|
581 | 582 | if ((value === null || value === "") && allowEmpty) {
|
582 | 583 | set(null);
|
583 |
| - updateOriginalInput(true); |
| 584 | + move(); |
| 585 | + updateOriginalInput(); |
584 | 586 | }
|
585 | 587 | else {
|
586 | 588 | var tiny = tinycolor(value);
|
587 | 589 | if (tiny.isValid()) {
|
588 | 590 | set(tiny);
|
| 591 | + move(); |
589 | 592 | updateOriginalInput(true);
|
590 | 593 | }
|
591 | 594 | else {
|
|
620 | 623 | hideAll();
|
621 | 624 | visible = true;
|
622 | 625 |
|
623 |
| - $(doc).bind("keydown.spectrum", onkeydown); |
624 |
| - $(doc).bind("click.spectrum", clickout); |
625 |
| - $(window).bind("resize.spectrum", resize); |
| 626 | + $(doc).on("keydown.spectrum", onkeydown); |
| 627 | + $(doc).on("click.spectrum", clickout); |
| 628 | + $(window).on("resize.spectrum", resize); |
626 | 629 | replacer.addClass("sp-active");
|
627 | 630 | container.removeClass("sp-hidden");
|
628 | 631 |
|
|
665 | 668 | if (!visible || flat) { return; }
|
666 | 669 | visible = false;
|
667 | 670 |
|
668 |
| - $(doc).unbind("keydown.spectrum", onkeydown); |
669 |
| - $(doc).unbind("click.spectrum", clickout); |
670 |
| - $(window).unbind("resize.spectrum", resize); |
| 671 | + $(doc).off("keydown.spectrum", onkeydown); |
| 672 | + $(doc).off("click.spectrum", clickout); |
| 673 | + $(window).off("resize.spectrum", resize); |
671 | 674 |
|
672 | 675 | replacer.removeClass("sp-active");
|
673 | 676 | container.addClass("sp-hidden");
|
|
678 | 681 |
|
679 | 682 | function revert() {
|
680 | 683 | set(colorOnShow, true);
|
| 684 | + updateOriginalInput(true); |
681 | 685 | }
|
682 | 686 |
|
683 | 687 | function set(color, ignoreFormatChange) {
|
|
719 | 723 | h: currentHue,
|
720 | 724 | s: currentSaturation,
|
721 | 725 | v: currentValue,
|
722 |
| - a: Math.round(currentAlpha * 100) / 100 |
| 726 | + a: Math.round(currentAlpha * 1000) / 1000 |
723 | 727 | }, { format: opts.format || currentPreferredFormat });
|
724 | 728 | }
|
725 | 729 |
|
|
909 | 913 |
|
910 | 914 | function destroy() {
|
911 | 915 | boundElement.show();
|
912 |
| - offsetElement.unbind("click.spectrum touchstart.spectrum"); |
| 916 | + offsetElement.off("click.spectrum touchstart.spectrum"); |
913 | 917 | container.remove();
|
914 | 918 | replacer.remove();
|
915 | 919 | spectrums[spect.id] = null;
|
|
988 | 992 | var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
|
989 | 993 | var viewHeight = docElem.clientHeight + $(doc).scrollTop();
|
990 | 994 | var offset = input.offset();
|
991 |
| - offset.top += inputHeight; |
| 995 | + var offsetLeft = offset.left; |
| 996 | + var offsetTop = offset.top; |
| 997 | + |
| 998 | + offsetTop += inputHeight; |
992 | 999 |
|
993 |
| - offset.left -= |
994 |
| - Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? |
995 |
| - Math.abs(offset.left + dpWidth - viewWidth) : 0); |
| 1000 | + offsetLeft -= |
| 1001 | + Math.min(offsetLeft, (offsetLeft + dpWidth > viewWidth && viewWidth > dpWidth) ? |
| 1002 | + Math.abs(offsetLeft + dpWidth - viewWidth) : 0); |
996 | 1003 |
|
997 |
| - offset.top -= |
998 |
| - Math.min(offset.top, ((offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? |
| 1004 | + offsetTop -= |
| 1005 | + Math.min(offsetTop, ((offsetTop + dpHeight > viewHeight && viewHeight > dpHeight) ? |
999 | 1006 | Math.abs(dpHeight + inputHeight - extraY) : extraY));
|
1000 | 1007 |
|
1001 |
| - return offset; |
| 1008 | + return { |
| 1009 | + top: offsetTop, |
| 1010 | + bottom: offset.bottom, |
| 1011 | + left: offsetLeft, |
| 1012 | + right: offset.right, |
| 1013 | + width: offset.width, |
| 1014 | + height: offset.height |
| 1015 | + }; |
1002 | 1016 | }
|
1003 | 1017 |
|
1004 | 1018 | /**
|
|
1091 | 1105 | maxWidth = $(element).width();
|
1092 | 1106 | offset = $(element).offset();
|
1093 | 1107 |
|
1094 |
| - $(doc).bind(duringDragEvents); |
| 1108 | + $(doc).on(duringDragEvents); |
1095 | 1109 | $(doc.body).addClass("sp-dragging");
|
1096 | 1110 |
|
1097 | 1111 | move(e);
|
|
1103 | 1117 |
|
1104 | 1118 | function stop() {
|
1105 | 1119 | if (dragging) {
|
1106 |
| - $(doc).unbind(duringDragEvents); |
| 1120 | + $(doc).off(duringDragEvents); |
1107 | 1121 | $(doc.body).removeClass("sp-dragging");
|
1108 | 1122 |
|
1109 | 1123 | // Wait a tick before notifying observers to allow the click event
|
|
1115 | 1129 | dragging = false;
|
1116 | 1130 | }
|
1117 | 1131 |
|
1118 |
| - $(element).bind("touchstart mousedown", start); |
| 1132 | + $(element).on("touchstart mousedown", start); |
1119 | 1133 | }
|
1120 | 1134 |
|
1121 | 1135 | function throttle(func, wait, debounce) {
|
|
1178 | 1192 |
|
1179 | 1193 | // Initializing a new instance of spectrum
|
1180 | 1194 | return this.spectrum("destroy").each(function () {
|
1181 |
| - var options = $.extend({}, opts, $(this).data()); |
| 1195 | + var options = $.extend({}, $(this).data(), opts); |
1182 | 1196 | var spect = spectrum(this, options);
|
1183 | 1197 | $(this).data(dataID, spect.id);
|
1184 | 1198 | });
|
|
1239 | 1253 | }
|
1240 | 1254 |
|
1241 | 1255 | 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; |
| 1256 | + this._originalInput = color; |
| 1257 | + this._r = rgb.r; |
| 1258 | + this._g = rgb.g; |
| 1259 | + this._b = rgb.b; |
| 1260 | + this._a = rgb.a; |
| 1261 | + this._roundA = mathRound(1000 * this._a) / 1000; |
| 1262 | + this._format = opts.format || rgb.format; |
1249 | 1263 | this._gradientType = opts.gradientType;
|
1250 | 1264 |
|
1251 | 1265 | // Don't let the range of [0,255] come back in [0,1].
|
|
1285 | 1299 | },
|
1286 | 1300 | setAlpha: function(value) {
|
1287 | 1301 | this._a = boundAlpha(value);
|
1288 |
| - this._roundA = mathRound(100*this._a) / 100; |
| 1302 | + this._roundA = mathRound(1000 * this._a) / 1000; |
1289 | 1303 | return this;
|
1290 | 1304 | },
|
1291 | 1305 | toHsv: function() {
|
|
0 commit comments