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

Commit

Permalink
feat(tabs): remove deprecated code
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Remove deprecated directives

Closes #4710
  • Loading branch information
wesleycho committed Oct 23, 2015
1 parent a85d499 commit 1b75164
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 224 deletions.
158 changes: 2 additions & 156 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ angular.module('ui.bootstrap.tabs', [])
.directive('uibTabHeadingTransclude', function() {
return {
restrict: 'A',
require: ['?^uibTab', '?^tab'], // TODO: change to '^uibTab' after deprecation removal
require: '^uibTab',
link: function(scope, elm) {
scope.$watch('headingElement', function updateHeadingElement(heading) {
if (heading) {
Expand All @@ -253,7 +253,7 @@ angular.module('ui.bootstrap.tabs', [])
.directive('uibTabContentTransclude', function() {
return {
restrict: 'A',
require: ['?^uibTabset', '?^tabset'], // TODO: change to '^uibTabset' after deprecation removal
require: '^uibTabset',
link: function(scope, elm, attrs) {
var tab = scope.$eval(attrs.uibTabContentTransclude);

Expand All @@ -274,166 +274,12 @@ angular.module('ui.bootstrap.tabs', [])

function isTabHeading(node) {
return node.tagName && (
node.hasAttribute('tab-heading') || // TODO: remove after deprecation removal
node.hasAttribute('data-tab-heading') || // TODO: remove after deprecation removal
node.hasAttribute('x-tab-heading') || // TODO: remove after deprecation removal
node.hasAttribute('uib-tab-heading') ||
node.hasAttribute('data-uib-tab-heading') ||
node.hasAttribute('x-uib-tab-heading') ||
node.tagName.toLowerCase() === 'tab-heading' || // TODO: remove after deprecation removal
node.tagName.toLowerCase() === 'data-tab-heading' || // TODO: remove after deprecation removal
node.tagName.toLowerCase() === 'x-tab-heading' || // TODO: remove after deprecation removal
node.tagName.toLowerCase() === 'uib-tab-heading' ||
node.tagName.toLowerCase() === 'data-uib-tab-heading' ||
node.tagName.toLowerCase() === 'x-uib-tab-heading'
);
}
});

/* deprecated tabs below */

angular.module('ui.bootstrap.tabs')

.value('$tabsSuppressWarning', false)

.controller('TabsetController', ['$scope', '$controller', '$log', '$tabsSuppressWarning', function($scope, $controller, $log, $tabsSuppressWarning) {
if (!$tabsSuppressWarning) {
$log.warn('TabsetController is now deprecated. Use UibTabsetController instead.');
}

angular.extend(this, $controller('UibTabsetController', {
$scope: $scope
}));
}])

.directive('tabset', ['$log', '$tabsSuppressWarning', function($log, $tabsSuppressWarning) {
return {
restrict: 'EA',
transclude: true,
replace: true,
scope: {
type: '@'
},
controller: 'TabsetController',
templateUrl: 'template/tabs/tabset.html',
link: function(scope, element, attrs) {

if (!$tabsSuppressWarning) {
$log.warn('tabset is now deprecated. Use uib-tabset instead.');
}
scope.vertical = angular.isDefined(attrs.vertical) ? scope.$parent.$eval(attrs.vertical) : false;
scope.justified = angular.isDefined(attrs.justified) ? scope.$parent.$eval(attrs.justified) : false;
}
};
}])

.directive('tab', ['$parse', '$log', '$tabsSuppressWarning', function($parse, $log, $tabsSuppressWarning) {
return {
require: '^tabset',
restrict: 'EA',
replace: true,
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
onDeselect: '&deselect'
},
controller: function() {
//Empty controller so other directives can require being 'under' a tab
},
link: function(scope, elm, attrs, tabsetCtrl, transclude) {
if (!$tabsSuppressWarning) {
$log.warn('tab is now deprecated. Use uib-tab instead.');
}

scope.$watch('active', function(active) {
if (active) {
tabsetCtrl.select(scope);
}
});

scope.disabled = false;
if (attrs.disable) {
scope.$parent.$watch($parse(attrs.disable), function(value) {
scope.disabled = !!value;
});
}

scope.select = function() {
if (!scope.disabled) {
scope.active = true;
}
};

tabsetCtrl.addTab(scope);
scope.$on('$destroy', function() {
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;
}
};
}])

.directive('tabHeadingTransclude', ['$log', '$tabsSuppressWarning', function($log, $tabsSuppressWarning) {
return {
restrict: 'A',
require: '^tab',
link: function(scope, elm) {
if (!$tabsSuppressWarning) {
$log.warn('tab-heading-transclude is now deprecated. Use uib-tab-heading-transclude instead.');
}

scope.$watch('headingElement', function updateHeadingElement(heading) {
if (heading) {
elm.html('');
elm.append(heading);
}
});
}
};
}])

.directive('tabContentTransclude', ['$log', '$tabsSuppressWarning', function($log, $tabsSuppressWarning) {
return {
restrict: 'A',
require: '^tabset',
link: function(scope, elm, attrs) {
if (!$tabsSuppressWarning) {
$log.warn('tab-content-transclude is now deprecated. Use uib-tab-content-transclude instead.');
}

var tab = scope.$eval(attrs.tabContentTransclude);

//Now our tab is ready to be transcluded: both the tab heading area
//and the tab content area are loaded. Transclude 'em both.
tab.$transcludeFn(tab.$parent, function(contents) {
angular.forEach(contents, function(node) {
if (isTabHeading(node)) {
//Let tabHeadingTransclude know.
tab.headingElement = node;
}
else {
elm.append(node);
}
});
});
}
};

function isTabHeading(node) {
return node.tagName && (
node.hasAttribute('tab-heading') ||
node.hasAttribute('data-tab-heading') ||
node.hasAttribute('x-tab-heading') ||
node.tagName.toLowerCase() === 'tab-heading' ||
node.tagName.toLowerCase() === 'data-tab-heading' ||
node.tagName.toLowerCase() === 'x-tab-heading'
);
}
}]);
68 changes: 0 additions & 68 deletions src/tabs/test/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,71 +853,3 @@ describe('tabs', function() {
}));
});
});

/* deprecation tests below */

describe('tab deprecation', function() {
beforeEach(module('ui.bootstrap.tabs'));
beforeEach(module('template/tabs/tabset.html'));
beforeEach(module('template/tabs/tab.html'));

it('should suppress warning', function() {
module(function($provide) {
$provide.value('$tabsSuppressWarning', true);
});

inject(function($compile, $log, $rootScope) {
spyOn($log, 'warn');

var element =
'<tabset>' +
'<tab>' +
'<tab-heading>Tab Heading One</tab-heading>' +
'<div>Tab One Contents</div>' +
'</tab>' +
'<tab heading="Tab Heading Two">' +
'<div>Tab Two Contents</div>' +
'</tab>' +
'</tabset>';
$compile(element)($rootScope);
$rootScope.$digest();
expect($log.warn.calls.count()).toBe(0);
});
});

it('should give warning by default', inject(function($templateCache, $compile, $log, $rootScope) {
spyOn($log, 'warn');

var tabSetTemplate =
'<div>' +
'<ul class="nav nav-{{type || \'tabs\'}}" ng-class="{\'nav-stacked\': vertical, \'nav-justified\': justified}" ng-transclude></ul>' +
'<div class="tab-content">' +
'<div class="tab-pane" ng-repeat="tab in tabs" ng-class="{active: tab.active}" tab-content-transclude="tab"></div>' +
'</div>' +
'</div>';
$templateCache.put('template/tabs/tabset.html', tabSetTemplate);

var tabTemplate =
'<li ng-class="{active: active, disabled: disabled}">' +
'<a href ng-click="select()" tab-heading-transclude>{{heading}}</a>' +
'</li>';
$templateCache.put('template/tabs/tab.html', tabTemplate);

var element =
'<tabset>' +
'<tab>' +
'<tab-heading>Tab Heading One</tab-heading>' +
'<div>Tab One Contents</div>' +
'</tab>' +
'</tabset>';
$compile(element)($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(5);
expect($log.warn.calls.argsFor(0)).toEqual(['TabsetController is now deprecated. Use UibTabsetController instead.']);
expect($log.warn.calls.argsFor(1)).toEqual(['tab-heading-transclude is now deprecated. Use uib-tab-heading-transclude instead.']);
expect($log.warn.calls.argsFor(2)).toEqual(['tab is now deprecated. Use uib-tab instead.']);
expect($log.warn.calls.argsFor(3)).toEqual(['tabset is now deprecated. Use uib-tabset instead.']);
expect($log.warn.calls.argsFor(4)).toEqual(['tab-content-transclude is now deprecated. Use uib-tab-content-transclude instead.']);
}));
});

0 comments on commit 1b75164

Please sign in to comment.