Skip to content

Commit 60637c2

Browse files
authored
Merge pull request #7075 from magento-trigger/AC-103
[Trigger] AC-103: Update Third Party library: spectrum/spectrum
2 parents c75fd89 + 50c9056 commit 60637c2

File tree

1 file changed

+52
-38
lines changed

1 file changed

+52
-38
lines changed

lib/web/jquery/spectrum/spectrum.js

Lines changed: 52 additions & 38 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,6 +462,7 @@
462462
else {
463463
set($(e.target).closest(".sp-thumb-el").data("color"));
464464
move();
465+
465466
updateOriginalInput(true);
466467
if (opts.hideAfterPaletteSelect) {
467468
hide();
@@ -472,8 +473,8 @@
472473
}
473474

474475
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);
477478
}
478479

479480
function updateSelectionPaletteFromStorage() {
@@ -580,12 +581,14 @@
580581

581582
if ((value === null || value === "") && allowEmpty) {
582583
set(null);
583-
updateOriginalInput(true);
584+
move();
585+
updateOriginalInput();
584586
}
585587
else {
586588
var tiny = tinycolor(value);
587589
if (tiny.isValid()) {
588590
set(tiny);
591+
move();
589592
updateOriginalInput(true);
590593
}
591594
else {
@@ -620,9 +623,9 @@
620623
hideAll();
621624
visible = true;
622625

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);
626629
replacer.addClass("sp-active");
627630
container.removeClass("sp-hidden");
628631

@@ -665,9 +668,9 @@
665668
if (!visible || flat) { return; }
666669
visible = false;
667670

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

672675
replacer.removeClass("sp-active");
673676
container.addClass("sp-hidden");
@@ -678,6 +681,7 @@
678681

679682
function revert() {
680683
set(colorOnShow, true);
684+
updateOriginalInput(true);
681685
}
682686

683687
function set(color, ignoreFormatChange) {
@@ -719,7 +723,7 @@
719723
h: currentHue,
720724
s: currentSaturation,
721725
v: currentValue,
722-
a: Math.round(currentAlpha * 100) / 100
726+
a: Math.round(currentAlpha * 1000) / 1000
723727
}, { format: opts.format || currentPreferredFormat });
724728
}
725729

@@ -909,7 +913,7 @@
909913

910914
function destroy() {
911915
boundElement.show();
912-
offsetElement.unbind("click.spectrum touchstart.spectrum");
916+
offsetElement.off("click.spectrum touchstart.spectrum");
913917
container.remove();
914918
replacer.remove();
915919
spectrums[spect.id] = null;
@@ -988,17 +992,27 @@
988992
var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
989993
var viewHeight = docElem.clientHeight + $(doc).scrollTop();
990994
var offset = input.offset();
991-
offset.top += inputHeight;
995+
var offsetLeft = offset.left;
996+
var offsetTop = offset.top;
997+
998+
offsetTop += inputHeight;
992999

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

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

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+
};
10021016
}
10031017

10041018
/**
@@ -1091,7 +1105,7 @@
10911105
maxWidth = $(element).width();
10921106
offset = $(element).offset();
10931107

1094-
$(doc).bind(duringDragEvents);
1108+
$(doc).on(duringDragEvents);
10951109
$(doc.body).addClass("sp-dragging");
10961110

10971111
move(e);
@@ -1103,7 +1117,7 @@
11031117

11041118
function stop() {
11051119
if (dragging) {
1106-
$(doc).unbind(duringDragEvents);
1120+
$(doc).off(duringDragEvents);
11071121
$(doc.body).removeClass("sp-dragging");
11081122

11091123
// Wait a tick before notifying observers to allow the click event
@@ -1115,7 +1129,7 @@
11151129
dragging = false;
11161130
}
11171131

1118-
$(element).bind("touchstart mousedown", start);
1132+
$(element).on("touchstart mousedown", start);
11191133
}
11201134

11211135
function throttle(func, wait, debounce) {
@@ -1178,7 +1192,7 @@
11781192

11791193
// Initializing a new instance of spectrum
11801194
return this.spectrum("destroy").each(function () {
1181-
var options = $.extend({}, opts, $(this).data());
1195+
var options = $.extend({}, $(this).data(), opts);
11821196
var spect = spectrum(this, options);
11831197
$(this).data(dataID, spect.id);
11841198
});
@@ -1239,13 +1253,13 @@
12391253
}
12401254

12411255
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;
12491263
this._gradientType = opts.gradientType;
12501264

12511265
// Don't let the range of [0,255] come back in [0,1].
@@ -1285,7 +1299,7 @@
12851299
},
12861300
setAlpha: function(value) {
12871301
this._a = boundAlpha(value);
1288-
this._roundA = mathRound(100*this._a) / 100;
1302+
this._roundA = mathRound(1000 * this._a) / 1000;
12891303
return this;
12901304
},
12911305
toHsv: function() {

0 commit comments

Comments
 (0)