Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Last active April 2, 2021 19:37
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save gregrickaby/aa96adef4406447df6dd to your computer and use it in GitHub Desktop.
Save gregrickaby/aa96adef4406447df6dd to your computer and use it in GitHub Desktop.
WDS Javascript Style
/**
* file: wdsjQuery.js
*
* Handle Foo things for the foo theme.
*/
window.wdsFoo = {};
( function( window, $, app ) {
// Private variable.
var fooVariable = 'foo';
// Constructor.
app.init = function() {
app.cache();
if ( app.meetsRequirements() ) {
app.bindEvents();
}
};
// Cache all the things.
app.cache = function() {
app.$c = {
window: $( window ),
fooSelector: $( '.foo' )
};
};
// Combine all events.
app.bindEvents = function() {
app.$c.window.on( 'load', app.doFoo );
};
// Do we meet the requirements?
app.meetsRequirements = function() {
return app.$c.fooSelector.length;
};
// Some function.
app.doFoo = function() {
// do stuff.
};
// Engage!
$( app.init );
})( window, jQuery, window.wdsFoo );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment