pagination.js 4.3 KB
Newer Older
Y
Your Name 已提交
1
angular.module("ui.bootstrap.paging",[]).factory("uibPaging",["$parse",function(e){return{create:function(a,t,n){a.setNumPages=n.numPages?e(n.numPages).assign:angular.noop,a.ngModelCtrl={$setViewValue:angular.noop},a._watchers=[],a.init=function(e,i){a.ngModelCtrl=e,a.config=i,e.$render=function(){a.render()},n.itemsPerPage?a._watchers.push(t.$parent.$watch(n.itemsPerPage,function(e){a.itemsPerPage=parseInt(e,10),t.totalPages=a.calculateTotalPages(),a.updatePage()})):a.itemsPerPage=i.itemsPerPage,t.$watch("totalItems",function(e,n){(angular.isDefined(e)||e!==n)&&(t.totalPages=a.calculateTotalPages(),a.updatePage())})},a.calculateTotalPages=function(){var e=a.itemsPerPage<1?1:Math.ceil(t.totalItems/a.itemsPerPage);return Math.max(e||0,1)},a.render=function(){t.page=parseInt(a.ngModelCtrl.$viewValue,10)||1},t.selectPage=function(e,n){n&&n.preventDefault();var i=!t.ngDisabled||!n;i&&t.page!==e&&e>0&&e<=t.totalPages&&(n&&n.target&&n.target.blur(),a.ngModelCtrl.$setViewValue(e),a.ngModelCtrl.$render())},t.getText=function(e){return t[e+"Text"]||a.config[e+"Text"]},t.noPrevious=function(){return 1===t.page},t.noNext=function(){return t.page===t.totalPages},a.updatePage=function(){a.setNumPages(t.$parent,t.totalPages),t.page>t.totalPages?t.selectPage(t.totalPages):a.ngModelCtrl.$render()},t.$on("$destroy",function(){for(;a._watchers.length;)a._watchers.shift()()})}}}]),angular.module("ui.bootstrap.pager",["ui.bootstrap.paging"]).controller("UibPagerController",["$scope","$attrs","uibPaging","uibPagerConfig",function(e,a,t,n){e.align=angular.isDefined(a.align)?e.$parent.$eval(a.align):n.align,t.create(this,e,a)}]).constant("uibPagerConfig",{itemsPerPage:10,previousText:"« Previous",nextText:"Next »",align:!0}).directive("uibPager",["uibPagerConfig",function(e){return{scope:{totalItems:"=",previousText:"@",nextText:"@",ngDisabled:"="},require:["uibPager","?ngModel"],controller:"UibPagerController",controllerAs:"pager",templateUrl:function(e,a){return a.templateUrl||"./libs/pagination/template/pager/pager.html"},replace:!0,link:function(a,t,n,i){var r=i[0],o=i[1];o&&r.init(o,e)}}}]),angular.module("ui.bootstrap.pagination",["ui.bootstrap.paging"]).controller("UibPaginationController",["$scope","$attrs","$parse","uibPaging","uibPaginationConfig",function(e,a,t,n,i){function r(e,a,t){return{number:e,text:a,active:t}}function o(e,a){var t=[],n=1,i=a,o=angular.isDefined(s)&&s<a;o&&(g?(n=Math.max(e-Math.floor(s/2),1),i=n+s-1,i>a&&(i=a,n=i-s+1)):(n=(Math.ceil(e/s)-1)*s+1,i=Math.min(n+s-1,a)));for(var l=n;l<=i;l++){var f=r(l,c(l),l===e);t.push(f)}if(o&&s>0&&(!g||u||p)){if(n>1){if(!p||n>3){var P=r(n-1,"...",!1);t.unshift(P)}if(p){if(3===n){var d=r(2,"2",!1);t.unshift(d)}var b=r(1,"1",!1);t.unshift(b)}}if(i<a){if(!p||i<a-2){var m=r(i+1,"...",!1);t.push(m)}if(p){if(i===a-2){var $=r(a-1,a-1,!1);t.push($)}var v=r(a,a,!1);t.push(v)}}}return t}var l=this,s=angular.isDefined(a.maxSize)?e.$parent.$eval(a.maxSize):i.maxSize,g=angular.isDefined(a.rotate)?e.$parent.$eval(a.rotate):i.rotate,u=angular.isDefined(a.forceEllipses)?e.$parent.$eval(a.forceEllipses):i.forceEllipses,p=angular.isDefined(a.boundaryLinkNumbers)?e.$parent.$eval(a.boundaryLinkNumbers):i.boundaryLinkNumbers,c=angular.isDefined(a.pageLabel)?function(t){return e.$parent.$eval(a.pageLabel,{$page:t})}:angular.identity;e.boundaryLinks=angular.isDefined(a.boundaryLinks)?e.$parent.$eval(a.boundaryLinks):i.boundaryLinks,e.directionLinks=angular.isDefined(a.directionLinks)?e.$parent.$eval(a.directionLinks):i.directionLinks,n.create(this,e,a),a.maxSize&&l._watchers.push(e.$parent.$watch(t(a.maxSize),function(e){s=parseInt(e,10),l.render()}));var f=this.render;this.render=function(){f(),e.page>0&&e.page<=e.totalPages&&(e.pages=o(e.page,e.totalPages))}}]).constant("uibPaginationConfig",{itemsPerPage:10,boundaryLinks:!1,boundaryLinkNumbers:!1,directionLinks:!0,firstText:"First",previousText:"Previous",nextText:"Next",lastText:"Last",rotate:!0,forceEllipses:!1}).directive("uibPagination",["$parse","uibPaginationConfig",function(e,a){return{scope:{totalItems:"=",firstText:"@",previousText:"@",nextText:"@",lastText:"@",ngDisabled:"="},require:["uibPagination","?ngModel"],controller:"UibPaginationController",controllerAs:"pagination",templateUrl:function(e,a){return a.templateUrl||"./libs/pagination/template/pagination/pagination.html"},replace:!0,link:function(e,t,n,i){var r=i[0],o=i[1];o&&r.init(o,a)}}}]);