layui 左侧导航生成tab
layui.define(['jquery', 'element'], function(exports) {
var $ = layui.jquery,
element = layui.element,
device = layui.device(),
tabMenu = function() {
this.config = {
item: '#WeTabTip',
closed: true
};
},
objTab = {};
/**
* [参数设置 options]
*/
tabMenu.prototype.set = function(options) {
if (typeof(options) == 'string' && options != "") {
this.config.item = options;
} else if (typeof(options) == 'object') {
$.extend(true, this.config, options);
}
return this;
};
/**
*@todo 初始化对象
*@return 返回对象参数初始化结果
*/
tabMenu.prototype.init = function(options) {
var _this = this,
config = _this.config,
$container = $('' + config.item + ''),
filter = $container.attr('lay-filter');
if (filter === undefined || filter === '') {
console.log('错误:请设置Tab菜单选项卡属性lay-filter过滤器');
}
objTab.titleBox = $container.children('ul.layui-tab-title');
objTab.contentBox = $container.children('div.layui-tab-content');
objTab.tabFilter = filter;
_this.hideRightMenu();
_this.drag();
return _this;
}
/**
*@todo 检查页面是否已打开,如果已打开则返回索引值,否则返回-1
*@param string title 打开页面的标题
*@return int tab的索引值,元则返回-1
*/
tabMenu.prototype.exited = function(title) {
var tab_index = -1;
if (objTab.titleBox === undefined) {
this.init()
}
objTab.titleBox.find('li').each(function(i, e) {
var $em = $(this).children('em');
if ($em.text() === title) {
tab_index = $(this).attr('lay-id');
};
});
return tab_index;
}
/**
* 菜单操作的接口
*/
tabMenu.prototype.beforeTabAdd = function(data, _this) {}
tabMenu.prototype.changeTab = function(data, _this, tab_index) {}
tabMenu.prototype.afterTabClose = function(data, _this) {}
/**
*@todo 添加tab菜单选项卡
*@param object data [ title 菜单选项卡标题
,href 菜单URL地址
,icon 菜单的ICON图标
]
*/
tabMenu.prototype.tabAdd = function(data, fresh) {
var tab_index = this.exited(data.title),
_this = this;
if (tab_index === -1) {
_this.beforeTabAdd(data, _this);
var layID = data.layId ? data.layId : new Date().getTime();
var content = '<iframe src="' + data.href + '" data-id="' + layID + '" class="jqadmin-iframe"></iframe>';
var title = '';
// 如果icon有定义则添加到标题中
if (!_this.config.showIcon) {
title += '<i class="iconfont hide-icon">' + data.icon + '</i>';
} else {
title += '<i class=&#