better jquery plugin template


/ Published in: jQuery
Save to your folder(s)

Following these docs: http://docs.jquery.com/Plugins/Authoring


Copy this code and paste it in your HTML
  1. (function($){
  2.  
  3. var environment = {};
  4.  
  5. var methods = {
  6. init:function(options) {
  7.  
  8. var options = $.extend({}, options);
  9.  
  10. return this.each(function() {
  11.  
  12. });
  13.  
  14. }
  15. };
  16.  
  17. $.fn.pluginName = function(method){
  18. if ( methods[method] ) {
  19. return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
  20. } else if ( typeof method === 'object' || ! method ) {
  21. return methods.init.apply( this, arguments );
  22. } else {
  23. $.error( 'Method ' + method + ' does not exist on jQuery.pluginName' );
  24. }
  25. };
  26. })(jQuery);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.