@@ -11,7 +11,7 @@ export const Api = function (options) {
11
11
const arg = arguments ;
12
12
this . _setOptions ( arg [ 1 ] ) ;
13
13
this . _tablistEl = null ;
14
- const { getElManagementIns} = arg [ 0 ] ( ) ;
14
+ const { getElManagementIns } = arg [ 0 ] ( ) ;
15
15
this . _getElManagementIns = getElManagementIns ;
16
16
this . _tabs = null ;
17
17
this . _tabsCount = null ;
@@ -63,11 +63,11 @@ Api.prototype = {
63
63
_hideTabs : function ( firstHiddenTabIndex , selectedTabInfo , includeSelectedTab ) {
64
64
const hiddenTabs = [ ] ;
65
65
this . _options . containerElement . style . display = 'none' ;
66
- const { index : selectedTabIndex } = selectedTabInfo ;
66
+ const { index : selectedTabIndex } = selectedTabInfo ;
67
67
for ( let i = firstHiddenTabIndex , tabsCount = this . _tabsCount ; i < tabsCount ; i ++ ) {
68
68
if ( includeSelectedTab || i !== selectedTabIndex ) {
69
69
this . _tabs [ i ] . style . display = 'none' ;
70
- hiddenTabs . push ( { el : this . _tabs [ i ] , index : i } ) ;
70
+ hiddenTabs . push ( { el : this . _tabs [ i ] , index : i } ) ;
71
71
}
72
72
}
73
73
this . _showBtn ( ) ;
@@ -78,10 +78,13 @@ Api.prototype = {
78
78
const index = selectedTabIndex ;
79
79
const el = index >= 0 ? tabs [ index ] : null ;
80
80
const overflow = el
81
- ? this . els . getDistance ( el ) . sub ( this . els . getEl ( this . _options . buttonElement ) . getFullSize ( ) ) . value <= 0
81
+ ? this . els
82
+ . getDistance ( el )
83
+ . sub ( this . els . getEl ( this . _options . tablistElement ) . getSpacing ( this . _btnPositionRelativeToTablist ) )
84
+ . sub ( this . els . getEl ( this . _options . buttonElement ) . getFullSize ( ) ) . value <= 0
82
85
: false ;
83
86
const overflowFullSize = overflow ? this . els . getEl ( el ) . getFullSize ( ) : 0 ;
84
- return { index, overflowFullSize} ;
87
+ return { index, overflowFullSize } ;
85
88
} ,
86
89
_validateTabsCount : function ( ) {
87
90
this . _tabs = this . _tablistEl . children ;
@@ -109,32 +112,34 @@ Api.prototype = {
109
112
if ( this . _checkOverflow ( _lastTab ) === false ) {
110
113
return [ ] ;
111
114
}
112
- const selectedTabInfo = this . _getSelectedTabInfo ( this . _tabs , selectedTabIndex ) ;
115
+ const selectedTabInfo = this . _setBtnPositionRelativeToTablist ( isVertical , direction ) . _getSelectedTabInfo ( this . _tabs , selectedTabIndex ) ;
113
116
return this . _validateSliderMinSize ( selectedTabInfo )
114
117
? this . _hideTabs (
115
- this . _findFirstHiddenTabIndexFactory (
116
- selectedTabInfo ,
117
- this . _getSearchBoundries ( selectedTabInfo ) ,
118
- this . _getOrder ( _lastTab ) ,
119
- ) ,
118
+ this . _findFirstHiddenTabIndexFactory (
120
119
selectedTabInfo ,
121
- )
120
+ this . _getSearchBoundries ( selectedTabInfo ) ,
121
+ this . _getOrder ( this . _tabs [ 0 ] , _lastTab ) ,
122
+ ) ,
123
+ selectedTabInfo ,
124
+ )
122
125
: this . _hideTabs ( 0 , selectedTabInfo , true ) ;
123
126
} ,
124
127
_validateSliderMinSize : function ( selectedTabInfo ) {
125
- //available and visiable space in the tablist element should be greater than size of selected tab + more button
126
- return selectedTabInfo . overflowFullSize + this . els . getEl ( this . _options . buttonElement ) . getFullSize ( ) >=
127
- this . els . getVisibleSize ( this . _options . tablistElement ) . value
128
+ return this . els . getEl ( this . _options . tablistElement ) . getSpacing ( this . _btnReversePositionRelativeToTablist ) +
129
+ selectedTabInfo . overflowFullSize +
130
+ this . els . getEl ( this . _options . tablistElement ) . getSpacing ( this . _btnPositionRelativeToTablist ) +
131
+ this . els . getEl ( this . _options . buttonElement ) . getFullSize ( ) >=
132
+ this . els . getEl ( this . _options . containerElement ) . getSize ( )
128
133
? false
129
134
: true ;
130
135
} ,
131
- _getOrder : function ( lastTab ) {
132
- return Math . abs ( this . els . getDistance ( lastTab ) . value ) > this . els . getVisibleSize ( this . _options . tablistElement ) . value
136
+ _getOrder : function ( firstTab , lastTab ) {
137
+ return Math . abs ( this . els . getDistance ( lastTab ) . value ) > Math . abs ( this . els . getDistance ( firstTab ) . value )
133
138
? 'asc'
134
139
: 'desc' ;
135
140
} ,
136
141
_getSearchBoundries : function ( selectedTabInfo ) {
137
- const { overflowFullSize, index : pivotIndex } = selectedTabInfo ;
142
+ const { overflowFullSize, index : pivotIndex } = selectedTabInfo ;
138
143
//if selected tab is not existed
139
144
if ( pivotIndex < 0 ) {
140
145
return [ 0 , this . _tabsCount - 2 ] ;
@@ -146,6 +151,7 @@ Api.prototype = {
146
151
return this . els
147
152
. getDistance ( el )
148
153
. sub ( selectedTabInfo . overflowFullSize )
154
+ . sub ( this . els . getEl ( this . _options . tablistElement ) . getSpacing ( this . _btnPositionRelativeToTablist ) )
149
155
. sub ( this . els . getEl ( this . _options . buttonElement ) . getFullSize ( ) ) ;
150
156
} ,
151
157
_findFirstHiddenTabIndexDSCE : function ( selectedTabInfo , start , stop ) {
@@ -172,4 +178,33 @@ Api.prototype = {
172
178
? this . _findFirstHiddenTabIndexASC ( selectedTabInfo , start , stop )
173
179
: this . _findFirstHiddenTabIndexDSCE ( selectedTabInfo , start , stop ) ;
174
180
} ,
181
+ /** set _btnPositionRelativeToTablist and _btnReversePositionRelativeToTablist */
182
+ _setBtnPositionRelativeToTablist : function ( isVertical , dir ) {
183
+ if ( ! this . _btnPositionRelativeToTablist ) {
184
+ let pos = '' , reversePos = '' ;
185
+ if ( isVertical == true ) {
186
+ pos = 'Bottom' ; //the Button is rendered below the Tablist
187
+ reversePos = 'Top' ;
188
+ } else {
189
+ if ( dir === 'ltr' ) {
190
+ pos = 'Right' ; //the Button is rendered in left-side of the Tablist
191
+ reversePos = 'Left' ;
192
+ } else {
193
+ pos = 'Left' ; //the Button is rendered in right-side of the Tablist
194
+ reversePos = 'Right' ;
195
+ }
196
+ }
197
+ /**
198
+ * specifics where Button is relative to Tablist
199
+ * @type {"Right"|"Bottom"|"Left" }
200
+ */
201
+ this . _btnPositionRelativeToTablist = pos ;
202
+ /**
203
+ * reverse Button position relative to Tablist
204
+ * @type {"Right"|"Top"|"Left" }
205
+ */
206
+ this . _btnReversePositionRelativeToTablist = reversePos ;
207
+ }
208
+ return this ;
209
+ } ,
175
210
} ;
0 commit comments