paulwalko.github.io/javascripts/pagination.js

11 lines
12 KiB
JavaScript
Raw Normal View History

2016-06-14 21:54:24 -04:00
/*
* pagination.js 2.0.5
* A jQuery plugin to provide simple yet fully customisable pagination
* https://github.com/superRaytin/paginationjs
* Homepage: http://paginationjs.com
*
* Copyright 2014-2100, superRaytin
* Released under the MIT license.
*/
!function(a,b){function c(a){throw new Error("Pagination: "+a)}function d(a){a.dataSource||c('"dataSource" is required.'),"string"==typeof a.dataSource?"undefined"==typeof a.totalNumber?c('"totalNumber" is required.'):b.isNumeric(a.totalNumber)||c('"totalNumber" is incorrect. (Number)'):i.isObject(a.dataSource)&&("undefined"==typeof a.locator?c('"dataSource" is a Object, please specify "locator".'):"string"==typeof a.locator||b.isFunction(a.locator)||c(""+a.locator+" is incorrect. (String | Function)"))}function e(a){var b;return("object"==(b=typeof a)?null==a&&"null"||Object.prototype.toString.call(a).slice(8,-1):b).toLowerCase()}"undefined"==typeof b&&c("Pagination requires jQuery.");var f="pagination",g="addHook",h="__pagination-";b.fn.pagination&&(f="pagination2"),b.fn[f]=function(e){if("undefined"==typeof e)return this;var f=b(this),g={initialize:function(){var a=this;if(f.data("pagination")||f.data("pagination",{}),a.callHook("beforeInit")!==!1){f.data("pagination").initialized&&b(".paginationjs",f).remove();var c=a.model={pageRange:k.pageRange,pageSize:k.pageSize};a.parseDataSource(k.dataSource,function(b){if(a.sync=i.isArray(b),a.sync&&(c.totalNumber=k.totalNumber=b.length),c.totalPage=a.getTotalPage(),!(k.hideWhenLessThanOnePage&&c.totalPage<=1)){var d=a.render(!0);k.className&&d.addClass(k.className),c.el=d,f["bottom"===k.position?"append":"prepend"](d),a.observer(),f.data("pagination").initialized=!0,a.callHook("afterInit",d)}})}},render:function(a){var c=this,d=c.model,e=d.el||b('<div class="paginationjs"></div>'),f=a!==!0;c.callHook("beforeRender",f);var g=d.pageNumber||k.pageNumber,h=k.pageRange,i=d.totalPage,j=g-h,l=g+h;return l>i&&(l=i,j=i-2*h,j=1>j?1:j),1>=j&&(j=1,l=Math.min(2*h+1,i)),e.html(c.createTemplate({currentPage:g,pageRange:h,totalPage:i,rangeStart:j,rangeEnd:l})),c.callHook("afterRender",f),e},createTemplate:function(a){var c,d,e=this,f=a.currentPage,g=a.totalPage,h=a.rangeStart,i=a.rangeEnd,j=k.totalNumber,l=k.showPrevious,m=k.showNext,n=k.showPageNumbers,o=k.showNavigator,p=k.showGoInput,q=k.showGoButton,r=k.pageLink,s=k.prevText,t=k.nextText,u=k.ellipsisText,v=k.goButtonText,w=k.classPrefix,x=k.activeClassName,y=k.disableClassName,z=k.ulClassName,A=b.isFunction(k.formatNavigator)?k.formatNavigator():k.formatNavigator,B=b.isFunction(k.formatGoInput)?k.formatGoInput():k.formatGoInput,C=b.isFunction(k.formatGoButton)?k.formatGoButton():k.formatGoButton,D=b.isFunction(k.autoHidePrevious)?k.autoHidePrevious():k.autoHidePrevious,E=b.isFunction(k.autoHideNext)?k.autoHideNext():k.autoHideNext,F=b.isFunction(k.header)?k.header():k.header,G=b.isFunction(k.footer)?k.footer():k.footer,H="",I='<input type="text" class="J-paginationjs-go-pagenumber">',J='<input type="button" class="J-paginationjs-go-button" value="'+v+'">';if(F&&(c=e.replaceVariables(F,{currentPage:f,totalPage:g,totalNumber:j}),H+=c),l||n||m){if(H+='<div class="paginationjs-pages">',H+=z?'<ul class="'+z+'">':"<ul>",l&&(1===f?D||(H+='<li class="'+w+"-prev "+y+'"><a href="#">'+s+"</a></li>"):H+='<li class="'+w+'-prev J-paginationjs-previous" data-num="'+(f-1)+'" title="Previous page"><a href="'+r+'">'+s+"</a></li>"),n){if(3>=h)for(d=1;h>d;d++)H+=d==f?'<li class="'+w+"-page J-paginationjs-page "+x+'" data-num="'+d+'"><a href="#">'+d+"</a></li>":'<li class="'+w+'-page J-paginationjs-page" data-num="'+d+'"><a href="'+r+'">'+d+"</a></li>";else k.showFirstOnEllipsisShow&&(H+='<li class="'+w+"-page "+w+'-first J-paginationjs-page" data-num="1"><a href="'+r+'">1</a></li>'),H+='<li class="'+w+"-ellipsis "+y+'"><a href="#">'+u+"</a></li>";for(d=h;i>=d;d++)H+=d==f?'<li class="'+w+"-page J-paginationjs-page "+x+'" data-num="'+d+'"><a href="#">'+d+"</a></li>":'<li class="'+w+'-page J-paginationjs-page" data-num="'+d+'"><a href="'+r+'">'+d+"</a></li>";if(i>=g-2)for(d=i+1;g>=d;d++)H+='<li class="'+w+'-page J-paginationjs-page" data-num="'+d+'"><a href="'+r+'">'+d+"</a></li>";else H+='<li class="'+w+"-ellipsis "+y+'"><a href="#">'+u+"</a></li>",k.showLastOnEllipsisShow&&(H+='<li class="'+w+"-page "+w+'-last J-paginationjs-page" data-num="'+g+'"><a href="