Skip to content

Instantly share code, notes, and snippets.

@Swivelgames
Last active September 11, 2015 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swivelgames/1ceaac67ac95a85f8619 to your computer and use it in GitHub Desktop.
Save Swivelgames/1ceaac67ac95a85f8619 to your computer and use it in GitHub Desktop.
jQuery Plugin
;(function($,window,document,undefined) {
var PluginConfig = {
"name": "PluginName",
"defaults": {
"propertyName": "value"
}
};
var Plugin = function(element, options) {
this.settings = $.extend( {}, this._defaults, options );
this.element = element;
this.init();
};
$.extend(Plugin.prototype, {
_name: PluginConfig.name,
_defaults: PluginConfig.defaults,
init: function() {
console.log("meow");
this.anotherMethod();
},
anotherMethod: function() {
console.log(this.element);
}
});
// Selector Passed!
$.fn[ PluginConfig.name ] = function(options) {
this.each(function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
}
});
// chain jQuery functions
return this;
};
// No Selector Passed!
$[ PluginConfig.name ] = function(options) {
return 'foobar';
};
})( jQuery, window, document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment