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

Commit 1f3e085

Browse files
author
Nick Litwin
committed
Merge branch 'Colinh84-issue-673' of https://github.com/Colinh84/topcoder-app into Colinh84-Colinh84-issue-673
2 parents 0062c7e + 6bb7b8f commit 1f3e085

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,50 @@ 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')
16+
var tabCtrl = this
1617
this.tabs = []
1718
this.addTab = function addTab(tab) {
1819
this.tabs.push(tab)
19-
if (this.tabs.length === 1) {
20+
if (!angular.isDefined($location.search().tab) && this.tabs.length === 1) {
21+
tab.active = true
22+
} else if ($location.search().tab === tab.heading) {
2023
tab.active = true
2124
}
2225
}
2326

2427
this.select = function(selectedTab) {
28+
var select = false
2529
angular.forEach(this.tabs, function(tab) {
26-
if (tab.active && tab !== selectedTab) {
30+
if (tab.active && tab.heading !== selectedTab.heading) {
2731
tab.active = false
32+
} else if (tab.heading === selectedTab.heading) {
33+
tab.active = true
34+
select = true
2835
}
2936
})
37+
if (select === false && this.tabs.length > 0) {
38+
this.tabs[0].active = true
39+
}
40+
}
3041

31-
selectedTab.active = true
42+
this.setTab = function(tab) {
43+
if ($location.search().tab !== tab.heading) {
44+
$location.search('tab', tab.heading)
45+
}
3246
}
47+
48+
$scope.$on( '$locationChangeSuccess', function() {
49+
var tab
50+
if (angular.isDefined($location.search().tab)) {
51+
tab = $location.search().tab
52+
tabCtrl.select({'heading' : tab})
53+
} else if (tabCtrl.tabs.length > 0) {
54+
tab = tabCtrl.tabs[0].heading
55+
tabCtrl.select({'heading' : tab})
56+
}
57+
})
3358
}],
3459
controllerAs: 'tabSet'
3560
}

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)