Skip to content

Commit 7e6f508

Browse files
Update jquery-ujs to latest v1.2.3
It contains improved compatibility with turbo. rails/jquery-ujs#521 Closes #284
1 parent a80d74b commit 7e6f508

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## unreleased
22

33
- update jquery to 3.6.1
4+
- update jquery-usj to 1.2.3
45

56
## 4.5.0
67

VERSIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| Gem | jQuery | jQuery UJS | jQuery UI |
44
|--------|--------|------------| ----------|
5-
| x.x.x | 1.12.4 & 2.2.4 & 3.6.1 | 1.2.2 | - |
5+
| x.x.x | 1.12.4 & 2.2.4 & 3.6.1 | 1.2.3 | - |
66
| 4.5.0 | 1.12.4 & 2.2.4 & 3.6.0 | 1.2.2 | - |
77
| 4.4.0 | 1.12.4 & 2.2.4 & 3.5.1 | 1.2.2 | - |
88
| 4.3.5 | 1.12.4 & 2.2.4 & 3.4.1 | 1.2.2 | - |

lib/jquery/rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ module Rails
44
JQUERY_VERSION = "1.12.4"
55
JQUERY_2_VERSION = "2.2.4"
66
JQUERY_3_VERSION = "3.6.1"
7-
JQUERY_UJS_VERSION = "1.2.2"
7+
JQUERY_UJS_VERSION = "1.2.3"
88
end
99
end

vendor/assets/javascripts/jquery_ujs.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function($, undefined) {
1+
/* jshint node: true */
22

33
/**
44
* Unobtrusive scripting adapter for jQuery
@@ -10,10 +10,13 @@
1010
*
1111
*/
1212

13-
// Cut down on the number of issues from people inadvertently including jquery_ujs twice
14-
// by detecting and raising an error when it happens.
13+
(function() {
1514
'use strict';
1615

16+
var jqueryUjsInit = function($, undefined) {
17+
18+
// Cut down on the number of issues from people inadvertently including jquery_ujs twice
19+
// by detecting and raising an error when it happens.
1720
if ( $.rails !== undefined ) {
1821
$.error('jquery-ujs has already been loaded!');
1922
}
@@ -33,10 +36,10 @@
3336
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
3437

3538
// Form elements bound by jquery-ujs
36-
formSubmitSelector: 'form',
39+
formSubmitSelector: 'form:not([data-turbo=true])',
3740

3841
// Form input elements bound by jquery-ujs
39-
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])',
42+
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])',
4043

4144
// Form input elements disabled during form submission
4245
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 @@
372375
element.html(replacement);
373376
}
374377

375-
element.bind('click.railsDisable', function(e) { // prevent further clicking
378+
element.on('click.railsDisable', function(e) { // prevent further clicking
376379
return rails.stopEverything(e);
377380
});
378381
element.data('ujs:disabled', true);
@@ -384,7 +387,7 @@
384387
element.html(element.data('ujs:enable-with')); // set to old enabled state
385388
element.removeData('ujs:enable-with'); // clean up cache
386389
}
387-
element.unbind('click.railsDisable'); // enable element
390+
element.off('click.railsDisable'); // enable element
388391
element.removeData('ujs:disabled');
389392
}
390393
};
@@ -552,4 +555,11 @@
552555
});
553556
}
554557

555-
})( jQuery );
558+
};
559+
560+
if (window.jQuery) {
561+
jqueryUjsInit(jQuery);
562+
} else if (typeof exports === 'object' && typeof module === 'object') {
563+
module.exports = jqueryUjsInit;
564+
}
565+
})();

0 commit comments

Comments
 (0)