Last active
April 2, 2021 19:37
-
-
Save gregrickaby/aa96adef4406447df6dd to your computer and use it in GitHub Desktop.
WDS Javascript Style
This file contains hidden or 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
/** | |
* 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