From 267b70d8a15514b084627aac6facd5bbdca8dd20 Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 30 Dec 2016 14:08:12 +0800 Subject: [PATCH 1/4] Allow to init Jquery UJS manually --- src/rails.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/rails.js b/src/rails.js index 1370a65c..e5f581fd 100644 --- a/src/rails.js +++ b/src/rails.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!'); } @@ -552,4 +555,11 @@ }); } -})( jQuery ); + }; + + if (window.jQuery) { + jqueryUjsInit(jQuery); + } else if (typeof exports === 'object' && typeof module === 'object') { + module.exports = jqueryUjsInit; + } +})(); From fd0837325aa58890e9d75288a9649b8935aceafd Mon Sep 17 00:00:00 2001 From: Jamie Dyer Date: Mon, 26 Mar 2018 10:39:08 +0100 Subject: [PATCH 2/4] Change jquery dependency to a peer dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 08a5a245..ca5c8bce 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "url": "https://github.com/rails/jquery-ujs/issues" }, "homepage": "https://github.com/rails/jquery-ujs#readme", - "dependencies": { + "peerDependencies": { "jquery": ">=1.8.0" } } From 4bdd8724d41a4dc84aa3f9b29381adb47e6ee215 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 14 Jun 2021 15:19:02 +0200 Subject: [PATCH 3/4] Don't attach UJS form submission handlers to Turbo forms Allows for easier migration of apps written for UJS, such that new work can be done with Turbo forms that are marked with data-turbo=true. --- src/rails.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rails.js b/src/rails.js index 93620134..0e27110d 100644 --- a/src/rails.js +++ b/src/rails.js @@ -36,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', From 83b041ba72261f487b9264b9e94211e8107a1f18 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 15 Jun 2021 17:39:02 +0200 Subject: [PATCH 4/4] Bump version for Turbo compatibility --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ca5c8bce..9299d5f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery-ujs", - "version": "1.2.2", + "version": "1.2.3", "description": "Unobtrusive scripting adapter for jQuery", "main": "src/rails.js", "scripts": {