/ Published in: jQuery
This is a skeleton template for a jquery plugin with custom methods
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * jQuery Plugin Template * Rickygri */ (function ($) { var defaults = { // total: 5 }; var options = $.extend(defaults, options); var o = options; var methods = { init: function () { }, fire: function () { } }; $.fn.popUp = function (methodOrOptions) { if (methods[methodOrOptions]) { return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1)) } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { return methods.init.apply(this, arguments) } else { $.error('Method ' + method + ' does not exist'); } } })(jQuery); // Use custom methods $(".elem").click(function() { $(this).popUp('fire'); });