forked from andrewwatts/ui.tabs.closable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.tabs.closable.js
60 lines (50 loc) · 2 KB
/
ui.tabs.closable.js
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
/*!
* Copyright (c) 2010 Andrew Watts
*
* Dual licensed under the MIT (MIT_LICENSE.txt)
* and GPL (GPL_LICENSE.txt) licenses
*
* http://github.com/andrewwatts/ui.tabs.closable
*/
(function() {
var ui_tabs_tabify = $.ui.tabs.prototype._tabify;
$.extend($.ui.tabs.prototype, {
_tabify: function() {
var self = this;
ui_tabs_tabify.apply(this, arguments);
// if closable tabs are enable, add a close button
if (self.options.closable === true) {
var unclosable_lis = this.lis.filter(function() {
// return the lis that do not have a close button
return $('span.ui-icon-circle-close', this).length === 0;
});
// append the close button and associated events
unclosable_lis.each(function() {
$(this)
.append('<a href="#"><span class="ui-icon ui-icon-circle-close"></span></a>')
.find('a:last')
.hover(
function() {
$(this).css('cursor', 'pointer');
},
function() {
$(this).css('cursor', 'default');
}
)
.click(function() {
var index = self.lis.index($(this).parent());
if (index > -1) {
// call _trigger to see if remove is allowed
if (false === self._trigger("closableClick", null, self._ui( $(self.lis[index]).find( "a" )[ 0 ], self.panels[index] ))) return;
// remove this tab
self.remove(index)
}
// don't follow the link
return false;
})
.end();
});
}
}
});
})(jQuery);