PHP Classes

File: src/js/Paginator.min.js

Recommend this page to a friend!
  Classes of Nikos M.   Alt PHP Paginator   src/js/Paginator.min.js   Download  
File: src/js/Paginator.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Alt PHP Paginator
Generate pagination controls for Web pages
Author: By
Last change:
Date: 3 years ago
Size: 5,710 bytes
 

Contents

Class file image Download
/** * Paginator * Simple and versatile Pagination utility class for PHP, Python, Node.js / Browser Javascript * * @version: 1.0.0 * https://github.com/foo123/Paginator * **/ !function(e,t,n){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils.import?(e.$deps=e.$deps||{})&&(e.EXPORTED_SYMBOLS=[t])&&(e[t]=e.$deps[t]=n.call(e)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[t]=n.call(e)):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(t)?define(t,["module"],function(t){return n.moduleUri=t.uri,n.call(e)}):t in e||(e[t]=n.call(e)||1)&&"function"==typeof define&&define.amd&&define(function(){return e[t]})}("undefined"!=typeof self?self:this,"Paginator",function(e){"use strict";function t(e){return String(e).replace(r,function(e){switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";default:return e}})}function n(e,t,n){var r=this;r._maxPagesToShow=10,r._placeholder="(:page)",r._urlPattern="?page="+r._placeholder,r._previousText="&laquo; Previous",r._nextText="Next &raquo;",r._ellipsis="...",r._view="list",r._numPages=0,r._totalItems=parseInt(e||0),r._itemsPerPage=parseInt(t||0),r._currentPage=parseInt(n||1),r.computeNumPages()}var r=/[&<>'"]/g;return n.VERSION="1.0.0",n.prototype={constructor:n,_totalItems:null,_itemsPerPage:null,_currentPage:null,_numPages:null,_maxPagesToShow:null,_placeholder:null,_urlPattern:null,_previousText:null,_nextText:null,_ellipsis:null,_view:null,computeNumPages:function(){var e=this;return e._numPages=0>=e._itemsPerPage||0>=e._totalItems?0:Math.ceil(e._totalItems/e._itemsPerPage),e},numPages:function(){return this._numPages},totalItems:function(e){var t=this;return arguments.length?(t._totalItems=parseInt(e),t.computeNumPages()):t._totalItems},itemsPerPage:function(e){var t=this;return arguments.length?(t._itemsPerPage=parseInt(e),t.computeNumPages()):t._itemsPerPage},currentPage:function(e){var t=this;return arguments.length?(t._currentPage=parseInt(e),t):t._currentPage},maxPagesToShow:function(e){var t=this;if(arguments.length){if((e=parseInt(e))<3)throw new TypeError("maxPagesToShow cannot be less than 3!");return t._maxPagesToShow=e,t}return t._maxPagesToShow},urlPattern:function(e){var t=this;return arguments.length?(t._urlPattern=String(e),t):t._urlPattern},placeholder:function(e){var t=this;return arguments.length?(t._placeholder=String(e),t):t._placeholder},previousText:function(e){var t=this;return arguments.length?(t._previousText=String(e),t):t._previousText},nextText:function(e){var t=this;return arguments.length?(t._nextText=String(e),t):t._nextText},ellipsis:function(e){var t=this;return arguments.length?(t._ellipsis=String(e),t):t._ellipsis},view:function(e){var t=this;if(arguments.length){switch(e=String(e).toLowerCase()){case"mobile":case"selectbox":case"select":e="selectbox";break;default:e="list"}return t._view=e,t}return t._view},pageUrl:function(e){return this._urlPattern.split(this._placeholder).join(String(e))},prevPage:function(){return this._currentPage>1?this._currentPage-1:null},nextPage:function(){return this._currentPage<this._numPages?this._currentPage+1:null},prevUrl:function(){return this.prevPage()?this.pageUrl(this.prevPage()):null},nextUrl:function(){return this.nextPage()?this.pageUrl(this.nextPage()):null},currentPageFirstItem:function(){var e=(this._currentPage-1)*this._itemsPerPage+1;return e>this._totalItems?null:e},currentPageLastItem:function(){var e,t=this.currentPageFirstItem();return null==t?null:(e=t+this._itemsPerPage-1)>this._totalItems?this._totalItems:e},pages:function(){var e,t,n,r,s,a=this,u=[];if(1>=a._numPages)return u;if(a._numPages<=a._maxPagesToShow)for(e=1,t=a._numPages;e<=t;e++)u.push(a.createPage(e,e==a._currentPage));else{for(n=Math.floor((a._maxPagesToShow-3)/2),(r=a._currentPage+n>a._numPages?a._numPages-a._maxPagesToShow+2:a._currentPage-n)<2&&(r=2),(s=r+a._maxPagesToShow-3)>=a._numPages&&(s=a._numPages-1),u.push(a.createPage(1,1==a._currentPage)),r>2&&u.push(a.createPage(null)),e=r;e<=s;e++)u.push(a.createPage(e,e==a._currentPage));s<a._numPages-1&&u.push(a.createPage(null)),u.push(a.createPage(a._numPages,a._numPages==a._currentPage))}return u},createPage:function(e,t){return null==e?{num:this._ellipsis,url:null,isCurrent:!1}:{num:e,url:this.pageUrl(e),isCurrent:!!t}},render:function(){var e,n,r,s,a,u=this;if(1>=u._numPages)return"";if("selectbox"===u._view){for(e='<div class="pagination">',u.prevUrl()&&(e+='<span class="page-previous"><a href="'+t(u.prevUrl())+'">'+u._previousText+"</a></span>"),e+='<select class="page-select">',r=0,s=(n=u.pages()).length;r<s;r++)(a=n[r]).url?e+='<option value="'+t(a.url)+'"'+(a.isCurrent?" selected":"")+">"+String(a.num)+"</option>":e+="<option disabled>"+String(a.num)+"</option>";e+="</select>",u.nextUrl()&&(e+='<span class="page-next"><a href="'+t(u.nextUrl())+'">'+u._nextText+"</a></span>"),e+="</div>"}else{for(e='<ul class="pagination">',u.prevUrl()&&(e+='<li class="page-previous"><a href="'+t(u.prevUrl())+'">'+u._previousText+"</a></li>"),r=0,s=(n=u.pages()).length;r<s;r++)(a=n[r]).url?e+='<li class="page-item'+(1==a.num?" first":"")+(u._numPages==a.num?" last":"")+(a.isCurrent?" active":"")+'"><a href="'+t(a.url)+'">'+String(a.num)+"</a></li>":e+='<li class="page-item disabled"><span>'+String(a.num)+"</span></li>";u.nextUrl()&&(e+='<li class="page-next"><a href="'+t(u.nextUrl())+'">'+u._nextText+"</a></li>"),e+="</ul>"}return e},toString:function(){return this.render()}},n});