Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
refactor(tabs): use optional binding for active
Browse files Browse the repository at this point in the history
Closes #1713
  • Loading branch information
bekos authored and pkozlowski-opensource committed Jan 31, 2014
1 parent 4f56e60 commit ab0387c
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ angular.module('ui.bootstrap.tabs', [])
templateUrl: 'template/tabs/tab.html',
transclude: true,
scope: {
active: '=?',
heading: '@',
onSelect: '&select', //This callback is called in contentHeadingTransclude
//once it inserts the tab's content into the dom
Expand All @@ -192,27 +193,7 @@ angular.module('ui.bootstrap.tabs', [])
},
compile: function(elm, attrs, transclude) {
return function postLink(scope, elm, attrs, tabsetCtrl) {
var getActive, setActive;
if (attrs.active) {
getActive = $parse(attrs.active);
setActive = getActive.assign;
scope.$parent.$watch(getActive, function updateActive(value, oldVal) {
// Avoid re-initializing scope.active as it is already initialized
// below. (watcher is called async during init with value ===
// oldVal)
if (value !== oldVal) {
scope.active = !!value;
}
});
scope.active = getActive(scope.$parent);
} else {
setActive = getActive = angular.noop;
}

scope.$watch('active', function(active) {
// Note this watcher also initializes and assigns scope.active to the
// attrs.active expression.
setActive(scope.$parent, active);
if (active) {
tabsetCtrl.select(scope);
}
Expand All @@ -226,7 +207,7 @@ angular.module('ui.bootstrap.tabs', [])
}

scope.select = function() {
if ( ! scope.disabled ) {
if ( !scope.disabled ) {
scope.active = true;
}
};
Expand All @@ -236,7 +217,6 @@ angular.module('ui.bootstrap.tabs', [])
tabsetCtrl.removeTab(scope);
});


//We need to transclude later, once the content container is ready.
//when this link happens, we're inside a tab heading.
scope.$transcludeFn = transclude;
Expand Down

0 comments on commit ab0387c

Please sign in to comment.