From 00e2ea3a62d6bac07ca9d115194a5f136c434051 Mon Sep 17 00:00:00 2001 From: Foxandxss Date: Sat, 24 Oct 2015 00:34:30 +0200 Subject: [PATCH] feat(pagination): remove deprecated code --- src/pagination/pagination.js | 226 ------------------------- src/pagination/test/pager.spec.js | 30 ---- src/pagination/test/pagination.spec.js | 30 ---- 3 files changed, 286 deletions(-) diff --git a/src/pagination/pagination.js b/src/pagination/pagination.js index 1e75dcfd5e..da611fd594 100644 --- a/src/pagination/pagination.js +++ b/src/pagination/pagination.js @@ -229,229 +229,3 @@ angular.module('ui.bootstrap.pagination', []) } }; }]); - -/* Deprecated Pagination Below */ - -angular.module('ui.bootstrap.pagination') -.value('$paginationSuppressWarning', false) -.controller('PaginationController', ['$scope', '$attrs', '$parse', '$log', '$paginationSuppressWarning', function($scope, $attrs, $parse, $log, $paginationSuppressWarning) { - if (!$paginationSuppressWarning) { - $log.warn('PaginationController is now deprecated. Use UibPaginationController instead.'); - } - - var self = this, - ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl - setNumPages = $attrs.numPages ? $parse($attrs.numPages).assign : angular.noop; - - this.init = function(ngModelCtrl_, config) { - ngModelCtrl = ngModelCtrl_; - this.config = config; - - ngModelCtrl.$render = function() { - self.render(); - }; - - if ($attrs.itemsPerPage) { - $scope.$parent.$watch($parse($attrs.itemsPerPage), function(value) { - self.itemsPerPage = parseInt(value, 10); - $scope.totalPages = self.calculateTotalPages(); - }); - } else { - this.itemsPerPage = config.itemsPerPage; - } - - $scope.$watch('totalItems', function() { - $scope.totalPages = self.calculateTotalPages(); - }); - - $scope.$watch('totalPages', function(value) { - setNumPages($scope.$parent, value); // Readonly variable - - if ( $scope.page > value ) { - $scope.selectPage(value); - } else { - ngModelCtrl.$render(); - } - }); - }; - - this.calculateTotalPages = function() { - var totalPages = this.itemsPerPage < 1 ? 1 : Math.ceil($scope.totalItems / this.itemsPerPage); - return Math.max(totalPages || 0, 1); - }; - - this.render = function() { - $scope.page = parseInt(ngModelCtrl.$viewValue, 10) || 1; - }; - - $scope.selectPage = function(page, evt) { - if (evt) { - evt.preventDefault(); - } - - var clickAllowed = !$scope.ngDisabled || !evt; - if (clickAllowed && $scope.page !== page && page > 0 && page <= $scope.totalPages) { - if (evt && evt.target) { - evt.target.blur(); - } - ngModelCtrl.$setViewValue(page); - ngModelCtrl.$render(); - } - }; - - $scope.getText = function(key) { - return $scope[key + 'Text'] || self.config[key + 'Text']; - }; - - $scope.noPrevious = function() { - return $scope.page === 1; - }; - - $scope.noNext = function() { - return $scope.page === $scope.totalPages; - }; -}]) -.directive('pagination', ['$parse', 'uibPaginationConfig', '$log', '$paginationSuppressWarning', function($parse, paginationConfig, $log, $paginationSuppressWarning) { - return { - restrict: 'EA', - scope: { - totalItems: '=', - firstText: '@', - previousText: '@', - nextText: '@', - lastText: '@', - ngDisabled:'=' - }, - require: ['pagination', '?ngModel'], - controller: 'PaginationController', - controllerAs: 'pagination', - templateUrl: function(element, attrs) { - return attrs.templateUrl || 'template/pagination/pagination.html'; - }, - replace: true, - link: function(scope, element, attrs, ctrls) { - if (!$paginationSuppressWarning) { - $log.warn('pagination is now deprecated. Use uib-pagination instead.'); - } - var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1]; - - if (!ngModelCtrl) { - return; // do nothing if no ng-model - } - - // Setup configuration parameters - var maxSize = angular.isDefined(attrs.maxSize) ? scope.$parent.$eval(attrs.maxSize) : paginationConfig.maxSize, - rotate = angular.isDefined(attrs.rotate) ? scope.$parent.$eval(attrs.rotate) : paginationConfig.rotate; - scope.boundaryLinks = angular.isDefined(attrs.boundaryLinks) ? scope.$parent.$eval(attrs.boundaryLinks) : paginationConfig.boundaryLinks; - scope.directionLinks = angular.isDefined(attrs.directionLinks) ? scope.$parent.$eval(attrs.directionLinks) : paginationConfig.directionLinks; - - paginationCtrl.init(ngModelCtrl, paginationConfig); - - if (attrs.maxSize) { - scope.$parent.$watch($parse(attrs.maxSize), function(value) { - maxSize = parseInt(value, 10); - paginationCtrl.render(); - }); - } - - // Create page object used in template - function makePage(number, text, isActive) { - return { - number: number, - text: text, - active: isActive - }; - } - - function getPages(currentPage, totalPages) { - var pages = []; - - // Default page limits - var startPage = 1, endPage = totalPages; - var isMaxSized = angular.isDefined(maxSize) && maxSize < totalPages; - - // recompute if maxSize - if (isMaxSized) { - if (rotate) { - // Current page is displayed in the middle of the visible ones - startPage = Math.max(currentPage - Math.floor(maxSize/2), 1); - endPage = startPage + maxSize - 1; - - // Adjust if limit is exceeded - if (endPage > totalPages) { - endPage = totalPages; - startPage = endPage - maxSize + 1; - } - } else { - // Visible pages are paginated with maxSize - startPage = ((Math.ceil(currentPage / maxSize) - 1) * maxSize) + 1; - - // Adjust last page if limit is exceeded - endPage = Math.min(startPage + maxSize - 1, totalPages); - } - } - - // Add page number links - for (var number = startPage; number <= endPage; number++) { - var page = makePage(number, number, number === currentPage); - pages.push(page); - } - - // Add links to move between page sets - if (isMaxSized && ! rotate) { - if (startPage > 1) { - var previousPageSet = makePage(startPage - 1, '...', false); - pages.unshift(previousPageSet); - } - - if (endPage < totalPages) { - var nextPageSet = makePage(endPage + 1, '...', false); - pages.push(nextPageSet); - } - } - - return pages; - } - - var originalRender = paginationCtrl.render; - paginationCtrl.render = function() { - originalRender(); - if (scope.page > 0 && scope.page <= scope.totalPages) { - scope.pages = getPages(scope.page, scope.totalPages); - } - }; - } - }; -}]) - -.directive('pager', ['uibPagerConfig', '$log', '$paginationSuppressWarning', function(pagerConfig, $log, $paginationSuppressWarning) { - return { - restrict: 'EA', - scope: { - totalItems: '=', - previousText: '@', - nextText: '@', - ngDisabled: '=' - }, - require: ['pager', '?ngModel'], - controller: 'PaginationController', - controllerAs: 'pagination', - templateUrl: function(element, attrs) { - return attrs.templateUrl || 'template/pagination/pager.html'; - }, - replace: true, - link: function(scope, element, attrs, ctrls) { - if (!$paginationSuppressWarning) { - $log.warn('pager is now deprecated. Use uib-pager instead.'); - } - var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1]; - - if (!ngModelCtrl) { - return; // do nothing if no ng-model - } - - scope.align = angular.isDefined(attrs.align) ? scope.$parent.$eval(attrs.align) : pagerConfig.align; - paginationCtrl.init(ngModelCtrl, pagerConfig); - } - }; -}]); diff --git a/src/pagination/test/pager.spec.js b/src/pagination/test/pager.spec.js index 3756d7062a..bfd39639c5 100644 --- a/src/pagination/test/pager.spec.js +++ b/src/pagination/test/pager.spec.js @@ -279,33 +279,3 @@ describe('pager directive', function() { expect(getPaginationEl(-1)).toHaveClass('disabled'); }); }); - -describe('pager deprecation', function() { - beforeEach(module('ui.bootstrap.pagination')); - beforeEach(module('template/pagination/pager.html')); - - it('should suppress warning', function() { - module(function($provide) { - $provide.value('$paginationSuppressWarning', true); - }); - - inject(function($compile, $log, $rootScope) { - spyOn($log, 'warn'); - - var element = $compile('')($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 = $compile('')($rootScope); - $rootScope.$digest(); - - expect($log.warn.calls.count()).toBe(2); - expect($log.warn.calls.argsFor(0)).toEqual(['PaginationController is now deprecated. Use UibPaginationController instead.']); - expect($log.warn.calls.argsFor(1)).toEqual(['pager is now deprecated. Use uib-pager instead.']); - })); -}); \ No newline at end of file diff --git a/src/pagination/test/pagination.spec.js b/src/pagination/test/pagination.spec.js index a3ef25097f..d18e7e8338 100644 --- a/src/pagination/test/pagination.spec.js +++ b/src/pagination/test/pagination.spec.js @@ -734,33 +734,3 @@ describe('pagination directive', function() { }); }); }); - -describe('pagination deprecation', function() { - beforeEach(module('ui.bootstrap.pagination')); - beforeEach(module('template/pagination/pagination.html')); - - it('should suppress warning', function() { - module(function($provide) { - $provide.value('$paginationSuppressWarning', true); - }); - - inject(function($compile, $log, $rootScope) { - spyOn($log, 'warn'); - - var element = $compile('')($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 = $compile('')($rootScope); - $rootScope.$digest(); - - expect($log.warn.calls.count()).toBe(2); - expect($log.warn.calls.argsFor(0)).toEqual(['PaginationController is now deprecated. Use UibPaginationController instead.']); - expect($log.warn.calls.argsFor(1)).toEqual(['pagination is now deprecated. Use uib-pagination instead.']); - })); -});