Skip to content

Instantly share code, notes, and snippets.

@davemo
Created March 10, 2010 17:31
Show Gist options
  • Select an option

  • Save davemo/328115 to your computer and use it in GitHub Desktop.

Select an option

Save davemo/328115 to your computer and use it in GitHub Desktop.
// 1. Instantiate a Loader in the global.html template
SREPLoader = new YAHOO.util.YUILoader({
base: '{% vurl "/static/script/" %}',
loadOptional: false,
combine: true,
require:["json"],
filter: "MIN",
allowRollup: true,
onSuccess: function() {
//you can make use of all requested YUI modules here.
while (SREPLoader.onReady.length) {
SREPLoader.onReady.shift()();
}
}
});
// 2. Define a list of executables that we can add to prior to page load completion
SREPLoader.onReady = [];
// 3. Load the list of modules in my manifest here:
(function() {
/* Modules for the Loader */
var modules = [ // indentation removed for visibility
{ name: 'jQuery.expose', type: 'js', varName: 'jQuery.expose', path: 'vendor/jquery.expose-0.14.min.js' },
{ name: 'jQuery.overlay', type: 'js', varName: 'jQuery.overlay', path: 'vendor/jquery.overlay-0.14.min.js', requires: ['jQuery.expose'] },
etc...
// add modules to loader
while( modules.length ) {
SREPLoader.addModule( modules.shift() );
}
})();
// 4. Load required modules for all pages
SREPLoader.require( 'SREP', 'SREP.Facebook');
// 5. Define a block that can be written to by child templates, that can add loader modules (django in this case)
// ie: child template contact.html requires a contactformhelper module: SREPLoader.require('SREP.FormHelper');
{% block script %}{% endblock %}
// 6. Insert the Loader picking up required modules from the global template and all children
SREPLoader.insert();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment