Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 529aebe

Browse files
author
Nick Litwin
committed
Merge branch 'Colinh84-Colinh84-issue-673' into dev
2 parents 0062c7e + 049f052 commit 529aebe

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

app/directives/tc-tabs/tc-tabs.directive.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,53 @@ import angular from 'angular'
1111
bindToController: true,
1212
template: require('./tc-tabs')(),
1313
scope: {},
14-
controller: ['$log', function($log, $scope, $element) {
14+
controller: ['$log', '$location', '$scope', function($log, $location, $scope, $element) {
1515
$log = $log.getInstance('TcTabSetController')
1616
this.tabs = []
17+
1718
this.addTab = function addTab(tab) {
1819
this.tabs.push(tab)
19-
if (this.tabs.length === 1) {
20+
21+
if (!angular.isDefined($location.search().tab) && this.tabs.length === 1) {
22+
tab.active = true
23+
} else if ($location.search().tab === tab.heading) {
2024
tab.active = true
2125
}
2226
}
2327

2428
this.select = function(selectedTab) {
29+
var select = false
30+
2531
angular.forEach(this.tabs, function(tab) {
26-
if (tab.active && tab !== selectedTab) {
32+
if (tab.active && tab.heading !== selectedTab.heading) {
2733
tab.active = false
34+
} else if (tab.heading === selectedTab.heading) {
35+
tab.active = true
36+
select = true
2837
}
2938
})
3039

31-
selectedTab.active = true
40+
if (select === false && this.tabs.length > 0) {
41+
this.tabs[0].active = true
42+
}
43+
}
44+
45+
this.setTab = function(tab) {
46+
if ($location.search().tab !== tab.heading) {
47+
$location.search('tab', tab.heading)
48+
}
3249
}
50+
51+
$scope.$on('$locationChangeSuccess', () => {
52+
var tab
53+
if (angular.isDefined($location.search().tab)) {
54+
tab = $location.search().tab
55+
this.select({'heading' : tab})
56+
} else if (this.tabs.length > 0) {
57+
tab = this.tabs[0].heading
58+
this.select({'heading' : tab})
59+
}
60+
})
3361
}],
3462
controllerAs: 'tabSet'
3563
}

app/directives/tc-tabs/tc-tabs.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.tab-panel
2-
2+
33
ul.tab-set
44
li.tab-pill(ng-repeat="tab in tabSet.tabs")
5-
a(ng-click="tabSet.select(tab)", ng-class="{'selected': tab.active}")
5+
a(ng-click="tabSet.setTab(tab)", ng-class="{'selected': tab.active}")
66
.header(ng-class="{'selected': tab.active}") {{tab.heading}}
77

88
.tab-view(ng-transclude)

0 commit comments

Comments
 (0)