Skip to content

Instantly share code, notes, and snippets.

@scarfacedeb
Created September 9, 2013 20:02
Show Gist options
  • Save scarfacedeb/6500740 to your computer and use it in GitHub Desktop.
Save scarfacedeb/6500740 to your computer and use it in GitHub Desktop.
My basic modular pattern for javascript files
var Module = (function(document, window, $){
var self = {},
// DOM/jQuery
$document = $(document),
$window = $(window),
// flags
// private functions
bindEvents,
assignDomVariables;
bindEvents = function(){
$document.on( 'ready page:change', assignDomVariables );
$document.on( 'ready page:change', function(){
});
$document.on( 'page:receive', self.destroy );
};
// assign DOM-dependent variables
assignDomVariables = function(){
};
// module settings
self.settings = {
};
self.init = function( settings ){
if ( settings ) {
$.extend( {}, self.settings, settings );
}
bindEvents();
};
self.destroy = function(){
$window.off('.module');
};
return self;
})(document, window, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment