Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Last active August 29, 2015 13:59
Show Gist options
  • Save GaryJones/10503607 to your computer and use it in GitHub Desktop.
Save GaryJones/10503607 to your computer and use it in GitHub Desktop.
JavaScript module template for plugins
/* global myPluginL10n */
var myPlugin = ( function ( $ ) {
function myPrivateFunction() {
}
function getStuff( id ) { // Private function
var jqxhr = $.get( myPlugin.ajax_url + '?x=y&id=' + id );
jqxhr.done( function ( data ) {
var results = data.split( ';' );
//...
});
}
function ready() { // Private function...
getStuff( 1 );
// Bind things
$( '#foo' ).on( 'change.my-plugin', myPrivateFunction );
}
return {
ready: ready // Expose private function to be public
};
})( jQuery );
jQuery( myPlugin.ready );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment