Created
March 1, 2012 00:53
-
-
Save Mr2P/1946308 to your computer and use it in GitHub Desktop.
jQuery plugin boilerplate based on Jeffrey Way's work
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
| // polyfill for unsupported browsers | |
| if( Object.create !== 'function'){ | |
| Object.create = function (o){ | |
| function F(){}; | |
| F.prototype = o; | |
| return new F(); | |
| } | |
| } | |
| (function($, window, document, undefined){ | |
| var PluginObj = { | |
| init: function(options, elem){ | |
| var self = this; | |
| self.elem = elem; | |
| self.$elem = $(elem); | |
| self.options = $.extend({}, $.fn.pluginName.options, options); | |
| // TODO: call main excute method | |
| }, | |
| // TODO: create internal method for PluginObj | |
| }; | |
| $.fn.pluginName = function (options){ | |
| return this.each(function(){ | |
| $.data(this, 'pluginName', Object.create(PluginObj).init(options, this)); | |
| }); | |
| }; | |
| $.fn.pluginName.options = {}; | |
| })(jQuery, window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good!