Created
July 2, 2012 16:32
-
-
Save interfeis/3034121 to your computer and use it in GitHub Desktop.
jQuery plugin boilerplate
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
(function($){ | |
$.fn.extend({ | |
//plugin name | |
pluginName: function(method) { | |
var methods = { | |
init : function(options) { | |
var defaults = { | |
color: '#333333' | |
//more default options | |
//... | |
}; | |
//map defaults and options | |
var options = $.extend(defaults, options); | |
return this.each(function() { | |
var o = options, | |
obj = $(this), | |
$labels = $("label", obj); | |
//more cached selectors | |
//... | |
//apply options | |
$labels.css({'color': o.color}); | |
//... | |
//more logic, animations, etc | |
//... | |
});//this.each | |
},//init | |
//more functions | |
//.. | |
destroy : function( ) { | |
//destroy logic | |
}//destroy | |
};//methods | |
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 on this plugin' ); | |
} | |
}//pluginName | |
});//$.fn.extend | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment