RSS
 

jQuery Plugin Template

19 Apr

Here my simple and short jQuery plugin template. Hope it helps with plugin development. It has all the recommended settings (from docs.jquery.com/Plugins/Authoring):

(function($) {
    $.fn.pluginNamespace = function(method) {
        var defaults = {
                // settings here
            },
            settings = null,
            methods = {
                init: function(options) {
                    settings = $.extend(defaults, options);
                }
            };
        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 jQuery.tooltip' );
        }
    };
})(jQuery);
 
 

Leave a Reply