Posted By

nikefido on 04/16/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

AllKnightAccess


better jquery plugin template


 / Published in: jQuery
 

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

  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  

You need to login to post a comment.