From 7e6f508b36b4ba7341a9f742d864c84a5b6bb626 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 10 Nov 2022 14:47:55 -0300 Subject: [PATCH] Update jquery-ujs to latest v1.2.3 It contains improved compatibility with turbo. https://github.com/rails/jquery-ujs/pull/521 Closes #284 --- CHANGELOG.md | 1 + VERSIONS.md | 2 +- lib/jquery/rails/version.rb | 2 +- vendor/assets/javascripts/jquery_ujs.js | 26 +++++++++++++++++-------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a604905b..fa14ae83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## unreleased - update jquery to 3.6.1 +- update jquery-usj to 1.2.3 ## 4.5.0 diff --git a/VERSIONS.md b/VERSIONS.md index 21d3cbe7..2bc6e798 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -2,7 +2,7 @@ | Gem | jQuery | jQuery UJS | jQuery UI | |--------|--------|------------| ----------| -| x.x.x | 1.12.4 & 2.2.4 & 3.6.1 | 1.2.2 | - | +| x.x.x | 1.12.4 & 2.2.4 & 3.6.1 | 1.2.3 | - | | 4.5.0 | 1.12.4 & 2.2.4 & 3.6.0 | 1.2.2 | - | | 4.4.0 | 1.12.4 & 2.2.4 & 3.5.1 | 1.2.2 | - | | 4.3.5 | 1.12.4 & 2.2.4 & 3.4.1 | 1.2.2 | - | diff --git a/lib/jquery/rails/version.rb b/lib/jquery/rails/version.rb index 4c775777..cfd75fa7 100644 --- a/lib/jquery/rails/version.rb +++ b/lib/jquery/rails/version.rb @@ -4,6 +4,6 @@ module Rails JQUERY_VERSION = "1.12.4" JQUERY_2_VERSION = "2.2.4" JQUERY_3_VERSION = "3.6.1" - JQUERY_UJS_VERSION = "1.2.2" + JQUERY_UJS_VERSION = "1.2.3" end end diff --git a/vendor/assets/javascripts/jquery_ujs.js b/vendor/assets/javascripts/jquery_ujs.js index 1370a65c..0e27110d 100644 --- a/vendor/assets/javascripts/jquery_ujs.js +++ b/vendor/assets/javascripts/jquery_ujs.js @@ -1,4 +1,4 @@ -(function($, undefined) { +/* jshint node: true */ /** * Unobtrusive scripting adapter for jQuery @@ -10,10 +10,13 @@ * */ - // Cut down on the number of issues from people inadvertently including jquery_ujs twice - // by detecting and raising an error when it happens. +(function() { 'use strict'; + var jqueryUjsInit = function($, undefined) { + + // Cut down on the number of issues from people inadvertently including jquery_ujs twice + // by detecting and raising an error when it happens. if ( $.rails !== undefined ) { $.error('jquery-ujs has already been loaded!'); } @@ -33,10 +36,10 @@ inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]', // Form elements bound by jquery-ujs - formSubmitSelector: 'form', + formSubmitSelector: 'form:not([data-turbo=true])', // Form input elements bound by jquery-ujs - formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])', + formInputClickSelector: 'form:not([data-turbo=true]) input[type=submit], form:not([data-turbo=true]) input[type=image], form:not([data-turbo=true]) button[type=submit], form:not([data-turbo=true]) button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])', // Form input elements disabled during form submission disableSelector: 'input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled', @@ -372,7 +375,7 @@ element.html(replacement); } - element.bind('click.railsDisable', function(e) { // prevent further clicking + element.on('click.railsDisable', function(e) { // prevent further clicking return rails.stopEverything(e); }); element.data('ujs:disabled', true); @@ -384,7 +387,7 @@ element.html(element.data('ujs:enable-with')); // set to old enabled state element.removeData('ujs:enable-with'); // clean up cache } - element.unbind('click.railsDisable'); // enable element + element.off('click.railsDisable'); // enable element element.removeData('ujs:disabled'); } }; @@ -552,4 +555,11 @@ }); } -})( jQuery ); + }; + + if (window.jQuery) { + jqueryUjsInit(jQuery); + } else if (typeof exports === 'object' && typeof module === 'object') { + module.exports = jqueryUjsInit; + } +})();