|
1 |
| -(function($, undefined) { |
| 1 | +/* jshint node: true */ |
2 | 2 |
|
3 | 3 | /**
|
4 | 4 | * Unobtrusive scripting adapter for jQuery
|
|
10 | 10 | *
|
11 | 11 | */
|
12 | 12 |
|
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() { |
15 | 14 | 'use strict';
|
16 | 15 |
|
| 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. |
17 | 20 | if ( $.rails !== undefined ) {
|
18 | 21 | $.error('jquery-ujs has already been loaded!');
|
19 | 22 | }
|
|
33 | 36 | inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
34 | 37 |
|
35 | 38 | // Form elements bound by jquery-ujs
|
36 |
| - formSubmitSelector: 'form', |
| 39 | + formSubmitSelector: 'form:not([data-turbo=true])', |
37 | 40 |
|
38 | 41 | // 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])', |
40 | 43 |
|
41 | 44 | // Form input elements disabled during form submission
|
42 | 45 | 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 | 375 | element.html(replacement);
|
373 | 376 | }
|
374 | 377 |
|
375 |
| - element.bind('click.railsDisable', function(e) { // prevent further clicking |
| 378 | + element.on('click.railsDisable', function(e) { // prevent further clicking |
376 | 379 | return rails.stopEverything(e);
|
377 | 380 | });
|
378 | 381 | element.data('ujs:disabled', true);
|
|
384 | 387 | element.html(element.data('ujs:enable-with')); // set to old enabled state
|
385 | 388 | element.removeData('ujs:enable-with'); // clean up cache
|
386 | 389 | }
|
387 |
| - element.unbind('click.railsDisable'); // enable element |
| 390 | + element.off('click.railsDisable'); // enable element |
388 | 391 | element.removeData('ujs:disabled');
|
389 | 392 | }
|
390 | 393 | };
|
|
552 | 555 | });
|
553 | 556 | }
|
554 | 557 |
|
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