Created
August 7, 2013 04:06
-
-
Save jennschiffer/15d5b1f6c21f6e37ca9a to your computer and use it in GitHub Desktop.
jquery plugin skelly
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
/** | |
* 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