Skip to content

Commit 9ec7f66

Browse files
authored
Merge pull request #6 from davidsekar/develop
add tab feature
2 parents fbfa0f7 + 4539e80 commit 9ec7f66

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/demo.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
</div>
8282
<br/>
8383
<button onclick="$('#example_0').scrollTabs('destroy')" >Destroy above tabs</button>
84+
<br/>
85+
<button id="addRandomTab" type="button">Add new random tab</button>
8486
<br /><br />
8587
<div id="example_1">
8688
<ul role="tablist">

src/ts/jquery.init.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ $(() => {
1616
}
1717
});
1818

19+
// $('#addRandomTab').on('click', (e) => {
20+
// $('#example_0').data('uiScrollTabs')
21+
// .addTab(keywords[Math.floor(Math.random() * keywords.length) + 1], );
22+
// });
23+
1924
if (scrollEnabled) {
2025
$tabs = $('#example_1')
2126
.scrollTabs({
@@ -49,14 +54,14 @@ $(() => {
4954
$('#example_2').tabs();
5055

5156
// Add new tab
52-
$('#addTab_1').click(() => {
57+
$('#addRandomTab').click(() => {
5358
const label = keywords[Math.floor(Math.random() * keywords.length)];
5459
const content = 'This is the content for the ' + label + '<br>Lorem ipsum dolor sit amet,' +
5560
' consectetur adipiscing elit. Quisque hendrerit vulputate porttitor. Fusce purus leo,' +
5661
' faucibus a sagittis congue, molestie tempus felis. Donec convallis semper enim,' +
5762
' varius sagittis eros imperdiet in. Vivamus semper sem at metus mattis a' +
5863
' aliquam neque ornare. Proin sed semper lacus.';
59-
$tabs.trigger('addTab', [label, content]);
64+
$('#example_0').data('uiScrollTabs').addTab(label, content);
6065
return false;
6166
});
6267
});

src/ts/jquery.ui.scrolltabs.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,25 @@
442442
});
443443
});
444444
},
445+
addTab(header: string, panelContent: string) {
446+
const newId: string = $({}).uniqueId()[0].id;
447+
const tab = $('<li><a href="#' + newId + '" role="tab">' + header + '</a></li>');
448+
const panel = this._createPanel(newId);
449+
panel.html(panelContent);
445450

451+
this.$ul.append(tab);
452+
panel.attr('aria-live', 'polite');
453+
454+
if (panel.length) {
455+
$(this.panels[this.panels.length - 1]).after(panel);
456+
}
457+
458+
panel.attr('role', 'tabpanel');
459+
this._addclosebutton(tab);
460+
461+
this.refresh();
462+
this._showNavsIfNeeded();
463+
},
446464
removeTab(anc: JQuery<HTMLElement>) {
447465
const tabId = anc.attr('href');
448466
// Remove the panel
@@ -481,4 +499,5 @@
481499
$(window).off('resize', this.debounceEvent(() => { this._showNavsIfNeeded(); }));
482500
}
483501
});
502+
return $.ui.scrollTabs;
484503
})(jQuery);

0 commit comments

Comments
 (0)