forked from angular/angular.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-tabs.js
63 lines (52 loc) · 1.28 KB
/
code-tabs.js
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
/*
* Code Tabs Directive
*
* Creates a tabs code examples that
* displayed in the same container
*/
angularIO.directive('codeTabs', function($timeout) {
return {
restrict: 'E',
scope: {},
transclude: true,
replace: true,
controllerAs: 'vm',
controller: function () {
var vm = this;
vm.panes = [];
/*
* Add Code Pane List of Panes
*
*/
this.addPane = function(pane) {
if (vm.panes.length === 0) {
vm.showPane(pane);
}
vm.panes.push(pane);
};
/*
* Show selected Code Examples
*
*/
vm.showPane = function(pane) {
// RESET ALL EXAMPLES
angular.forEach(vm.panes, function(pane) {
pane.selected = false;
});
// SELECT CURRENT EXAMPLE
pane.selected = true;
};
},
template:
'<div class="code-box">' +
' <header class="code-box-header">' +
' <nav class="code-box-nav">' +
' <button ng-repeat="pane in vm.panes" ng-click="vm.showPane(pane)" class="button" ng-class="{selected:pane.selected}">' +
' {{pane.name}}' +
' </button>' +
' </nav>' +
' </header>' +
' <div class="code-box-examples" ng-transclude></div>' +
'</div>'
};
});