@materializecss/materialize 2.0.0-alpha → 2.0.2-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +7 -4
- package/README.md +24 -12
- package/dist/css/materialize.css +90 -86
- package/dist/css/materialize.min.css +2 -2
- package/dist/js/materialize.js +2869 -2764
- package/dist/js/materialize.min.js +2 -2
- package/dist/js/materialize.min.js.map +1 -1
- package/package.json +1 -1
- package/sass/components/_collapsible.scss +0 -41
- package/sass/components/_global.scss +3 -2
- package/sass/components/_icons-material-design.scss +2 -1
- package/sass/components/_navbar.scss +6 -3
- package/sass/components/_sidenav.scss +66 -37
- package/sass/components/_theme_variables.scss +98 -0
- package/sass/components/_typography.scss +2 -2
- package/sass/components/forms/_input-fields.scss +4 -10
- package/sass/materialize.scss +0 -4
- package/src/autocomplete.ts +188 -94
- package/src/buttons.ts +225 -260
- package/src/cards.ts +5 -6
- package/src/carousel.ts +611 -542
- package/src/characterCounter.ts +50 -21
- package/src/chips.ts +152 -63
- package/src/collapsible.ts +97 -32
- package/src/component.ts +99 -10
- package/src/datepicker.ts +905 -726
- package/src/dropdown.ts +576 -484
- package/src/edges.ts +4 -4
- package/src/forms.ts +17 -14
- package/src/global.ts +56 -325
- package/src/materialbox.ts +354 -298
- package/src/modal.ts +296 -211
- package/src/parallax.ts +129 -105
- package/src/pushpin.ts +148 -103
- package/src/range.ts +166 -150
- package/src/scrollspy.ts +214 -174
- package/src/select.ts +434 -398
- package/src/sidenav.ts +447 -381
- package/src/slider.ts +421 -362
- package/src/tabs.ts +284 -227
- package/src/tapTarget.ts +246 -213
- package/src/timepicker.ts +738 -614
- package/src/toasts.ts +254 -230
- package/src/tooltip.ts +315 -252
- package/src/utils.ts +271 -0
- package/src/waves.ts +10 -10
package/src/tabs.ts
CHANGED
|
@@ -1,290 +1,347 @@
|
|
|
1
|
-
import { Component } from "./component";
|
|
2
|
-
import { Carousel } from "./carousel";
|
|
3
1
|
import anim from "animejs";
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
import { Carousel } from "./carousel";
|
|
4
|
+
import { Component, BaseOptions, InitElements, MElement } from "./component";
|
|
5
|
+
|
|
6
|
+
export interface TabsOptions extends BaseOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Transition duration in milliseconds.
|
|
9
|
+
* @default 300
|
|
10
|
+
*/
|
|
11
|
+
duration: number;
|
|
12
|
+
/**
|
|
13
|
+
* Callback for when a new tab content is shown.
|
|
14
|
+
* @default null
|
|
15
|
+
*/
|
|
16
|
+
onShow: (newContent: Element) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Set to true to enable swipeable tabs.
|
|
19
|
+
* This also uses the responsiveThreshold option.
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
swipeable: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The maximum width of the screen, in pixels,
|
|
25
|
+
* where the swipeable functionality initializes.
|
|
26
|
+
* @default infinity
|
|
27
|
+
*/
|
|
28
|
+
responsiveThreshold: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let _defaults: TabsOptions = {
|
|
6
32
|
duration: 300,
|
|
7
33
|
onShow: null,
|
|
8
34
|
swipeable: false,
|
|
9
|
-
responsiveThreshold: Infinity
|
|
35
|
+
responsiveThreshold: Infinity // breakpoint for swipeable
|
|
10
36
|
};
|
|
11
37
|
|
|
12
|
-
export class Tabs extends Component {
|
|
13
|
-
|
|
14
|
-
_tabLinks: any;
|
|
38
|
+
export class Tabs extends Component<TabsOptions> {
|
|
39
|
+
_tabLinks: NodeListOf<HTMLAnchorElement>;
|
|
15
40
|
_index: number;
|
|
16
41
|
_indicator: any;
|
|
17
|
-
_handleWindowResizeBound: (this: Window, ev: UIEvent) => any;
|
|
18
|
-
_handleTabClickBound: (this: Window, ev: UIEvent) => any;
|
|
19
42
|
_tabWidth: number;
|
|
20
43
|
_tabsWidth: number;
|
|
21
44
|
_tabsCarousel: any;
|
|
22
45
|
_activeTabLink: any;
|
|
23
46
|
_content: any;
|
|
24
47
|
|
|
25
|
-
constructor(el, options:
|
|
26
|
-
super(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
this._setupEventHandlers();
|
|
48
|
+
constructor(el: HTMLElement, options: Partial<TabsOptions>) {
|
|
49
|
+
super(el, options, Tabs);
|
|
50
|
+
(this.el as any).M_Tabs = this;
|
|
51
|
+
|
|
52
|
+
this.options = {
|
|
53
|
+
...Tabs.defaults,
|
|
54
|
+
...options
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
this._tabLinks = this.el.querySelectorAll('li.tab > a');
|
|
58
|
+
this._index = 0;
|
|
59
|
+
this._setupActiveTabLink();
|
|
60
|
+
if (this.options.swipeable) {
|
|
61
|
+
this._setupSwipeableTabs();
|
|
62
|
+
} else {
|
|
63
|
+
this._setupNormalTabs();
|
|
42
64
|
}
|
|
65
|
+
// Setup tabs indicator after content to ensure accurate widths
|
|
66
|
+
this._setTabsAndTabWidth();
|
|
67
|
+
this._createIndicator();
|
|
68
|
+
this._setupEventHandlers();
|
|
69
|
+
}
|
|
43
70
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
static get defaults(): TabsOptions {
|
|
72
|
+
return _defaults;
|
|
73
|
+
}
|
|
47
74
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Initializes instance of Tabs.
|
|
77
|
+
* @param el HTML element.
|
|
78
|
+
* @param options Component options.
|
|
79
|
+
*/
|
|
80
|
+
static init(el: HTMLElement, options?: Partial<TabsOptions>): Tabs;
|
|
81
|
+
/**
|
|
82
|
+
* Initializes instances of Tabs.
|
|
83
|
+
* @param els HTML elements.
|
|
84
|
+
* @param options Component options.
|
|
85
|
+
*/
|
|
86
|
+
static init(els: InitElements<MElement>, options?: Partial<TabsOptions>): Tabs[];
|
|
87
|
+
/**
|
|
88
|
+
* Initializes instances of Tabs.
|
|
89
|
+
* @param els HTML elements.
|
|
90
|
+
* @param options Component options.
|
|
91
|
+
*/
|
|
92
|
+
static init(els: HTMLElement | InitElements<MElement>, options: Partial<TabsOptions> = {}): Tabs | Tabs[] {
|
|
93
|
+
return super.init(els, options, Tabs);
|
|
94
|
+
}
|
|
51
95
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
96
|
+
static getInstance(el: HTMLElement): Tabs {
|
|
97
|
+
return (el as any).M_Tabs;
|
|
98
|
+
}
|
|
56
99
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this._teardownNormalTabs();
|
|
65
|
-
}
|
|
66
|
-
(this.el as any).M_Tabs = undefined;
|
|
100
|
+
destroy() {
|
|
101
|
+
this._removeEventHandlers();
|
|
102
|
+
this._indicator.parentNode.removeChild(this._indicator);
|
|
103
|
+
if (this.options.swipeable) {
|
|
104
|
+
this._teardownSwipeableTabs();
|
|
67
105
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this._handleWindowResizeBound = this._handleWindowResize.bind(this);
|
|
71
|
-
window.addEventListener('resize', this._handleWindowResizeBound);
|
|
72
|
-
this._handleTabClickBound = this._handleTabClick.bind(this);
|
|
73
|
-
this.el.addEventListener('click', this._handleTabClickBound);
|
|
106
|
+
else {
|
|
107
|
+
this._teardownNormalTabs();
|
|
74
108
|
}
|
|
109
|
+
(this.el as any).M_Tabs = undefined;
|
|
110
|
+
}
|
|
75
111
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
/**
|
|
113
|
+
* The index of tab that is currently shown.
|
|
114
|
+
*/
|
|
115
|
+
get index(){ return this._index; }
|
|
80
116
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
_setupEventHandlers() {
|
|
118
|
+
window.addEventListener('resize', this._handleWindowResize);
|
|
119
|
+
this.el.addEventListener('click', this._handleTabClick);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
_removeEventHandlers() {
|
|
123
|
+
window.removeEventListener('resize', this._handleWindowResize);
|
|
124
|
+
this.el.removeEventListener('click', this._handleTabClick);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_handleWindowResize = () => {
|
|
128
|
+
this._setTabsAndTabWidth();
|
|
129
|
+
if (this._tabWidth !== 0 && this._tabsWidth !== 0) {
|
|
130
|
+
this._indicator.style.left = this._calcLeftPos(this._activeTabLink)+'px';
|
|
131
|
+
this._indicator.style.right = this._calcRightPos(this._activeTabLink)+'px';
|
|
87
132
|
}
|
|
133
|
+
}
|
|
88
134
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
135
|
+
_handleTabClick = (e: MouseEvent) => {
|
|
136
|
+
const tabLink = e.target as HTMLAnchorElement;
|
|
137
|
+
const tab = tabLink.parentElement;
|
|
138
|
+
// Handle click on tab link only
|
|
139
|
+
if (!tabLink || !tab.classList.contains('tab')) return;
|
|
140
|
+
// is disabled?
|
|
141
|
+
if (tab.classList.contains('disabled')) {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// Act as regular link if target attribute is specified.
|
|
146
|
+
if (tabLink.hasAttribute('target')) return;
|
|
147
|
+
// Make the old tab inactive.
|
|
148
|
+
this._activeTabLink.classList.remove('active');
|
|
149
|
+
const _oldContent = this._content;
|
|
150
|
+
// Update the variables with the new link and content
|
|
105
151
|
|
|
106
152
|
this._activeTabLink = tabLink;
|
|
107
|
-
|
|
153
|
+
if (tabLink.hash)
|
|
154
|
+
this._content = document.querySelector(tabLink.hash);
|
|
108
155
|
this._tabLinks = this.el.querySelectorAll('li.tab > a');
|
|
109
156
|
// Make the tab active
|
|
110
157
|
this._activeTabLink.classList.add('active');
|
|
111
158
|
const prevIndex = this._index;
|
|
112
159
|
this._index = Math.max(Array.from(this._tabLinks).indexOf(tabLink), 0);
|
|
113
160
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (typeof this.options.onShow === 'function')
|
|
119
|
-
this.options.onShow.call(this, this._content);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
if (this._content) {
|
|
124
|
-
this._content.style.display = 'block';
|
|
125
|
-
this._content.classList.add('active');
|
|
161
|
+
// Swap content
|
|
162
|
+
if (this.options.swipeable) {
|
|
163
|
+
if (this._tabsCarousel) {
|
|
164
|
+
this._tabsCarousel.set(this._index, () => {
|
|
126
165
|
if (typeof this.options.onShow === 'function')
|
|
127
166
|
this.options.onShow.call(this, this._content);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
if (this._content) {
|
|
171
|
+
this._content.style.display = 'block';
|
|
172
|
+
this._content.classList.add('active');
|
|
173
|
+
if (typeof this.options.onShow === 'function')
|
|
174
|
+
this.options.onShow.call(this, this._content);
|
|
175
|
+
if (_oldContent && _oldContent !== this._content) {
|
|
176
|
+
_oldContent.style.display = 'none';
|
|
177
|
+
_oldContent.classList.remove('active');
|
|
132
178
|
}
|
|
133
179
|
}
|
|
134
|
-
// Update widths after content is swapped (scrollbar bugfix)
|
|
135
|
-
this._setTabsAndTabWidth();
|
|
136
|
-
this._animateIndicator(prevIndex);
|
|
137
|
-
e.preventDefault();
|
|
138
180
|
}
|
|
181
|
+
// Update widths after content is swapped (scrollbar bugfix)
|
|
182
|
+
this._setTabsAndTabWidth();
|
|
183
|
+
this._animateIndicator(prevIndex);
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
}
|
|
139
186
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
187
|
+
_createIndicator() {
|
|
188
|
+
const indicator = document.createElement('li');
|
|
189
|
+
indicator.classList.add('indicator');
|
|
190
|
+
this.el.appendChild(indicator);
|
|
191
|
+
this._indicator = indicator;
|
|
192
|
+
this._indicator.style.left = this._calcLeftPos(this._activeTabLink)+'px';
|
|
193
|
+
this._indicator.style.right = this._calcRightPos(this._activeTabLink)+'px';
|
|
194
|
+
}
|
|
148
195
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
196
|
+
_setupActiveTabLink() {
|
|
197
|
+
// If the location.hash matches one of the links, use that as the active tab.
|
|
198
|
+
this._activeTabLink = Array.from(this._tabLinks).find((a: HTMLAnchorElement) => a.getAttribute('href') === location.hash);
|
|
199
|
+
// If no match is found, use the first link or any with class 'active' as the initial active tab.
|
|
200
|
+
if (!this._activeTabLink) {
|
|
201
|
+
this._activeTabLink = this.el.querySelector('li.tab a.active');
|
|
202
|
+
}
|
|
203
|
+
if (this._activeTabLink.length === 0) {
|
|
204
|
+
this._activeTabLink = this.el.querySelector('li.tab a');
|
|
205
|
+
}
|
|
206
|
+
Array.from(this._tabLinks).forEach((a: HTMLAnchorElement) => a.classList.remove('active'));
|
|
207
|
+
this._activeTabLink.classList.add('active');
|
|
161
208
|
|
|
162
209
|
this._index = Math.max(Array.from(this._tabLinks).indexOf(this._activeTabLink), 0);
|
|
163
|
-
if (this._activeTabLink) {
|
|
210
|
+
if (this._activeTabLink && this._activeTabLink.hash) {
|
|
164
211
|
this._content = document.querySelector(this._activeTabLink.hash);
|
|
165
212
|
this._content.classList.add('active');
|
|
166
213
|
}
|
|
167
214
|
}
|
|
168
215
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
216
|
+
_setupSwipeableTabs() {
|
|
217
|
+
// Change swipeable according to responsive threshold
|
|
218
|
+
if (window.innerWidth > this.options.responsiveThreshold)
|
|
219
|
+
this.options.swipeable = false;
|
|
173
220
|
|
|
174
221
|
const tabsContent = [];
|
|
175
222
|
this._tabLinks.forEach(a => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// Create Carousel-Wrapper around Tab-Contents
|
|
182
|
-
const tabsWrapper = document.createElement('div');
|
|
183
|
-
tabsWrapper.classList.add('tabs-content', 'carousel', 'carousel-slider');
|
|
184
|
-
|
|
185
|
-
// Wrap around
|
|
186
|
-
tabsContent[0].parentElement.insertBefore(tabsWrapper, tabsContent[0]);
|
|
187
|
-
tabsContent.forEach(tabContent => {
|
|
188
|
-
tabsWrapper.appendChild(tabContent);
|
|
189
|
-
tabContent.style.display = '';
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// Keep active tab index to set initial carousel slide
|
|
193
|
-
const tab = this._activeTabLink.parentElement;
|
|
194
|
-
const activeTabIndex = Array.from(tab.parentNode.children).indexOf(tab);
|
|
195
|
-
|
|
196
|
-
this._tabsCarousel = Carousel.init(tabsWrapper, {
|
|
197
|
-
fullWidth: true,
|
|
198
|
-
noWrap: true,
|
|
199
|
-
onCycleTo: (item) => {
|
|
200
|
-
const prevIndex = this._index;
|
|
201
|
-
this._index = Array.from(item.parentNode.children).indexOf(item);
|
|
202
|
-
this._activeTabLink.classList.remove('active');
|
|
203
|
-
this._activeTabLink = Array.from(this._tabLinks)[this._index];
|
|
204
|
-
this._activeTabLink.classList.add('active');
|
|
205
|
-
this._animateIndicator(prevIndex);
|
|
206
|
-
if (typeof this.options.onShow === 'function')
|
|
207
|
-
this.options.onShow.call(this, this._content);
|
|
223
|
+
if (a.hash) {
|
|
224
|
+
const currContent = document.querySelector(a.hash);
|
|
225
|
+
currContent.classList.add('carousel-item');
|
|
226
|
+
tabsContent.push(currContent);
|
|
208
227
|
}
|
|
209
228
|
});
|
|
210
|
-
// Set initial carousel slide to active tab
|
|
211
|
-
this._tabsCarousel.set(activeTabIndex);
|
|
212
|
-
}
|
|
213
229
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
230
|
+
// Create Carousel-Wrapper around Tab-Contents
|
|
231
|
+
const tabsWrapper = document.createElement('div');
|
|
232
|
+
tabsWrapper.classList.add('tabs-content', 'carousel', 'carousel-slider');
|
|
233
|
+
|
|
234
|
+
// Wrap around
|
|
235
|
+
tabsContent[0].parentElement.insertBefore(tabsWrapper, tabsContent[0]);
|
|
236
|
+
tabsContent.forEach(tabContent => {
|
|
237
|
+
tabsWrapper.appendChild(tabContent);
|
|
238
|
+
tabContent.style.display = '';
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Keep active tab index to set initial carousel slide
|
|
242
|
+
const tab = this._activeTabLink.parentElement;
|
|
243
|
+
const activeTabIndex = Array.from(tab.parentNode.children).indexOf(tab);
|
|
244
|
+
|
|
245
|
+
this._tabsCarousel = Carousel.init(tabsWrapper, {
|
|
246
|
+
fullWidth: true,
|
|
247
|
+
noWrap: true,
|
|
248
|
+
onCycleTo: (item) => {
|
|
249
|
+
const prevIndex = this._index;
|
|
250
|
+
this._index = Array.from(item.parentNode.children).indexOf(item);
|
|
251
|
+
this._activeTabLink.classList.remove('active');
|
|
252
|
+
this._activeTabLink = Array.from(this._tabLinks)[this._index];
|
|
253
|
+
this._activeTabLink.classList.add('active');
|
|
254
|
+
this._animateIndicator(prevIndex);
|
|
255
|
+
if (typeof this.options.onShow === 'function')
|
|
256
|
+
this.options.onShow.call(this, this._content);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
// Set initial carousel slide to active tab
|
|
260
|
+
this._tabsCarousel.set(activeTabIndex);
|
|
261
|
+
}
|
|
221
262
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
263
|
+
_teardownSwipeableTabs() {
|
|
264
|
+
const tabsWrapper = this._tabsCarousel.el;
|
|
265
|
+
this._tabsCarousel.destroy();
|
|
266
|
+
// Unwrap
|
|
267
|
+
tabsWrapper.after(tabsWrapper.children);
|
|
268
|
+
tabsWrapper.remove();
|
|
269
|
+
}
|
|
232
270
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
}
|
|
271
|
+
_setupNormalTabs() {
|
|
272
|
+
// Hide Tabs Content
|
|
273
|
+
Array.from(this._tabLinks).forEach((a) => {
|
|
274
|
+
if (a === this._activeTabLink) return;
|
|
275
|
+
if ((<HTMLAnchorElement>a).hash) {
|
|
276
|
+
const currContent = document.querySelector((<HTMLAnchorElement>a).hash);
|
|
277
|
+
if (currContent) (<HTMLElement>currContent).style.display = 'none';
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
242
281
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
282
|
+
_teardownNormalTabs() {
|
|
283
|
+
// show Tabs Content
|
|
284
|
+
this._tabLinks.forEach((a) => {
|
|
285
|
+
if (a.hash) {
|
|
286
|
+
const currContent = document.querySelector(a.hash) as HTMLElement;
|
|
287
|
+
if (currContent) currContent.style.display = '';
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
247
291
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
292
|
+
_setTabsAndTabWidth() {
|
|
293
|
+
this._tabsWidth = this.el.getBoundingClientRect().width;
|
|
294
|
+
this._tabWidth = Math.max(this._tabsWidth, this.el.scrollWidth) / this._tabLinks.length;
|
|
295
|
+
}
|
|
251
296
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
297
|
+
_calcRightPos(el) {
|
|
298
|
+
return Math.ceil(this._tabsWidth - el.offsetLeft - el.getBoundingClientRect().width);
|
|
299
|
+
}
|
|
255
300
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
301
|
+
_calcLeftPos(el) {
|
|
302
|
+
return Math.floor(el.offsetLeft);
|
|
303
|
+
}
|
|
260
304
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const animOptions = {
|
|
270
|
-
targets: this._indicator,
|
|
271
|
-
left: {
|
|
272
|
-
value: this._calcLeftPos(this._activeTabLink),
|
|
273
|
-
delay: leftDelay
|
|
274
|
-
},
|
|
275
|
-
right: {
|
|
276
|
-
value: this._calcRightPos(this._activeTabLink),
|
|
277
|
-
delay: rightDelay
|
|
278
|
-
},
|
|
279
|
-
duration: this.options.duration,
|
|
280
|
-
easing: 'easeOutQuad'
|
|
281
|
-
};
|
|
282
|
-
anim.remove(this._indicator);
|
|
283
|
-
anim(animOptions);
|
|
284
|
-
}
|
|
305
|
+
/**
|
|
306
|
+
* Recalculate tab indicator position. This is useful when
|
|
307
|
+
* the indicator position is not correct.
|
|
308
|
+
*/
|
|
309
|
+
updateTabIndicator() {
|
|
310
|
+
this._setTabsAndTabWidth();
|
|
311
|
+
this._animateIndicator(this._index);
|
|
312
|
+
}
|
|
285
313
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
314
|
+
_animateIndicator(prevIndex) {
|
|
315
|
+
let leftDelay = 0, rightDelay = 0;
|
|
316
|
+
|
|
317
|
+
if (this._index - prevIndex >= 0)
|
|
318
|
+
leftDelay = 90;
|
|
319
|
+
else
|
|
320
|
+
rightDelay = 90;
|
|
321
|
+
|
|
322
|
+
const animOptions = {
|
|
323
|
+
targets: this._indicator,
|
|
324
|
+
left: {
|
|
325
|
+
value: this._calcLeftPos(this._activeTabLink),
|
|
326
|
+
delay: leftDelay
|
|
327
|
+
},
|
|
328
|
+
right: {
|
|
329
|
+
value: this._calcRightPos(this._activeTabLink),
|
|
330
|
+
delay: rightDelay
|
|
331
|
+
},
|
|
332
|
+
duration: this.options.duration,
|
|
333
|
+
easing: 'easeOutQuad'
|
|
334
|
+
};
|
|
335
|
+
anim.remove(this._indicator);
|
|
336
|
+
anim(animOptions);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Show tab content that corresponds to the tab with the id.
|
|
341
|
+
* @param tabId The id of the tab that you want to switch to.
|
|
342
|
+
*/
|
|
343
|
+
select(tabId: string) {
|
|
344
|
+
const tab = Array.from(this._tabLinks).find((a: HTMLAnchorElement) => a.getAttribute('href') === '#'+tabId);
|
|
345
|
+
if (tab) (<HTMLAnchorElement>tab).click();
|
|
290
346
|
}
|
|
347
|
+
}
|