Skip to content

Instantly share code, notes, and snippets.

@jaredwilli
Created December 13, 2013 18:41
Show Gist options
  • Save jaredwilli/7949078 to your computer and use it in GitHub Desktop.
Save jaredwilli/7949078 to your computer and use it in GitHub Desktop.
DOM Ready module pattern
/**
* Brightcove Consulting
*/
var bcc = {
common : {
init: function(){
$('body').append('<h2>HIIIIII<h2>');
}
}
};
var UTIL = {
fire : function(func,funcname, args){
var namespace = bcc; // indicate your obj literal namespace here
funcname = (funcname === undefined) ? 'init' : funcname;
if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function'){
namespace[func][funcname](args);
}
},
loadEvents : function(){
var bodyId = document.body.id;
// hit up common first.
UTIL.fire('common');
// do all the classes too.
$.each(document.body.className.split(/\s+/),function(i,classnm){
UTIL.fire(classnm);
UTIL.fire(classnm,bodyId);
});
UTIL.fire('common','finalize');
}
};
// kick it all off here
$(document).ready(UTIL.loadEvents);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment