forked from jquery/jquery-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.ya.tabs0.js
More file actions
104 lines (94 loc) · 2.79 KB
/
jquery.ya.tabs0.js
File metadata and controls
104 lines (94 loc) · 2.79 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
/**
* @author 13
*/
(function($,root){
var ya=root.ya,
sl=ya.sl,
uihelper=ya.uihelper,
Solution=sl.Solution;
var Base=$.ui.tabs;
$.widget('ya.tabs0',Base,{
options: {
closable:false,
advancedTheme:{ //设置widget的高级主题效果
shadow:false, //设置背景阴影,默认不存在
corner:false
}
},
_create:function(){
var self=this;
var element=self.element,
options=self.options,
advancedTheme=options.advancedTheme;
if(options.closable){
options.tabTemplate='<li><a href="#{href}">#{label}</a><span class="ui-icon ui-icon-close">Remove Tab</span>';
element.on('click','.ui-icon-close',function(){
var thisJq=$(this);
var headerListJq=self.lis,
curHeaderJq=thisJq.parent();
var index = headerListJq.index(curHeaderJq);
self.remove(index);
});
}
Base.prototype._create.call(self);
var listJq=self.list;
if(options.closable){
listJq.addClass('ui-tabs-nav-closable');
}
if(advancedTheme){
for(var n in advancedTheme){
if(advancedTheme[n]){
uihelper.advancedThemeH(self,n,self.element);
}
}
}
//nav item顶部圆角
uihelper.advancedThemeH(self,'corner',self.lis);
},
/**
* 添加一个新的tab
*
* @override
*/
add: function( url, label, index ) {
if ( index === undefined ) {
index = this.anchors.length;
}
var self = this,
o = this.options,
$li = $( o.tabTemplate.replace( /#\{href\}/g, url ).replace( /#\{label\}/g, label ) ),
id = !url.indexOf( "#" ) ? url.replace( "#", "" ) : this._tabId( $( "a", $li )[ 0 ] );
$li.addClass( "ui-state-default ui-corner-top" ).data( "destroy.tabs", true );
// try to find an existing element before creating a new one
var $panel = self.element.find( "#" + id );
if ( !$panel.length ) {
$panel = $( o.panelTemplate )
.attr( "id", id )
.data( "destroy.tabs", true );
}
$panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" );
if ( index >= this.lis.length ) {
$li.appendTo( this.list );
$panel.appendTo( this.panels[ 0 ].parentNode ); //this.list改为this.panels
} else {
$li.insertBefore( this.lis[ index ] );
$panel.insertBefore( this.panels[ index ] );
}
o.disabled = $.map( o.disabled, function( n, i ) {
return n >= index ? ++n : n;
});
this._tabify();
if ( this.anchors.length == 1 ) {
o.selected = 0;
$li.addClass( "ui-tabs-selected ui-state-active" );
$panel.removeClass( "ui-tabs-hide" );
this.element.queue( "tabs", function() {
self._trigger( "show", null, self._ui( self.anchors[ 0 ], self.panels[ 0 ] ) );
});
this.load( 0 );
}
this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
return this;
}
});
}(jQuery,this));