diff --git a/src/accordion/accordion.js b/src/accordion/accordion.js index 93a71eeb45..b2ab87ca5f 100644 --- a/src/accordion/accordion.js +++ b/src/accordion/accordion.js @@ -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(''); @@ -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); - } - }); - } - }; - }]); - diff --git a/src/accordion/test/accordion.spec.js b/src/accordion/test/accordion.spec.js index f7b669b279..ed22de6360 100644 --- a/src/accordion/test/accordion.spec.js +++ b/src/accordion/test/accordion.spec.js @@ -139,7 +139,7 @@ describe('uib-accordion', function() { it('should allow custom templates', function() { $templateCache.put('foo/bar.html', '
baz
'); - element = $compile('')(scope); + element = $compile('')(scope); scope.$digest(); expect(element.html()).toBe('
baz
'); }); @@ -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 = - '' + - '' + - '
Heading Element {{x}}
' + - 'Body' + - '
' + - '
'; - 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 = - '' + - '' + - '
Heading Element {{x}}
' + - 'Body' + - '
' + - '
'; - 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.']); - })); -});