Skip to content

Instantly share code, notes, and snippets.

@alexanmtz
Created July 24, 2012 00:31
Show Gist options
  • Save alexanmtz/3167160 to your computer and use it in GitHub Desktop.
Save alexanmtz/3167160 to your computer and use it in GitHub Desktop.
A basic jQuery plugin file
;(function ( $, window, document, undefined ) {
// Create the defaults once
var pluginName = 'defaultPluginName',
defaults = {
propertyName: "value"
};
// The actual plugin constructor
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function() {
this.yourOtherFunction(this.element, this.options).
},
yourOtherFunction: function(el, options) {
// some logic
}
};
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName,
new Plugin( this, options ));
}
});
}
})( jQuery, window, document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment