Files
galaxy/static/scripts/ui/pagination.js
T

2 lines
2.8 KiB
JavaScript

!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function b(a,b){return this.numPages=null,this.currPage=0,this.init(a,b)}function c(b){return a(['<li><a href="javascript:void(0);">',b,"</a></li>"].join(""))}b.prototype.DATA_KEY="pagination",b.prototype.defaults={startingPage:0,perPage:20,totalDataSize:null,currDataSize:null},b.prototype.init=function(a,c){return c=c||{},this.$element=a,this.options=jQuery.extend(!0,{},this.defaults,c),this.currPage=this.options.startingPage,null!==this.options.totalDataSize&&(this.numPages=Math.ceil(this.options.totalDataSize/this.options.perPage),this.currPage>=this.numPages&&(this.currPage=this.numPages-1)),this.$element.data(b.prototype.DATA_KEY,this),this._render(),this},b.prototype._render=function(){return 0===this.options.totalDataSize?this:1===this.numPages?this:(this.numPages>0?(this._renderPages(),this._scrollToActivePage()):this._renderPrevNext(),this)},b.prototype._renderPrevNext=function(){var b=this,d=c("Prev"),e=c("Next"),f=a("<ul/>").addClass("pagination pagination-prev-next");return 0===this.currPage?d.addClass("disabled"):d.click(function(){b.prevPage()}),this.numPages&&this.currPage===this.numPages-1||this.options.currDataSize&&this.options.currDataSize<this.options.perPage?e.addClass("disabled"):e.click(function(){b.nextPage()}),this.$element.html(f.append([d,e])),this.$element},b.prototype._renderPages=function(){for(var b=this,d=a("<div>").addClass("pagination-scroll-container"),e=a("<ul/>").addClass("pagination pagination-page-list"),f=function(){b.goToPage(a(this).data("page"))},g=0;g<this.numPages;g+=1){var h=c(g+1).attr("data-page",g).click(f);g===this.currPage&&h.addClass("active"),e.append(h)}return this.$element.html(d.html(e))},b.prototype._scrollToActivePage=function(){var a=this.$element.find(".pagination-scroll-container");if(!a.size())return this;var b=this.$element.find("li.active"),c=a.width()/2;return a.scrollLeft(a.scrollLeft()+b.position().left-c),this},b.prototype.goToPage=function(a){return 0>=a&&(a=0),this.numPages&&a>=this.numPages&&(a=this.numPages-1),a===this.currPage?this:(this.currPage=a,this.$element.trigger("pagination.page-change",this.currPage),this._render(),this)},b.prototype.prevPage=function(){return this.goToPage(this.currPage-1)},b.prototype.nextPage=function(){return this.goToPage(this.currPage+1)},b.prototype.page=function(){return this.currPage},b.create=function(a,c){return new b(a,c)},jQuery.fn.extend({pagination:function(c){var d=jQuery.makeArray(arguments).slice(1);if("object"===jQuery.type(c))return this.map(function(){return b.create(a(this),c),this});var e=a(this[0]),f=e.data(b.prototype.DATA_KEY);if(f){if("string"!==jQuery.type(c))return f;var g=f[c];if("function"===jQuery.type(g))return g.apply(f,d)}return void 0}})});
//# sourceMappingURL=../../maps/ui/pagination.js.map