Last active
August 29, 2015 13:59
-
-
Save GaryJones/10503607 to your computer and use it in GitHub Desktop.
JavaScript module template for plugins
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
/* 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