扩展jquery.fn,增加获取或设置zIndex的function

/*扩展 jQuery.fn 的方法*/
jQuery.fn.extend({
    /*
    获取或设置zIndex
    */
    zIndex: function (zIndex) {
        if (zIndex !== undefined) {
            return this.css("zIndex", zIndex);
        }
        if (this.length) {
            var elem = $(this[0]), position, value;
            while (elem.length && elem[0] !== document) {
                // Ignore z-index if position is set to a value where z-index is ignored by the browser
                // This makes behavior of this function consistent across browsers
                // WebKit always returns auto if the element is positioned
                position = elem.css("position");
                if (position === "absolute" || position === "relative" || position === "fixed") {
                    // IE returns 0 when zIndex is not specified
                    // other browsers return a string
                    // we ignore the case of nested elements with an explicit value of 0
                    // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
                    value = parseInt(elem.css("zIndex"), 10);
                    if (!isNaN(value) && value !== 0) {
                        return value;
                    }
                }
                elem = elem.parent();
            }
        }
        return 0;
    }
});

if (jQuery.datepicker) {
    jQuery.datepicker.setDefaults({
        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
        dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
        dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
        weekHeader: '周',
        nextText: '下月&#x3e',
        prevText: '&#x3c上月',
        closeText: '完成',
        currentText: '今天',
        yearSuffix: '年'
    });
}

/*扩展 jQuery.browser 的属性*/
if (!jQuery.browser) {
    jQuery.browser = {};
}
jQuery.extend(jQuery.browser, {
    /*检查浏览器是否支持CSS3*/
    css3: (function () {
        var css3Div = document.createElement('div');
        if ('border-radius' in css3Div.style) {
            css3Div.style['border-radius'] = '3px';
            return css3Div.style['border-radius'] == '3px';
        }
        else {
            return false;
        }
    })(),
    /*检查浏览器是否支持HTML5*/
    html5: (function () {
        return !!document.createElement('canvas').getContext;
    })()
});
jQuery.widget("ui.tabs", $.ui.tabs, {
    addTab: function (options) {
        var _self = this;
        options = $.extend({
            title: 'New Tab', //标题
            content: '', //内容
            id: 'tab_' + new Date().getTime(), //Id
            enableClose: true, //是否允许关闭
            activate: true //是否激活
        }, options || {});

        var id = "tabs-" + options.id;
        var tab = this.element.find('.ui-tabs-nav li[aria-controls="' + id + '"]');
        if (tab.length < 1) {
            var _li = $('<li></li>').append($('<a></a>').attr('href', '#' + id).html(options.title));
            this.element.find(".ui-tabs-nav").append(_li);
            var _div = $('<div></div>');
            _div.attr('id', id);
            _div.append(options.content);
            this.element.append(_div);
            if (options.enableClose) {
                var _closeBtn = $('<span class="ui-icon ui-icon-close" role="presentation" title="关闭"></span>').click(function () {
                    var _this = $(this);
                    var panelId = _li.remove().attr("aria-controls");
                    $("#" + panelId).remove();
                    if (_li.hasClass('ui-tabs-active')) {
                        _self.element.tabs('option', 'active', _self.element.find(".ui-tabs-nav li").length - 1);
                    }
                });
                _li.append(_closeBtn);
            }
            this.refresh();
            if (options.activate) {
                this._activate(this.element.find(".ui-tabs-nav li").length - 1);
            }
            //解决不支持css3的浏览器问题
            if (!$.browser.css3) {
                _div.height(this.element.innerHeight() - this.element.css('padding-top').replace('px', '') - this.element.find(".ui-tabs-nav").outerHeight(true) - Math.mul(_div.css('margin-top').replace('px', ''), 2));
            }
        } else if (options.activate) {
            var activeIndex = this.element.find(".ui-tabs-nav li").index(tab);
            this._activate(activeIndex);
        }
    }
});