Example JS File – Module Pattern

In the interests of having all my code snippets in a single location, here’s an empty JS file in case I need to cut and paste it into an existing theme or plugin. It uses the module pattern, meaning that all of the custom code is encapsulated in a single JS namespace. In this case Generico, as in my Genesis starter theme.

var generico = (function ($) {
'use strict';
/**
* Empty placeholder function.
*
* @since 1.0.0
*/
var functionName = function () {
// Empty function, do all the things.
},
/**
* Fire events on document ready, and bind other events.
*
* @since 1.0.0
*/
ready = function () {
functionName();
// Examples binding to events.
$(window).on('resize.generico', functionName);
$(window).on('scroll.generico resize.generico', functionName);
};
// Only expose the ready function to the world
return {
ready: ready
};
})(jQuery);
jQuery(generico.ready);
view raw global.js hosted with ❤ by GitHub

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *