forked from muicss/mui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabs.js
More file actions
65 lines (60 loc) · 1.74 KB
/
tabs.js
File metadata and controls
65 lines (60 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* MUI Angular Tabs Component
* @module angular/tabs
*/
module.exports = angular.module('mui.tabs', [])
.directive('muiTabs', function() {
return {
restrict: 'E',
transclude: true,
scope: {
justified: '=?',
selected: '=?'
},
controller: function($scope) {
var panes = $scope.panes = [];
$scope.selected = $scope.selected || 0;
$scope.onClick = function(pane, panelIndex) {
angular.forEach(panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
$scope.selected = panelIndex;
};
$scope.$watch('selected', function(newVal) {
$scope.onClick(panes[newVal] , newVal);
});
this.addPane = function(pane) {
if (panes.length === $scope.selected) {
$scope.select(pane, $scope.selected);
}
panes.push(pane);
};
},
template: '' +
'<ul class="mui-tabs__bar" ' +
'ng-class=\'{"mui-tabs__bar--justified" : justified}\'>' +
'<li ng-repeat="pane in panes track by $index" ' +
'ng-class=\'{"mui--is-active" : pane.selected}\'>' +
'<a ng-click="onClick(pane, $index)">{{pane.title}}</a>' +
'</li>' +
'</ul>'+
'<ng-transclude></ng-transclude>'
};
})
.directive('muiTab', function() {
return {
require: '^muiTabs',
restrict: 'AE',
scope: {
title: '@'
},
replace: true,
template: '<div class="mui-tabs__pane" ' +
'ng-class=\'{"mui--is-active" : selected}\' ng-transclude></div>',
transclude: true,
link: function(scope, element, attrs, tabsCtrl) {
tabsCtrl.addPane(scope);
}
};
});