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

Commit 0010aff

Browse files
committed
feat(accordion): remove deprecated code
BREAKING CHANGE: Remove deprecated non-prefixed directives Closes #4706
1 parent ca3a343 commit 0010aff

File tree

2 files changed

+2
-172
lines changed

2 files changed

+2
-172
lines changed

src/accordion/accordion.js

+1-121
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
116116
// You must provide the property on the accordion-group controller that will hold the transcluded element
117117
.directive('uibAccordionTransclude', function() {
118118
return {
119-
require: ['?^uibAccordionGroup', '?^accordionGroup'],
119+
require: '^uibAccordionGroup',
120120
link: function(scope, element, attrs, controller) {
121-
controller = controller[0] ? controller[0] : controller[1]; // Delete after we remove deprecation
122121
scope.$watch(function() { return controller[attrs.uibAccordionTransclude]; }, function(heading) {
123122
if (heading) {
124123
element.find('span').html('');
@@ -128,122 +127,3 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
128127
}
129128
};
130129
});
131-
132-
/* Deprecated accordion below */
133-
134-
angular.module('ui.bootstrap.accordion')
135-
136-
.value('$accordionSuppressWarning', false)
137-
138-
.controller('AccordionController', ['$scope', '$attrs', '$controller', '$log', '$accordionSuppressWarning', function($scope, $attrs, $controller, $log, $accordionSuppressWarning) {
139-
if (!$accordionSuppressWarning) {
140-
$log.warn('AccordionController is now deprecated. Use UibAccordionController instead.');
141-
}
142-
143-
angular.extend(this, $controller('UibAccordionController', {
144-
$scope: $scope,
145-
$attrs: $attrs
146-
}));
147-
}])
148-
149-
.directive('accordion', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
150-
return {
151-
restrict: 'EA',
152-
controller: 'AccordionController',
153-
controllerAs: 'accordion',
154-
transclude: true,
155-
replace: false,
156-
templateUrl: function(element, attrs) {
157-
return attrs.templateUrl || 'template/accordion/accordion.html';
158-
},
159-
link: function() {
160-
if (!$accordionSuppressWarning) {
161-
$log.warn('accordion is now deprecated. Use uib-accordion instead.');
162-
}
163-
}
164-
};
165-
}])
166-
167-
.directive('accordionGroup', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
168-
return {
169-
require: '^accordion', // We need this directive to be inside an accordion
170-
restrict: 'EA',
171-
transclude: true, // It transcludes the contents of the directive into the template
172-
replace: true, // The element containing the directive will be replaced with the template
173-
templateUrl: function(element, attrs) {
174-
return attrs.templateUrl || 'template/accordion/accordion-group.html';
175-
},
176-
scope: {
177-
heading: '@', // Interpolate the heading attribute onto this scope
178-
isOpen: '=?',
179-
isDisabled: '=?'
180-
},
181-
controller: function() {
182-
this.setHeading = function(element) {
183-
this.heading = element;
184-
};
185-
},
186-
link: function(scope, element, attrs, accordionCtrl) {
187-
if (!$accordionSuppressWarning) {
188-
$log.warn('accordion-group is now deprecated. Use uib-accordion-group instead.');
189-
}
190-
191-
accordionCtrl.addGroup(scope);
192-
193-
scope.openClass = attrs.openClass || 'panel-open';
194-
scope.panelClass = attrs.panelClass;
195-
scope.$watch('isOpen', function(value) {
196-
element.toggleClass(scope.openClass, !!value);
197-
if (value) {
198-
accordionCtrl.closeOthers(scope);
199-
}
200-
});
201-
202-
scope.toggleOpen = function($event) {
203-
if (!scope.isDisabled) {
204-
if (!$event || $event.which === 32) {
205-
scope.isOpen = !scope.isOpen;
206-
}
207-
}
208-
};
209-
}
210-
};
211-
}])
212-
213-
.directive('accordionHeading', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
214-
return {
215-
restrict: 'EA',
216-
transclude: true, // Grab the contents to be used as the heading
217-
template: '', // In effect remove this element!
218-
replace: true,
219-
require: '^accordionGroup',
220-
link: function(scope, element, attr, accordionGroupCtrl, transclude) {
221-
if (!$accordionSuppressWarning) {
222-
$log.warn('accordion-heading is now deprecated. Use uib-accordion-heading instead.');
223-
}
224-
// Pass the heading to the accordion-group controller
225-
// so that it can be transcluded into the right place in the template
226-
// [The second parameter to transclude causes the elements to be cloned so that they work in ng-repeat]
227-
accordionGroupCtrl.setHeading(transclude(scope, angular.noop));
228-
}
229-
};
230-
}])
231-
232-
.directive('accordionTransclude', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
233-
return {
234-
require: '^accordionGroup',
235-
link: function(scope, element, attr, controller) {
236-
if (!$accordionSuppressWarning) {
237-
$log.warn('accordion-transclude is now deprecated. Use uib-accordion-transclude instead.');
238-
}
239-
240-
scope.$watch(function() { return controller[attr.accordionTransclude]; }, function(heading) {
241-
if (heading) {
242-
element.find('span').html('');
243-
element.find('span').append(heading);
244-
}
245-
});
246-
}
247-
};
248-
}]);
249-

src/accordion/test/accordion.spec.js

+1-51
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('uib-accordion', function() {
139139
it('should allow custom templates', function() {
140140
$templateCache.put('foo/bar.html', '<div>baz</div>');
141141

142-
element = $compile('<accordion template-url="foo/bar.html"></accordion>')(scope);
142+
element = $compile('<uib-accordion template-url="foo/bar.html"></uib-accordion>')(scope);
143143
scope.$digest();
144144
expect(element.html()).toBe('<div>baz</div>');
145145
});
@@ -583,53 +583,3 @@ describe('uib-accordion', function() {
583583
});
584584
});
585585
});
586-
587-
/* Deprecation tests below */
588-
589-
describe('accordion deprecation', function() {
590-
beforeEach(module('ui.bootstrap.accordion'));
591-
beforeEach(module('ngAnimateMock'));
592-
beforeEach(module('template/accordion/accordion.html'));
593-
beforeEach(module('template/accordion/accordion-group.html'));
594-
595-
it('should suppress warning', function() {
596-
module(function($provide) {
597-
$provide.value('$accordionSuppressWarning', true);
598-
});
599-
600-
inject(function($compile, $log, $rootScope) {
601-
spyOn($log, 'warn');
602-
603-
var element =
604-
'<accordion ng-init="a = [1,2,3]">' +
605-
'<accordion-group heading="I get overridden">' +
606-
'<div accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </div>' +
607-
'Body' +
608-
'</accordion-group>' +
609-
'</accordion>';
610-
element = $compile(element)($rootScope);
611-
$rootScope.$digest();
612-
expect($log.warn.calls.count()).toBe(0);
613-
});
614-
});
615-
616-
it('should give warning by default', inject(function($compile, $log, $rootScope) {
617-
spyOn($log, 'warn');
618-
619-
var element =
620-
'<accordion ng-init="a = [1,2,3]">' +
621-
'<accordion-group heading="I get overridden">' +
622-
'<div accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </div>' +
623-
'Body' +
624-
'</accordion-group>' +
625-
'</accordion>';
626-
element = $compile(element)($rootScope);
627-
$rootScope.$digest();
628-
629-
expect($log.warn.calls.count()).toBe(4);
630-
expect($log.warn.calls.argsFor(0)).toEqual(['AccordionController is now deprecated. Use UibAccordionController instead.']);
631-
expect($log.warn.calls.argsFor(1)).toEqual(['accordion-heading is now deprecated. Use uib-accordion-heading instead.']);
632-
expect($log.warn.calls.argsFor(2)).toEqual(['accordion-group is now deprecated. Use uib-accordion-group instead.']);
633-
expect($log.warn.calls.argsFor(3)).toEqual(['accordion is now deprecated. Use uib-accordion instead.']);
634-
}));
635-
});

0 commit comments

Comments
 (0)