angular-cn/public/resources/js/directives/code-tabs.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-05-01 09:48:52 -04:00
/*
2015-05-02 18:34:16 -04:00
* Code Tabs Directive
2015-05-01 09:48:52 -04:00
*
2015-05-02 18:34:16 -04:00
* Creates a tabs code examples that
* displayed in the same container
2015-05-01 09:48:52 -04:00
*/
2015-05-02 18:34:16 -04:00
angularIO.directive('codeTabs', function($timeout) {
2015-05-01 09:48:52 -04:00
return {
2015-05-02 18:34:16 -04:00
restrict: 'E',
scope: {},
transclude: true,
replace: true,
controllerAs: 'vm',
controller: function () {
var vm = this;
2015-05-02 18:34:16 -04:00
vm.panes = [];
2015-05-01 09:48:52 -04:00
2015-05-02 18:34:16 -04:00
/*
* Add Code Pane List of Panes
*
*/
2015-05-01 09:48:52 -04:00
2015-05-02 18:34:16 -04:00
this.addPane = function(pane) {
if (vm.panes.length === 0) {
vm.showPane(pane);
2015-05-02 18:34:16 -04:00
}
2015-05-01 09:48:52 -04:00
vm.panes.push(pane);
2015-05-02 18:34:16 -04:00
};
2015-05-01 09:48:52 -04:00
2015-05-02 18:34:16 -04:00
/*
* Show selected Code Examples
*
*/
2015-05-01 09:48:52 -04:00
vm.showPane = function(pane) {
2015-05-02 18:34:16 -04:00
// RESET ALL EXAMPLES
angular.forEach(vm.panes, function(pane) {
2015-05-02 18:34:16 -04:00
pane.selected = false;
2015-05-01 09:48:52 -04:00
});
2015-05-02 18:34:16 -04:00
// 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}">' +
2015-05-02 18:34:16 -04:00
' {{pane.name}}' +
' </button>' +
' </nav>' +
' </header>' +
' <div class="code-box-examples" ng-transclude></div>' +
'</div>'
2015-05-01 09:48:52 -04:00
};
2015-05-02 18:34:16 -04:00
});