Created
January 9, 2018 10:18
-
-
Save l4ci/60c2e06eee0de68e8619560423ba3750 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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