Permalink
Browse files

Merge pull request #482 from s0ber/allow-manual-initialization

Allow manual initialization of jQuery UJS, if jQuery is not exposed to global namespace
  • Loading branch information...
rafaelfranca committed Apr 27, 2018
2 parents ac99b2a + 267b70d commit 9e805c90c8cfc57b39967052e1e9013ccb318cf8
Showing with 14 additions and 4 deletions.
  1. +14 −4 src/rails.js
View
@@ -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;
+ }
+})();

0 comments on commit 9e805c9

Please sign in to comment.