Skip to content

Commit

Permalink
Merge pull request #482 from s0ber/allow-manual-initialization
Browse files Browse the repository at this point in the history
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 9e805c9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/rails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function($, undefined) {
/* jshint node: true */

/**
* Unobtrusive scripting adapter for jQuery
Expand All @@ -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!');
}
Expand Down Expand Up @@ -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.