Skip to content

Commit 9e805c9

Browse files
authored
Merge pull request #482 from s0ber/allow-manual-initialization
Allow manual initialization of jQuery UJS, if jQuery is not exposed to global namespace
2 parents ac99b2a + 267b70d commit 9e805c9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/rails.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function($, undefined) {
1+
/* jshint node: true */
22

33
/**
44
* Unobtrusive scripting adapter for jQuery
@@ -10,10 +10,13 @@
1010
*
1111
*/
1212

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() {
1514
'use strict';
1615

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.
1720
if ( $.rails !== undefined ) {
1821
$.error('jquery-ujs has already been loaded!');
1922
}
@@ -552,4 +555,11 @@
552555
});
553556
}
554557

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

Comments
 (0)