var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; }; if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } } { let window = _____WB$wombat$assign$function_____("window"); let self = _____WB$wombat$assign$function_____("self"); let document = _____WB$wombat$assign$function_____("document"); let location = _____WB$wombat$assign$function_____("location"); let top = _____WB$wombat$assign$function_____("top"); let parent = _____WB$wombat$assign$function_____("parent"); let frames = _____WB$wombat$assign$function_____("frames"); let opener = _____WB$wombat$assign$function_____("opener"); $c.fn.tabs = function (config) { var obj = function (selector, config) { this.selector = selector; this.config = $.extendEx({}, this.defConfig, config); } obj.prototype.tabs = function () { var _obj = this; if (_obj.selector.find('.kui-tabs-head').length == 0) { _obj.create(); } else { var tabList = _obj.getTabs(); $.each(tabList, function (i,o) { var titlePart = o.titlePart; var contentPart = o.contentPart; var tab = { id: o.titlePart.attr('id'), title: titlePart.find('>span').html(), content: contentPart.html() }; titlePart[0].tab = tab; }); } _obj._addEvents(); } obj.prototype.getTab = function (id) { var _obj=this; var result = null; $.each(_obj.selector.find('.kui-tabs-title'), function (i, o) { if (o.id == id) { result = { titlePart: $(o) }; } }); $.each(_obj.selector.find('.kui-tabs-content'), function (i, o) { if (o.id == id) { result.contentPart = $(o); } }); return result; } obj.prototype.update = function (id, tab) { var result = _obj.getTab(id); if (!result) { return; } var titlePart = result.titlePart; var contentPart = result.contentPart; contentPart[0].isLoaded = false; tab.id = id; titlePart[0].tab = tab; if (tab.title) { titlePart.find('span').html(tab.title); } } obj.prototype.select = function (id) { var _obj = this; var result = _obj.getTab(id); if (!result) { return result; } _obj.selector.find('.kui-tabs-title,.kui-tabs-content').removeClass('kui-selected'); var titlePart = result.titlePart; var contentPart = result.contentPart; titlePart.addClass('kui-selected'); contentPart.addClass('kui-selected'); if (contentPart[0].isLoaded) { return; } contentPart[0].isLoaded = true; //contentPart 可见之后,才设置内容,因为如果是隐藏的,会出现一些问题,比如: $('#test').css('border-left-width')为undefined. var tab = titlePart[0].tab; if (!tab.content) { tab.content = ''; } if ($.isFunction(tab.content)) { contentPart.html(tab.content()); } else if (tab.content.indexOf('url:') == 0) { var loadingIndex = 0; if (tab.showLoading == true && window.kwindow) { loadingIndex = kwindow.loading(tab.loadingConfig); } content = '' tab.style = $.extendEx({}, { overflow: 'hidden' }, tab.style); contentPart.html(content); } else if (tab.content.indexOf('ajax-get:') == 0) { var url = tab.content.substr(9); var loadingIndex = 0; if (tab.showLoading == true) { loadingIndex = kwindow.loading(tab.loadingConfig); } $.get(url, function (data, status) { kwindow.close(loadingIndex); contentPart.html(data); }); } else if (tab.content.indexOf('ajax-post:') == 0) { var url = tab.content.substr(10); var loadingIndex = 0; if (tab.showLoading == true) { loadingIndex = kwindow.loading(tab.loadingConfig); } $.post(url, {}, function (data, status) { kwindow.close(loadingIndex); contentPart.html(data); }); } else { contentPart.html(tab.content); } return result; } obj.prototype.getTabs = function () { var _obj = this; var tabList = []; $.each(_obj.selector.find('.kui-tabs-title'), function (i, o) { var _tab = { titlePart: $(o), contentPart: _obj.selector.find('.kui-tabs-content:eq('+i+')') }; tabList.push(_tab); }); return tabList; } obj.prototype._addEvents = function () { var _obj = this; var tabList = _obj.getTabs(); $.each(tabList, function (i,o) { var titlePart = o.titlePart; //var tab = titlePart[0].tab; var contentPart = o.contentPart; titlePart.on(_obj.config.switchEvent, function () { if (contentPart.is(':hidden')) { _obj.select(this.id); } }); titlePart.find('.icon-close').click(function () { titlePart.remove(); contentPart.remove(); }); }); } obj.prototype.add = function (tab) { var _obj = this; var headPart = _obj.selector.find('.kui-tabs-head'); var bodyPart = _obj.selector.find('.kui-tabs-body'); var titlePart = $('').appendTo(headPart); var textPart = $('' + tab.title + '').appendTo(titlePart); var closePart = $('').appendTo(titlePart); var contentPart = $('
').appendTo(bodyPart); titlePart[0].id = tab.id; contentPart[0].id = tab.id; titlePart[0].tab = tab; titlePart.setStyle($.extendEx({}, _obj.config.titlePartStyle, tab.titlePartStyle)); textPart.setStyle($.extendEx({}, _obj.config.textPartStyle, tab.textPartStyle)); closePart.setStyle($.extendEx({}, _obj.config.closePartStyle, tab.closePartStyle)); contentPart.setStyle($.extendEx({}, _obj.config.contentPartStyle, tab.contentPartStyle)); headPart.find('.kui-tabs-head-clear').remove(); headPart.append('
'); return {titlePart:titlePart,contentPart:contentPart}; } obj.prototype.create = function () { var _obj = this; _obj.selector.addClass('kui-tabs'); var headPart = $('
').appendTo(_obj.selector); var spacePart = $('
').appendTo(_obj.selector); var bodyPart = $('
').appendTo(_obj.selector); $.each(this.config.tabs, function (i, tab) { var ret = _obj.add(tab); if (i == 0) { ret.titlePart.addClass('kui-first'); } if(i==_obj.config.tabs.length-1) { ret.titlePart.addClass('kui-last'); } }); if (_obj.config.tabs.length > 0) { _obj.select(_obj.config.tabs[0].id); } _obj.selector.setStyle(this.config.style); headPart.setStyle(this.config.headPartStyle); spacePart.setStyle(this.config.spacePartStyle); bodyPart.setStyle(this.config.bodyPartStyle); } obj.prototype.defConfig = { switchEvent: 'click' } obj.prototype._autoHeight = function () { var headHeight = _obj.selector.find('.kui-tabs-head').height(); _obj.selector.find('.kui-tabs-body').height(_obj.selector.height() - headHeight);; } var _obj = new obj($(this.jo), config || {}); _obj.tabs(); _obj._autoHeight(); $(window).resize(function () { _obj._autoHeight(); }); return _obj; }; /*自动化操作*/ $(function () { $.each($('body').find('.kui-tabs'), function (i, o) { $c(o).tabs(); }); }); }