Skip to content

Instantly share code, notes, and snippets.

@l4ci
Created January 9, 2018 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l4ci/60c2e06eee0de68e8619560423ba3750 to your computer and use it in GitHub Desktop.
Save l4ci/60c2e06eee0de68e8619560423ba3750 to your computer and use it in GitHub Desktop.
/**
* Example Boilerplate Module
*
* Add boilerplateModule.init() to main.js to initiate it.
*/
var boilerplateModule = (function(){
var config = {
'default': true,
'element': $('.some-element'),
};
// Add functions
var doSomething = function(){
console.log('Boilerplate running.');
console.log('Loaded config:');
console.table(config);
}
// Add event handlers and keybindings here
var setupBindings = function(){
config.element.on('click',function(e){
e.preventDefault();
doSomething();
});
// Always append module name on global functions
$(window).on('scroll.boilerplateModule', doSomething);
};
var init = function(settings){
// Allow overriding the default config
if (settings) $.extend( config, settings );
setupBindings();
};
// Expose publicly
return {
init: init,
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment