I want to write one script that runs on every apge--that uses the jquery plugins that I just loaded--and run it first thing after all plugins are loaded. According to comments thus far, this requires defining and running modules in Require.js...
I have footer partial in a CMS that contains my Require.js code, thus:
<!-- special version of jQuery with RequireJS built-in -->
script data-main="/addons/shared_addons/themes/base/js/main" src="/addons/shared_addons/themesbase/js/require-jquery.js" type="text/javascript"> /script
...and my main.js is fairly standard:
// urlArgs: "bust=v1" // for release
require.config({
urlArgs: "bust=" + (new Date()).getTime(),
paths: {
Corner: "/addons/shared_addons/themes/base/js/jquery.corner",
JQForm: "/addons/shared_addons/themes/base/js/jquery.form",
Gritter: "/addons/shared_addons/themes/base/js/jquery.gritter.min",
JQUI: "/addons/shared_addons/themes/base/js/jquery-ui-1.8.21.custom.min",
TimePicker: "/addons/shared_addons/themes/base/js/jquery.ui.timepicker",
DateFormat: "/addons/shared_addons/themes/base/js/date.format",
countdown: "/addons/shared_addons/themes/base/js/jquery.countdown.min",
JQMustache: "/addons/shared_addons/themes/base/js/jquery-Mustache",
Mustache: "/addons/shared_addons/themes/base/js/mustache",
Kendo: "/addons/shared_addons/themes/base/js/kendo.web.min",
Chosen: "/addons/shared_addons/themes/base/js/chosen.jquery.min",
EveryPage: "/addons/shared_addons/themes/base/js/another_doc_ready_script"
}
});
require([
'jquery',
'Corner',
'JQForm',
'Gritter',
'JQUI',
'TimePicker',
'DateFormat',
'countdown',
'JQMustache',
'Mustache',
'Kendo',
'Chosen'
],
[ "EveryPage" ],
function($) {
//run
$(function() {
console.log('get everything we could possibly need');
});
});
"another_doc_ready_script.js" contains the "everypage" module definition:
console.log('here');
define("EveryPage",
[
'jquery',
'Corner',
'JQForm',
'Gritter',
'JQUI',
'TimePicker',
'DateFormat',
'countdown',
'JQMustache',
'Mustache',
'Kendo',
'Chosen'
],
function($) {
console.log('in everypage');
$(document).ready(function() {
console.log('in everypage doc ready');
$( "body").removeClass('nodisplay');
}); // document ready
console.log('leaving everypage');
} // function-define-require
); // define-require
EDIT: Bergi's comment made this make more sense. I have adapted my code above, but it is still not working. Zip. Nada. No console log statements or errors. This has got to be a common usage, but I am not finding a simple example.