Created
May 13, 2011 02:50
-
-
Save hiromitz/969884 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
This file contains 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($) { | |
var pluginName = 'myPlugin'; | |
$[pluginName] = function(el, op) { | |
this.options = op = $.extend({}, { | |
// default options here | |
}, op); | |
this.el = el; | |
}; | |
$[pluginName].prototype = { | |
methodName: function() { return this; } | |
}; | |
$.fn[pluginName] = function( method, options ) { | |
if(typeof method === "object") { | |
options = method; | |
method = null; | |
} | |
var res; | |
this.each(function() { | |
var inst = $.data(this, pluginName) || $.data(this, pluginName, new $[pluginName](this, options)); | |
if(method) { | |
res = inst[method](options); | |
} | |
}); | |
return res || this; | |
}; | |
}(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment