From 267b70d8a15514b084627aac6facd5bbdca8dd20 Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 30 Dec 2016 14:08:12 +0800 Subject: [PATCH 1/5] 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 fcd8a33409ec6814a4ecc868073f175cba85083c Mon Sep 17 00:00:00 2001 From: Justin Searls Date: Fri, 4 Aug 2017 22:33:24 -0400 Subject: [PATCH 2/5] Add Rails 5.1 / webpacker instructions I just had to figure this out on my own, so I figured throwing it in the readme wouldn't hurt, given that 5.1 / webpacker are now released --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index df6aee68..2e429bd1 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,21 @@ Installation using npm. Run `npm install --save jquery-ujs` to install the jquery-ujs package. +Installation using Rails and Webpacker +------------ + +If you're using [webpacker](https://github.com/rails/webpacker) (introduced in [Rails 5.1](http://edgeguides.rubyonrails.org/5_1_release_notes.html#optional-webpack-support)) to manage JavaScript assets, then you can add the jquery-ujs npm package to your project using the [yarn](https://yarnpkg.com/en/) CLI. + +``` +$ yarn add jquery-ujs +``` + +Then, from any of your included files (e.g. `app/javascript/packs/application.js`, or from a JavaScript file imported by such a pack), you need only import the package for jquery-ujs to be initialized: + +```js +import {} from 'jquery-ujs' +``` + Installation using Bower ------------ From fd0837325aa58890e9d75288a9649b8935aceafd Mon Sep 17 00:00:00 2001 From: Jamie Dyer Date: Mon, 26 Mar 2018 10:39:08 +0100 Subject: [PATCH 3/5] 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 4/5] 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 5/5] 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": {