From 6452ac20806f34b61a12ea31fc384b24891bae79 Mon Sep 17 00:00:00 2001 From: Alexander Silberschneider Date: Thu, 4 Jan 2018 15:38:22 +0100 Subject: [PATCH] Replace deprecated event handlers Replace the usage of (deprecated) shortcut methods to attach event handlers with calls to "on". --- docs/docs.js | 6 +++--- example/example.js | 4 ++-- index.html | 12 ++++++------ spectrum.js | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/docs.js b/docs/docs.js index abd11a7d..0be76ed1 100644 --- a/docs/docs.js +++ b/docs/docs.js @@ -61,7 +61,7 @@ $("#hideButtons").spectrum({ var isDisabled = true; -$("#toggle-disabled").click(function() { +$("#toggle-disabled").on("click", function() { if (isDisabled) { $("#disabled").spectrum("enable"); } @@ -464,12 +464,12 @@ $("#triggerSet").spectrum({ // Show the original input to demonstrate the value changing when calling `set` $("#triggerSet").show(); -$("#btnEnterAColor").click(function() { +$("#btnEnterAColor").on("click", function() { $("#triggerSet").spectrum("set", $("#enterAColor").val()); }); $("#toggle").spectrum(); -$("#btn-toggle").click(function() { +$("#btn-toggle").on("click", function() { $("#toggle").spectrum("toggle"); return false; }); diff --git a/example/example.js b/example/example.js index 86337b4b..2fed8aeb 100644 --- a/example/example.js +++ b/example/example.js @@ -61,14 +61,14 @@ $(function() { ] }); - $("#size").change(function() { + $("#size").on("change", function() { var size = Math.min(500, Math.max(50, $(this).val())); $(".sp-picker-container").width(size); colorpickerInput.spectrum("reflow"); }); - $("#huesize").change(function() { + $("#huesize").on("change", function() { var size = Math.min(80, Math.max(5, $(this).val())); $(".sp-hue").css("left", (103 - size) + "%"); diff --git a/index.html b/index.html index a9d800d9..de434f10 100644 --- a/index.html +++ b/index.html @@ -759,10 +759,10 @@

Events

}); // Alternatively, they can be added as an event listener: -$("#picker").on('move.spectrum', function(e, tinycolor) { }); -$("#picker").on('show.spectrum', function(e, tinycolor) { }); -$("#picker").on('hide.spectrum', function(e, tinycolor) { }); -$("#picker").on('beforeShow.spectrum', function(e, tinycolor) { }); +$("#picker").on("move.spectrum", function(e, tinycolor) { }); +$("#picker").on("show.spectrum", function(e, tinycolor) { }); +$("#picker").on("hide.spectrum", function(e, tinycolor) { }); +$("#picker").on("beforeShow.spectrum", function(e, tinycolor) { });

change

@@ -965,7 +965,7 @@

toggle

-$("#btn-toggle").click(function() {
+$("#btn-toggle").on("click", function() {
     $("#toggle").spectrum("toggle");
     return false;
 });
@@ -1011,7 +1011,7 @@ 

set

// Show the original input to demonstrate the value changing when calling `set` $("#triggerSet").show(); -$("#btnEnterAColor").click(function() { +$("#btnEnterAColor").on("click", function() { $("#triggerSet").spectrum("set", $("#enterAColor").val()); }); </script> diff --git a/spectrum.js b/spectrum.js index e129e184..02b4dedd 100644 --- a/spectrum.js +++ b/spectrum.js @@ -321,14 +321,14 @@ } // Prevent clicks from bubbling up to document. This would cause it to be hidden. - container.click(stopPropagation); + container.on("click", stopPropagation); // Handle user typed input textInput.change(setFromTextInput); textInput.on("paste", function () { setTimeout(setFromTextInput, 1); }); - textInput.keydown(function (e) { if (e.keyCode == 13) { setFromTextInput(); } }); + textInput.on("keydown", function (e) { if (e.keyCode == 13) { setFromTextInput(); } }); cancelButton.text(opts.cancelText); cancelButton.on("click.spectrum", function (e) {