easyui.hp.myTabs.js
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* 显示一个tab 继承与easyui的tabs
* 可以右键点击tab头,来实现关闭和选择tab功能,还可以选择最大化tab页
* 作者:黄平
* 日期:2014-05-15
*/
(function($) {
$.fn.myTabs = function(options, param) {
var self = this;
if (typeof (options) == "string") {
var method = $.fn.myTabs.methods[options];
if (method) {
return method.call(this, param);
} else {
return this.tabs(options, param);
}
}
return this.each(function() {
var opt = $.extend({}, $.fn.myTabs.defaults, options, {
onContextMenu : function(e, title,index) {
if (options.onContextMenu) {
options.onContextMenu(e, title, index);
}
$(self).tabs("select", index);
}
});
$(self).tabs(opt);
var menu = $("<div>");
menu.menu({
hideOnUnhover : false,
onClick : function(item) {
if (!item.onclick) {
$(self).tabs("select", item.text);
}
}
});
menu.menu("appendItem", {
text : "关闭",
iconCls : "icon-cancel",
onclick : function() {
$(self).tabs("close", $(self).tabs("getSelected").panel("options").title);
}
}).menu("appendItem", {
text : "关闭其他",
iconCls : "icon-cancel",
onclick : function() {
var tab = $(self).tabs("tabs");
var selectTab = $(self).tabs("getSelected").panel("options");
var o = null;
for (var i = 0; i < tab.length; i++) {
o = tab[i].panel("options");
if (selectTab.title == o.title) {
continue;
}
if (o.closable) {
$(self).tabs("close", o.title);
i--;
}
}
}
}).menu("appendItem", {
text : "关闭全部",
iconCls : "icon-cancel",
onclick : function() {
var tab = $(self).tabs("tabs");
var selectTab = $(self).tabs("getSelected").panel("options");
var o = null;
for (var i = 0; i < tab.length; i++) {
o = tab[i].panel("options");
if (o.closable) {
$(self).tabs("close", o.title);
i--;
}
}
}
});
if (opt.maxSizeAble === true) {
menu.menu("appendItem", {
text : "最大化",
iconCls : "icon-more",
onclick : function() {
var selectPanel = $(self).tabs("getSelected");
var div = $("<div>").appendTo($(window.top.document.body));
window.top.$(div).window({
width : "100%",
height : "100%",
title : selectPanel.panel("options").title,
content : selectPanel.html(),
modal : true,
collapsible : true,
cache : false
});
}
});
}
menu.menu("appendItem", {
separator : true
});
$(".tabs-header", self).bind("contextmenu", function(e1) {
e1.preventDefault();
var tab = $(self).tabs("tabs");
var selectTab = $(self).tabs("getSelected").panel("options");
var closeMenu = menu.menu("findItem", "关闭");
if (selectTab.closable) {
menu.menu("enableItem", closeMenu.target);
} else {
menu.menu("disableItem", closeMenu.target);
}
var parentMenu = menu.menu("findItem", "选择标签");
if (parentMenu) {
menu.menu("removeItem", parentMenu.target);
}
menu.menu("appendItem", {
text : "选择标签",
iconCls : "icon-ok"
});
parentMenu = menu.menu("findItem", "选择标签");
var o;
for (var i = 0; i < tab.length; i++) {
o = tab[i].panel("options");
menu.menu("appendItem", {
parent : parentMenu.target,
text : o.title,
disabled : o.title == selectTab.title ? true : false,
iconCls : "icon-tip"
});
}
menu.menu("show", {
left : e1.clientX,
top : e1.clientY
});
});
});
};
$.fn.myTabs.methods = {
};
$.fn.myTabs.events = {
};
$.fn.myTabs.defaults = $.extend({}, $.fn.myTabs.events, {
maxSizeAble : false
});
})(jQuery);