Jquery set defaults for all instances of a plugin

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-06-18T15:58:41Z Indexed on 2010/06/18 16:03 UTC
Read the original article Hit count: 260

Filed under:

Given the following plugin how would you set defaults for all the instances? I would like it to work the same as $.datepicker.setDefaults().

(function ($) {
$.fn.borderSwitcher = function (options) {
    defaults = {
        borderColor: 'Black',
        borderWidth: '1px',
        borderStyle: 'solid'
    };

    return this.each(function () {

        var settings = $.extend(defaults, options);

        $(this).focus(function () {
            //find a better way to set border properties
            var props = settings.borderStyle + ' ' + settings.borderWidth + ' ' + settings.borderColor;
            $(this).css('border', props);
        });

        $(this).blur(function () {
            $(this).css('border', '');
        });
    });
};

})(jQuery);

© Stack Overflow or respective owner

Related posts about jquery-plugins