access settings from whole jquery component

Posted by Pacuraru Daniel on Stack Overflow See other posts from Stack Overflow or by Pacuraru Daniel
Published on 2012-03-31T19:44:31Z Indexed on 2012/03/31 23:28 UTC
Read the original article Hit count: 224

Filed under:
|
|
|
|

I am trying to develop a jquery component for dialog modals and i dont know how to access the settings from all component functions. I need to access settings,zIndex from open function and it seems to not work.

(function($) {

    var methods = {

        init: function(options) {

            var defaults = {
                bgClass: "fancy-dialog-bg",
                bgShow: null,
                zIndex: 100,
                show: null
            };
            var settings = $.extend(defaults, options);

            return this.each(function() {
                var obj = $(this).hide().css("position", "fixed").css("z-index", settings.zIndex).css("left", "300px").css("top", "200px");
            });

        },

        open: function() {
                    // alert(settings.zIndex); not working
            var tes = $("<div></div>").css("backgroundColor", "#f00").css("position", "fixed").css("z-index", "99").css("width", "50%").css("height", "100%").css("left", "0").css("top", "0");
            $('body').append(tes);
            var obj = $(this);
            obj.show();

        },

        close: function() {

            var obj = $(this);
            $("#fancy-dialog-bg-" + obj.attr('id')).remove();
            obj.hide();

        }

    };

    $.fn.fancyDialog = function(method) {

        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.');
        }

    };

})(jQuery);

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about settings