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

Commit

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

Closes #4706
  • Loading branch information
wesleycho committed Oct 23, 2015
1 parent ca3a343 commit 0010aff
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 172 deletions.
122 changes: 1 addition & 121 deletions src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
// You must provide the property on the accordion-group controller that will hold the transcluded element
.directive('uibAccordionTransclude', function() {
return {
require: ['?^uibAccordionGroup', '?^accordionGroup'],
require: '^uibAccordionGroup',
link: function(scope, element, attrs, controller) {
controller = controller[0] ? controller[0] : controller[1]; // Delete after we remove deprecation
scope.$watch(function() { return controller[attrs.uibAccordionTransclude]; }, function(heading) {
if (heading) {
element.find('span').html('');
Expand All @@ -128,122 +127,3 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
}
};
});

/* Deprecated accordion below */

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

.value('$accordionSuppressWarning', false)

.controller('AccordionController', ['$scope', '$attrs', '$controller', '$log', '$accordionSuppressWarning', function($scope, $attrs, $controller, $log, $accordionSuppressWarning) {
if (!$accordionSuppressWarning) {
$log.warn('AccordionController is now deprecated. Use UibAccordionController instead.');
}

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

.directive('accordion', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
return {
restrict: 'EA',
controller: 'AccordionController',
controllerAs: 'accordion',
transclude: true,
replace: false,
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/accordion/accordion.html';
},
link: function() {
if (!$accordionSuppressWarning) {
$log.warn('accordion is now deprecated. Use uib-accordion instead.');
}
}
};
}])

.directive('accordionGroup', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
return {
require: '^accordion', // We need this directive to be inside an accordion
restrict: 'EA',
transclude: true, // It transcludes the contents of the directive into the template
replace: true, // The element containing the directive will be replaced with the template
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/accordion/accordion-group.html';
},
scope: {
heading: '@', // Interpolate the heading attribute onto this scope
isOpen: '=?',
isDisabled: '=?'
},
controller: function() {
this.setHeading = function(element) {
this.heading = element;
};
},
link: function(scope, element, attrs, accordionCtrl) {
if (!$accordionSuppressWarning) {
$log.warn('accordion-group is now deprecated. Use uib-accordion-group instead.');
}

accordionCtrl.addGroup(scope);

scope.openClass = attrs.openClass || 'panel-open';
scope.panelClass = attrs.panelClass;
scope.$watch('isOpen', function(value) {
element.toggleClass(scope.openClass, !!value);
if (value) {
accordionCtrl.closeOthers(scope);
}
});

scope.toggleOpen = function($event) {
if (!scope.isDisabled) {
if (!$event || $event.which === 32) {
scope.isOpen = !scope.isOpen;
}
}
};
}
};
}])

.directive('accordionHeading', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
return {
restrict: 'EA',
transclude: true, // Grab the contents to be used as the heading
template: '', // In effect remove this element!
replace: true,
require: '^accordionGroup',
link: function(scope, element, attr, accordionGroupCtrl, transclude) {
if (!$accordionSuppressWarning) {
$log.warn('accordion-heading is now deprecated. Use uib-accordion-heading instead.');
}
// Pass the heading to the accordion-group controller
// so that it can be transcluded into the right place in the template
// [The second parameter to transclude causes the elements to be cloned so that they work in ng-repeat]
accordionGroupCtrl.setHeading(transclude(scope, angular.noop));
}
};
}])

.directive('accordionTransclude', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
return {
require: '^accordionGroup',
link: function(scope, element, attr, controller) {
if (!$accordionSuppressWarning) {
$log.warn('accordion-transclude is now deprecated. Use uib-accordion-transclude instead.');
}

scope.$watch(function() { return controller[attr.accordionTransclude]; }, function(heading) {
if (heading) {
element.find('span').html('');
element.find('span').append(heading);
}
});
}
};
}]);

52 changes: 1 addition & 51 deletions src/accordion/test/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('uib-accordion', function() {
it('should allow custom templates', function() {
$templateCache.put('foo/bar.html', '<div>baz</div>');

element = $compile('<accordion template-url="foo/bar.html"></accordion>')(scope);
element = $compile('<uib-accordion template-url="foo/bar.html"></uib-accordion>')(scope);
scope.$digest();
expect(element.html()).toBe('<div>baz</div>');
});
Expand Down Expand Up @@ -583,53 +583,3 @@ describe('uib-accordion', function() {
});
});
});

/* Deprecation tests below */

describe('accordion deprecation', function() {
beforeEach(module('ui.bootstrap.accordion'));
beforeEach(module('ngAnimateMock'));
beforeEach(module('template/accordion/accordion.html'));
beforeEach(module('template/accordion/accordion-group.html'));

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

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

var element =
'<accordion ng-init="a = [1,2,3]">' +
'<accordion-group heading="I get overridden">' +
'<div accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </div>' +
'Body' +
'</accordion-group>' +
'</accordion>';
element = $compile(element)($rootScope);
$rootScope.$digest();
expect($log.warn.calls.count()).toBe(0);
});
});

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

var element =
'<accordion ng-init="a = [1,2,3]">' +
'<accordion-group heading="I get overridden">' +
'<div accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </div>' +
'Body' +
'</accordion-group>' +
'</accordion>';
element = $compile(element)($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(4);
expect($log.warn.calls.argsFor(0)).toEqual(['AccordionController is now deprecated. Use UibAccordionController instead.']);
expect($log.warn.calls.argsFor(1)).toEqual(['accordion-heading is now deprecated. Use uib-accordion-heading instead.']);
expect($log.warn.calls.argsFor(2)).toEqual(['accordion-group is now deprecated. Use uib-accordion-group instead.']);
expect($log.warn.calls.argsFor(3)).toEqual(['accordion is now deprecated. Use uib-accordion instead.']);
}));
});

0 comments on commit 0010aff

Please sign in to comment.