Posted By

rickygri on 12/14/12


Tagged

plugin template jquery


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

swapnilgg
pibot77
lionminister


jQuery Plugin Template


 / Published in: jQuery
 

This is a skeleton template for a jquery plugin with custom methods

  1. /*
  2.  * jQuery Plugin Template
  3.  * Rickygri
  4.  */
  5. (function ($) {
  6. var defaults = {
  7. // total: 5
  8. };
  9. var options = $.extend(defaults, options);
  10. var o = options;
  11. var methods = {
  12. init: function () {
  13.  
  14. },
  15. fire: function () {
  16.  
  17. }
  18. };
  19. $.fn.popUp = function (methodOrOptions) {
  20. if (methods[methodOrOptions]) {
  21. return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1))
  22. } else if (typeof methodOrOptions === 'object' || !methodOrOptions) {
  23. return methods.init.apply(this, arguments)
  24. } else {
  25. $.error('Method ' + method + ' does not exist');
  26. }
  27. }
  28. })(jQuery);
  29.  
  30. // Use custom methods
  31. $(".elem").click(function() {
  32. $(this).popUp('fire');
  33. });

Report this snippet  

You need to login to post a comment.