-
-
Save ryanfitzer/1372424 to your computer and use it in GitHub Desktop.
possible jquery plugin boilerplate
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
!function( root, factory ) { | |
// Export | |
if ( typeof exports === 'object' ) { | |
// Node/CommonJS | |
factory( require( 'jquery' ) ); | |
} else if ( typeof define === 'function' && define.amd ) { | |
// AMD. Use a named plugin in case this | |
// file is loaded outside an AMD loader, | |
// but an AMD loader lives on the page. | |
define( 'myPlugin', [ 'jquery' ], factory ); | |
} else { | |
// Browser globals | |
factory( root.jQuery ); | |
} | |
}( this, function( $ ) { | |
// Plugin constructor | |
$.MyPlugin = function( element, options ) {}; | |
// Plugin prototype | |
$.MyPlugin.prototype = {}; | |
// Plugin to jQuery's prototype | |
$.fn.myPlugin = function( options ) { | |
// New instance for each element in the collection. | |
return this.each( function() { | |
new $.MyPlugin( this, options ); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edited based on my response to the original gist.