| @@ 5437-5530 (lines=94) @@ | ||
| 5434 | ||
| 5435 | angular.module('ui.bootstrap.tabs', []) |
|
| 5436 | ||
| 5437 | .controller('UibTabsetController', ['$scope', function ($scope) { |
|
| 5438 | var ctrl = this, |
|
| 5439 | oldIndex; |
|
| 5440 | ctrl.tabs = []; |
|
| 5441 | ||
| 5442 | ctrl.select = function(index, evt) { |
|
| 5443 | if (!destroyed) { |
|
| 5444 | var previousIndex = findTabIndex(oldIndex); |
|
| 5445 | var previousSelected = ctrl.tabs[previousIndex]; |
|
| 5446 | if (previousSelected) { |
|
| 5447 | previousSelected.tab.onDeselect({ |
|
| 5448 | $event: evt |
|
| 5449 | }); |
|
| 5450 | if (evt && evt.isDefaultPrevented()) { |
|
| 5451 | return; |
|
| 5452 | } |
|
| 5453 | previousSelected.tab.active = false; |
|
| 5454 | } |
|
| 5455 | ||
| 5456 | var selected = ctrl.tabs[index]; |
|
| 5457 | if (selected) { |
|
| 5458 | selected.tab.onSelect({ |
|
| 5459 | $event: evt |
|
| 5460 | }); |
|
| 5461 | selected.tab.active = true; |
|
| 5462 | ctrl.active = selected.index; |
|
| 5463 | oldIndex = selected.index; |
|
| 5464 | } else if (!selected && angular.isNumber(oldIndex)) { |
|
| 5465 | ctrl.active = null; |
|
| 5466 | oldIndex = null; |
|
| 5467 | } |
|
| 5468 | } |
|
| 5469 | }; |
|
| 5470 | ||
| 5471 | ctrl.addTab = function addTab(tab) { |
|
| 5472 | ctrl.tabs.push({ |
|
| 5473 | tab: tab, |
|
| 5474 | index: tab.index |
|
| 5475 | }); |
|
| 5476 | ctrl.tabs.sort(function(t1, t2) { |
|
| 5477 | if (t1.index > t2.index) { |
|
| 5478 | return 1; |
|
| 5479 | } |
|
| 5480 | ||
| 5481 | if (t1.index < t2.index) { |
|
| 5482 | return -1; |
|
| 5483 | } |
|
| 5484 | ||
| 5485 | return 0; |
|
| 5486 | }); |
|
| 5487 | ||
| 5488 | if (tab.index === ctrl.active || !angular.isNumber(ctrl.active) && ctrl.tabs.length === 1) { |
|
| 5489 | var newActiveIndex = findTabIndex(tab.index); |
|
| 5490 | ctrl.select(newActiveIndex); |
|
| 5491 | } |
|
| 5492 | }; |
|
| 5493 | ||
| 5494 | ctrl.removeTab = function removeTab(tab) { |
|
| 5495 | var index; |
|
| 5496 | for (var i = 0; i < ctrl.tabs.length; i++) { |
|
| 5497 | if (ctrl.tabs[i].tab === tab) { |
|
| 5498 | index = i; |
|
| 5499 | break; |
|
| 5500 | } |
|
| 5501 | } |
|
| 5502 | ||
| 5503 | if (ctrl.tabs[index].index === ctrl.active) { |
|
| 5504 | var newActiveTabIndex = index === ctrl.tabs.length - 1 ? |
|
| 5505 | index - 1 : index + 1 % ctrl.tabs.length; |
|
| 5506 | ctrl.select(newActiveTabIndex); |
|
| 5507 | } |
|
| 5508 | ||
| 5509 | ctrl.tabs.splice(index, 1); |
|
| 5510 | }; |
|
| 5511 | ||
| 5512 | $scope.$watch('tabset.active', function(val) { |
|
| 5513 | if (angular.isNumber(val) && val !== oldIndex) { |
|
| 5514 | ctrl.select(findTabIndex(val)); |
|
| 5515 | } |
|
| 5516 | }); |
|
| 5517 | ||
| 5518 | var destroyed; |
|
| 5519 | $scope.$on('$destroy', function() { |
|
| 5520 | destroyed = true; |
|
| 5521 | }); |
|
| 5522 | ||
| 5523 | function findTabIndex(index) { |
|
| 5524 | for (var i = 0; i < ctrl.tabs.length; i++) { |
|
| 5525 | if (ctrl.tabs[i].index === index) { |
|
| 5526 | return i; |
|
| 5527 | } |
|
| 5528 | } |
|
| 5529 | } |
|
| 5530 | }]) |
|
| 5531 | ||
| 5532 | .directive('uibTabset', function() { |
|
| 5533 | return { |
|
| @@ 5436-5529 (lines=94) @@ | ||
| 5433 | ||
| 5434 | angular.module('ui.bootstrap.tabs', []) |
|
| 5435 | ||
| 5436 | .controller('UibTabsetController', ['$scope', function ($scope) { |
|
| 5437 | var ctrl = this, |
|
| 5438 | oldIndex; |
|
| 5439 | ctrl.tabs = []; |
|
| 5440 | ||
| 5441 | ctrl.select = function(index, evt) { |
|
| 5442 | if (!destroyed) { |
|
| 5443 | var previousIndex = findTabIndex(oldIndex); |
|
| 5444 | var previousSelected = ctrl.tabs[previousIndex]; |
|
| 5445 | if (previousSelected) { |
|
| 5446 | previousSelected.tab.onDeselect({ |
|
| 5447 | $event: evt |
|
| 5448 | }); |
|
| 5449 | if (evt && evt.isDefaultPrevented()) { |
|
| 5450 | return; |
|
| 5451 | } |
|
| 5452 | previousSelected.tab.active = false; |
|
| 5453 | } |
|
| 5454 | ||
| 5455 | var selected = ctrl.tabs[index]; |
|
| 5456 | if (selected) { |
|
| 5457 | selected.tab.onSelect({ |
|
| 5458 | $event: evt |
|
| 5459 | }); |
|
| 5460 | selected.tab.active = true; |
|
| 5461 | ctrl.active = selected.index; |
|
| 5462 | oldIndex = selected.index; |
|
| 5463 | } else if (!selected && angular.isNumber(oldIndex)) { |
|
| 5464 | ctrl.active = null; |
|
| 5465 | oldIndex = null; |
|
| 5466 | } |
|
| 5467 | } |
|
| 5468 | }; |
|
| 5469 | ||
| 5470 | ctrl.addTab = function addTab(tab) { |
|
| 5471 | ctrl.tabs.push({ |
|
| 5472 | tab: tab, |
|
| 5473 | index: tab.index |
|
| 5474 | }); |
|
| 5475 | ctrl.tabs.sort(function(t1, t2) { |
|
| 5476 | if (t1.index > t2.index) { |
|
| 5477 | return 1; |
|
| 5478 | } |
|
| 5479 | ||
| 5480 | if (t1.index < t2.index) { |
|
| 5481 | return -1; |
|
| 5482 | } |
|
| 5483 | ||
| 5484 | return 0; |
|
| 5485 | }); |
|
| 5486 | ||
| 5487 | if (tab.index === ctrl.active || !angular.isNumber(ctrl.active) && ctrl.tabs.length === 1) { |
|
| 5488 | var newActiveIndex = findTabIndex(tab.index); |
|
| 5489 | ctrl.select(newActiveIndex); |
|
| 5490 | } |
|
| 5491 | }; |
|
| 5492 | ||
| 5493 | ctrl.removeTab = function removeTab(tab) { |
|
| 5494 | var index; |
|
| 5495 | for (var i = 0; i < ctrl.tabs.length; i++) { |
|
| 5496 | if (ctrl.tabs[i].tab === tab) { |
|
| 5497 | index = i; |
|
| 5498 | break; |
|
| 5499 | } |
|
| 5500 | } |
|
| 5501 | ||
| 5502 | if (ctrl.tabs[index].index === ctrl.active) { |
|
| 5503 | var newActiveTabIndex = index === ctrl.tabs.length - 1 ? |
|
| 5504 | index - 1 : index + 1 % ctrl.tabs.length; |
|
| 5505 | ctrl.select(newActiveTabIndex); |
|
| 5506 | } |
|
| 5507 | ||
| 5508 | ctrl.tabs.splice(index, 1); |
|
| 5509 | }; |
|
| 5510 | ||
| 5511 | $scope.$watch('tabset.active', function(val) { |
|
| 5512 | if (angular.isNumber(val) && val !== oldIndex) { |
|
| 5513 | ctrl.select(findTabIndex(val)); |
|
| 5514 | } |
|
| 5515 | }); |
|
| 5516 | ||
| 5517 | var destroyed; |
|
| 5518 | $scope.$on('$destroy', function() { |
|
| 5519 | destroyed = true; |
|
| 5520 | }); |
|
| 5521 | ||
| 5522 | function findTabIndex(index) { |
|
| 5523 | for (var i = 0; i < ctrl.tabs.length; i++) { |
|
| 5524 | if (ctrl.tabs[i].index === index) { |
|
| 5525 | return i; |
|
| 5526 | } |
|
| 5527 | } |
|
| 5528 | } |
|
| 5529 | }]) |
|
| 5530 | ||
| 5531 | .directive('uibTabset', function() { |
|
| 5532 | return { |
|