Skip to content

Instantly share code, notes, and snippets.

@jennschiffer
Created August 7, 2013 04:06
Show Gist options
  • Save jennschiffer/15d5b1f6c21f6e37ca9a to your computer and use it in GitHub Desktop.
Save jennschiffer/15d5b1f6c21f6e37ca9a to your computer and use it in GitHub Desktop.
jquery plugin skelly
/**
* a jquery plugin
* by jenn schiffer
*/
(function($) {
var pluginName = 'pluginName';
var defaults = {
};
var methods = {
init : function (opts) {
return this.each(function() {
var $this = $(this).addClass(pluginName);
var options = $.extend(defaults, opts);
var data = {
$this : $this,
};
$this.data(pluginName, data);
});
},
exampleFunction : function () {
var $this = $(this).addClass(hiddenClass);
var data = $this.data(pluginName);
// do something
},
};
/*** MODULE DEFINITION ***/
$.fn[pluginName] = function (method) {
if ( methods[method] ) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this,arguments);
} else {
$.error('Method ' + method + ' does not exist');
}
};
/*** EVENTS HANDLERS ***/
/*** GLOBAL EVENTS ***/
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment