Skip to content

Commit 5aaa07d

Browse files
AC-103: Update Third Party library: spectrum/spectrum
1 parent 6df210e commit 5aaa07d

File tree

1 file changed

+58
-40
lines changed

1 file changed

+58
-40
lines changed

lib/web/jquery/spectrum/spectrum.js

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Spectrum Colorpicker v1.8.0
1+
// Spectrum Colorpicker v1.8.1
22
// https://github.com/bgrins/spectrum
33
// Author: Brian Grinstead
44
// License: MIT
@@ -140,7 +140,7 @@
140140
c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : "";
141141
var formattedString = tiny.toString(opts.preferredFormat || "rgb");
142142
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>');
144144
} else {
145145
var cls = 'sp-clear-display';
146146
html.push($('<div />')
@@ -304,7 +304,7 @@
304304

305305
updateSelectionPaletteFromStorage();
306306

307-
offsetElement.bind("click.spectrum touchstart.spectrum", function (e) {
307+
offsetElement.on("click.spectrum touchstart.spectrum", function (e) {
308308
if (!disabled) {
309309
toggle();
310310
}
@@ -325,21 +325,21 @@
325325

326326
// Handle user typed input
327327
textInput.change(setFromTextInput);
328-
textInput.bind("paste", function () {
328+
textInput.on("paste", function () {
329329
setTimeout(setFromTextInput, 1);
330330
});
331331
textInput.keydown(function (e) { if (e.keyCode == 13) { setFromTextInput(); } });
332332

333333
cancelButton.text(opts.cancelText);
334-
cancelButton.bind("click.spectrum", function (e) {
334+
cancelButton.on("click.spectrum", function (e) {
335335
e.stopPropagation();
336336
e.preventDefault();
337337
revert();
338338
hide();
339339
});
340340

341341
clearButton.attr("title", opts.clearText);
342-
clearButton.bind("click.spectrum", function (e) {
342+
clearButton.on("click.spectrum", function (e) {
343343
e.stopPropagation();
344344
e.preventDefault();
345345
isEmpty = true;
@@ -352,7 +352,7 @@
352352
});
353353

354354
chooseButton.text(opts.chooseText);
355-
chooseButton.bind("click.spectrum", function (e) {
355+
chooseButton.on("click.spectrum", function (e) {
356356
e.stopPropagation();
357357
e.preventDefault();
358358

@@ -367,7 +367,7 @@
367367
});
368368

369369
toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
370-
toggleButton.bind("click.spectrum", function (e) {
370+
toggleButton.on("click.spectrum", function (e) {
371371
e.stopPropagation();
372372
e.preventDefault();
373373

@@ -462,18 +462,23 @@
462462
else {
463463
set($(e.target).closest(".sp-thumb-el").data("color"));
464464
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.
466468
if (opts.hideAfterPaletteSelect) {
469+
updateOriginalInput(true);
467470
hide();
471+
} else {
472+
updateOriginalInput();
468473
}
469474
}
470475

471476
return false;
472477
}
473478

474479
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);
477482
}
478483

479484
function updateSelectionPaletteFromStorage() {
@@ -580,13 +585,15 @@
580585

581586
if ((value === null || value === "") && allowEmpty) {
582587
set(null);
583-
updateOriginalInput(true);
588+
move();
589+
updateOriginalInput();
584590
}
585591
else {
586592
var tiny = tinycolor(value);
587593
if (tiny.isValid()) {
588594
set(tiny);
589-
updateOriginalInput(true);
595+
move();
596+
updateOriginalInput();
590597
}
591598
else {
592599
textInput.addClass("sp-validation-error");
@@ -620,9 +627,9 @@
620627
hideAll();
621628
visible = true;
622629

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);
626633
replacer.addClass("sp-active");
627634
container.removeClass("sp-hidden");
628635

@@ -665,9 +672,9 @@
665672
if (!visible || flat) { return; }
666673
visible = false;
667674

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);
671678

672679
replacer.removeClass("sp-active");
673680
container.addClass("sp-hidden");
@@ -678,6 +685,7 @@
678685

679686
function revert() {
680687
set(colorOnShow, true);
688+
updateOriginalInput(true);
681689
}
682690

683691
function set(color, ignoreFormatChange) {
@@ -719,7 +727,7 @@
719727
h: currentHue,
720728
s: currentSaturation,
721729
v: currentValue,
722-
a: Math.round(currentAlpha * 100) / 100
730+
a: Math.round(currentAlpha * 1000) / 1000
723731
}, { format: opts.format || currentPreferredFormat });
724732
}
725733

@@ -909,7 +917,7 @@
909917

910918
function destroy() {
911919
boundElement.show();
912-
offsetElement.unbind("click.spectrum touchstart.spectrum");
920+
offsetElement.off("click.spectrum touchstart.spectrum");
913921
container.remove();
914922
replacer.remove();
915923
spectrums[spect.id] = null;
@@ -988,17 +996,27 @@
988996
var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
989997
var viewHeight = docElem.clientHeight + $(doc).scrollTop();
990998
var offset = input.offset();
991-
offset.top += inputHeight;
999+
var offsetLeft = offset.left;
1000+
var offsetTop = offset.top;
9921001

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;
9961003

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) ?
9991010
Math.abs(dpHeight + inputHeight - extraY) : extraY));
10001011

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+
};
10021020
}
10031021

10041022
/**
@@ -1091,7 +1109,7 @@
10911109
maxWidth = $(element).width();
10921110
offset = $(element).offset();
10931111

1094-
$(doc).bind(duringDragEvents);
1112+
$(doc).on(duringDragEvents);
10951113
$(doc.body).addClass("sp-dragging");
10961114

10971115
move(e);
@@ -1103,7 +1121,7 @@
11031121

11041122
function stop() {
11051123
if (dragging) {
1106-
$(doc).unbind(duringDragEvents);
1124+
$(doc).off(duringDragEvents);
11071125
$(doc.body).removeClass("sp-dragging");
11081126

11091127
// Wait a tick before notifying observers to allow the click event
@@ -1115,7 +1133,7 @@
11151133
dragging = false;
11161134
}
11171135

1118-
$(element).bind("touchstart mousedown", start);
1136+
$(element).on("touchstart mousedown", start);
11191137
}
11201138

11211139
function throttle(func, wait, debounce) {
@@ -1178,7 +1196,7 @@
11781196

11791197
// Initializing a new instance of spectrum
11801198
return this.spectrum("destroy").each(function () {
1181-
var options = $.extend({}, opts, $(this).data());
1199+
var options = $.extend({}, $(this).data(), opts);
11821200
var spect = spectrum(this, options);
11831201
$(this).data(dataID, spect.id);
11841202
});
@@ -1239,13 +1257,13 @@
12391257
}
12401258

12411259
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;
12491267
this._gradientType = opts.gradientType;
12501268

12511269
// Don't let the range of [0,255] come back in [0,1].
@@ -1285,7 +1303,7 @@
12851303
},
12861304
setAlpha: function(value) {
12871305
this._a = boundAlpha(value);
1288-
this._roundA = mathRound(100*this._a) / 100;
1306+
this._roundA = mathRound(1000 * this._a) / 1000;
12891307
return this;
12901308
},
12911309
toHsv: function() {

0 commit comments

Comments
 (0)