summaryrefslogtreecommitdiffstats
path: root/VNF_Catalogue/public/3rd_party/materialize-pagination.min.js
blob: c7b712c96a920976e4e63217abdfd1f3360adbf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
/* materialize Pagination v0.2.2 | http://mirjamsk.github.io/materialize-pagination */
;(function(c,f,g,k){var d=function(a,b){this.$elem=c(a);this.options=b;this.currentPage=this.$nextEllipsis=this.$prevEllipsis=this.$container=null;this.visiblePages=[];this.maxVisiblePages=3};d.prototype={defaults:{align:"center",lastPage:1,firstPage:1,urlParameter:"page",useUrlParameter:!0,onClickCallback:function(){}},init:function(){this.config=c.extend({},this.defaults,this.options);var a=this.config.useUrlParameter?this.parseUrl():this.config.firstPage;this.createPaginationBase(a)&&this.bindClickEvent()},
createPaginationBase:function(a){if(isNaN(this.config.firstPage)||isNaN(this.config.lastPage))return console.error("Both firstPage and lastPage attributes need to be integer values"),!1;if(this.config.firstPage>this.config.lastPage)return console.error("Value of firstPage must be less than the value of lastPage"),!1;this.config.firstPage=parseInt(this.config.firstPage);this.config.lastPage=parseInt(this.config.lastPage);this.currentPage=this.config.firstPage-this.maxVisiblePages;this.$container=c("<ul>").addClass("pagination").addClass(this.config.align+
"-align");this.$prevEllipsis=this.util.Ellipsis();this.$nextEllipsis=this.util.Ellipsis();var b=this.util.createPage(this.config.firstPage),h=this.util.createChevron("prev"),e=this.util.createChevron("next");this.$container.append(h).append(b).append(this.$prevEllipsis.$elem).append(this.$nextEllipsis.$elem).append(e);this.config.lastPage>this.config.firstPage&&this.util.createPage(this.config.lastPage).insertBefore(e);this.requestPage(a);this.renderActivePage();this.$elem.append(this.$container);
return!0},requestPage:function(a){switch(a){case this.currentPage:return;case this.currentPage-1:this.requestPrevPage();break;case this.currentPage+1:this.requestNextPage();break;default:this.requestPageByNumber(a)}this.config.onClickCallback(this.currentPage);this.renderActivePage();this.config.useUrlParameter&&this.updateUrlParam(this.config.urlParameter,this.currentPage)},requestPrevPage:function(){--this.currentPage;this.visiblePages.pop().remove();this.visiblePages.unshift(this.insertPrevPaginationComponent(this.currentPage-
1))},requestNextPage:function(){this.currentPage+=1;this.visiblePages.shift().remove();this.visiblePages.push(this.insertNextPaginationComponent(this.currentPage+1))},requestPageByNumber:function(a){this.purgeVisiblePages();this.currentPage=a;this.visiblePages.push(this.insertNextPaginationComponent(this.currentPage-1));this.visiblePages.push(this.insertNextPaginationComponent(this.currentPage));this.visiblePages.push(this.insertNextPaginationComponent(this.currentPage+1))},renderActivePage:function(){this.renderEllipsis();
this.$container.find("li.active").removeClass("active");c(this.$container.find('[data-page="'+this.currentPage+'"]')[0]).addClass("active")},renderEllipsis:function(){this.$prevEllipsis.isHidden&&this.currentPage>=this.config.firstPage+this.maxVisiblePages?this.$prevEllipsis.show():!this.$prevEllipsis.isHidden&&this.currentPage<=this.config.firstPage+this.maxVisiblePages-1&&this.$prevEllipsis.hide();this.$nextEllipsis.isHidden&&this.currentPage<=this.config.lastPage-this.maxVisiblePages?this.$nextEllipsis.show():
!this.$nextEllipsis.isHidden&&this.currentPage>=this.config.lastPage-this.maxVisiblePages+1&&this.$nextEllipsis.hide()},bindClickEvent:function(){var a=this;this.$container.on("click","li",function(){var b=a.sanitizePageRequest(c(this).data("page"));a.requestPage(b)})},insertPrevPaginationComponent:function(a){return a>this.config.firstPage&&a<this.config.lastPage?this.util.createPage(a).insertAfter(this.$prevEllipsis.$elem):c("")},insertNextPaginationComponent:function(a){return a>this.config.firstPage&&
a<this.config.lastPage?this.util.createPage(a).insertBefore(this.$nextEllipsis.$elem):c("")},sanitizePageRequest:function(a){var b=this.config.firstPage;"prev"===a?b=this.currentPage===this.config.firstPage?this.currentPage:this.currentPage-1:"next"===a?b=this.currentPage===this.config.lastPage?this.currentPage:this.currentPage+1:!isNaN(a)&&a>=this.config.firstPage&&a<=this.config.lastPage&&(b=parseInt(a));return b},purgeVisiblePages:function(){for(var a=this.visiblePages.length,b=0;b<a;b+=1)this.visiblePages.pop().remove()},
parseUrl:function(){var a=this.getUrlParamByName(this.config.urlParameter)||this.config.firstPage;return this.sanitizePageRequest(a)},getUrlParamByName:function(a){a=a.replace(/[\[\]]/g,"\\$&");return(a=(new RegExp("[?&]"+a+"(=([^&#]*)|&|#|$)")).exec(f.location.href))?a[2]?decodeURIComponent(a[2].replace(/\+/g," ")):"":null},updateUrlParam:function(a,b){[location.protocol,"//",location.host,location.pathname].join("");var c=g.location.search,e=a+"="+b,d="?"+e;c&&(keyRegex=new RegExp("([?&])"+a+"[^&]*"),
d=null!==c.match(keyRegex)?c.replace(keyRegex,"$1"+e):c+"&"+e);f.history.pushState("","",d)},util:{createPage:function(a){return c("<li>").text(a).addClass("waves-effect").attr("data-page",a)},createChevron:function(a){var b="next"===a?"right":"left",b=c("<i>").addClass("waves-effect").addClass("material-icons").text("chevron_"+b);return this.createPage(a).text("").attr("data-page",a).append(b)},Ellipsis:function(){var a=c("<li>");a.text("...");a.addClass("hide disabled");return{$elem:a,isHidden:!0,
show:function(){this.isHidden=!1;this.$elem.removeClass("hide")},hide:function(){this.isHidden=!0;this.$elem.addClass("hide")}}}}};d.defaults=d.prototype.defaults;c.fn.materializePagination=function(a){return this.each(function(){(new d(this,a)).init()})}})(jQuery,window,document);