|
1 | 1 | angular.module('examples', [])
|
2 | 2 |
|
| 3 | +.directive('runnableExample', ['$templateCache', '$document', function($templateCache, $document) { |
| 4 | + var exampleClassNameSelector = '.runnable-example-file'; |
| 5 | + var doc = $document[0]; |
| 6 | + var tpl = |
| 7 | + '<nav class="runnable-example-tabs" ng-if="tabs">' + |
| 8 | + ' <a ng-class="{active:$index==activeTabIndex}"' + |
| 9 | + 'ng-repeat="tab in tabs track by $index" ' + |
| 10 | + 'href="" ' + |
| 11 | + 'class="btn"' + |
| 12 | + 'ng-click="setTab($index)">' + |
| 13 | + ' {{ tab }}' + |
| 14 | + ' </a>' + |
| 15 | + '</nav>'; |
| 16 | + |
| 17 | + return { |
| 18 | + restrict: 'C', |
| 19 | + scope : true, |
| 20 | + controller : ['$scope', function($scope) { |
| 21 | + $scope.setTab = function(index) { |
| 22 | + var tab = $scope.tabs[index]; |
| 23 | + $scope.activeTabIndex = index; |
| 24 | + $scope.$broadcast('tabChange', index, tab); |
| 25 | + }; |
| 26 | + }], |
| 27 | + compile : function(element) { |
| 28 | + element.html(tpl + element.html()); |
| 29 | + return function(scope, element) { |
| 30 | + var node = element[0]; |
| 31 | + var examples = node.querySelectorAll(exampleClassNameSelector); |
| 32 | + var tabs = [], now = Date.now(); |
| 33 | + angular.forEach(examples, function(child, index) { |
| 34 | + tabs.push(child.getAttribute('name')); |
| 35 | + }); |
| 36 | + |
| 37 | + if(tabs.length > 0) { |
| 38 | + scope.tabs = tabs; |
| 39 | + scope.$on('tabChange', function(e, index, title) { |
| 40 | + angular.forEach(examples, function(child) { |
| 41 | + child.style.display = 'none'; |
| 42 | + }); |
| 43 | + var selected = examples[index]; |
| 44 | + selected.style.display = 'block'; |
| 45 | + }); |
| 46 | + scope.setTab(0); |
| 47 | + } |
| 48 | + }; |
| 49 | + } |
| 50 | + }; |
| 51 | +}]) |
| 52 | + |
3 | 53 | .factory('formPostData', ['$document', function($document) {
|
4 | 54 | return function(url, newWindow, fields) {
|
5 | 55 | /**
|
|
0 commit comments