Skip to content

Allow manual initialization of jQuery UJS, if jQuery is not exposed to global namespace#482

Merged
rafaelfranca merged 1 commit intorails:masterfrom
s0ber:allow-manual-initialization
Apr 27, 2018
Merged

Allow manual initialization of jQuery UJS, if jQuery is not exposed to global namespace#482
rafaelfranca merged 1 commit intorails:masterfrom
s0ber:allow-manual-initialization

Conversation

@s0ber
Copy link
Contributor

@s0ber s0ber commented Dec 30, 2016

Problem

When you are using jQuery as a common js module, you try not to export it to window and require it manually only when you need it. But current implementation of jquery-ujs expects that jQuery is accessible in a global namespace.

Solution

This simple fix just exports initialization function as a module, if there is no window.jQuery.
In this case you can use it like that:

$ = require 'jquery'
jqueryUjsInit = require 'jquery-ujs'

jqueryUjsInit($)

If there is a global jQuery, then requiring jquery-ujs will be just enough:

require 'jquery-ujs'

So, this change should be completely backward compatible. Just let me know, if I need to add tests here, or suggest your concerns, I'd be really glad to help pushing this fix forward.

upd: I tried to use original indentation, so it will be easier to inspect the diff.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @lucasmazza (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@s0ber s0ber force-pushed the allow-manual-initialization branch from 6364084 to 95a7b38 Compare December 30, 2016 06:48
@s0ber s0ber force-pushed the allow-manual-initialization branch from 8789109 to 267b70d Compare December 30, 2016 06:52
@s0ber
Copy link
Contributor Author

s0ber commented Jan 9, 2017

@rails-bot @lucasmazza Anyone?

@wkirby
Copy link

wkirby commented Jan 28, 2017

This sure would be nice to see merged.

@s0ber
Copy link
Contributor Author

s0ber commented Feb 7, 2017

@wkirby Agree. It would be nice to hear any human feedback here, but seems like the project is kind of abandoned.

@s0ber
Copy link
Contributor Author

s0ber commented Jan 8, 2018

@lucasmazza Can you please leave any feedback on this?

@cr0t
Copy link

cr0t commented Apr 27, 2018

Up? Guys, anybody?

@rafaelfranca rafaelfranca merged commit 9e805c9 into rails:master Apr 27, 2018
tortuetorche added a commit to efficiently/jquery-laravel that referenced this pull request Jan 7, 2021
This simple fix just exports initialization function as a module, if
there is no window.jQuery.
In this case you can use it like that:

$ = require 'jquery'
jqueryUjsInit = require 'jquery-ujs'

jqueryUjsInit($)

Reference:
rails/jquery-ujs#482

Source:
https://github.com/rails/jquery-ujs/blob/master/src/rails.js
tortuetorche added a commit to efficiently/jquery-laravel that referenced this pull request Jan 7, 2021
This simple fix just exports initialization function as a module, if
there is no window.jQuery.
In this case you can use it like that:

$ = require 'jquery'
jqueryUjsInit = require 'jquery-ujs'

jqueryUjsInit($)

Reference:
rails/jquery-ujs#482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants