seisobs-webapp/www/jquery.tablesorter.pager.min.js

3 lines
14 KiB
JavaScript

/* tablesorter pager plugin updated 4/23/2014 (v2.16.0) */
;(function(h){var k=h.tablesorter;h.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,customAjaxUrl:function(c,a){return a},ajaxObject:{dataType:"json"},processAjaxOnInit:!0,ajaxProcessing:function(c){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,pageReset:0,size:10,savePages:!0,storageKey:"tablesorter-pager",fixedHeight:!1,countChildRows:!1,removeRows:!1,cssFirst:".first",cssPrev:".prev",cssNext:".next",cssLast:".last", cssGoto:".gotoPage",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssErrorRow:"tablesorter-errorRow",cssDisabled:"disabled",totalRows:0,totalPages:0,filteredRows:0,filteredPages:0,ajaxCounter:0,currentFilters:[],startRow:0,endRow:0,$size:null,last:{}};var w=this,p=function(c,a){var b=c.cssDisabled,d=!!a,f=d||0===c.page,g=Math.min(c.totalPages,c.filteredPages),d=d||c.page===g-1||0===c.totalPages;c.updateArrows&&(c.$container.find(c.cssFirst+","+c.cssPrev)[f?"addClass":"removeClass"](b).attr("aria-disabled", f),c.$container.find(c.cssNext+","+c.cssLast)[d?"addClass":"removeClass"](b).attr("aria-disabled",d))},t=function(c,a,b){var d,f,g,l=c.config;d=l.$table.hasClass("hasFilters")&&!a.ajaxUrl;g=[];f=a.size||10;g=[l.widgetOptions&&l.widgetOptions.filter_filteredRow||"filtered",l.selectorRemove];a.countChildRows&&g.push(l.cssChildRow);g.join("|");a.totalPages=Math.ceil(a.totalRows/f);a.filteredRows=d?0:a.totalRows;a.filteredPages=a.totalPages;d&&(h.each(l.cache[0].normalized,function(e,c){a.filteredRows+= a.regexRows.test(c[l.columns].$row[0].className)?0:1}),a.filteredPages=Math.ceil(a.filteredRows/f)||0);if(0<=Math.min(a.totalPages,a.filteredPages)&&(g=a.size*a.page>a.filteredRows,a.startRow=g?1:0===a.filteredRows?0:a.size*a.page+1,a.page=g?0:a.page,a.endRow=Math.min(a.filteredRows,a.totalRows,a.size*(a.page+1)),d=a.$container.find(a.cssPageDisplay),g=(a.ajaxData&&a.ajaxData.output?a.ajaxData.output||a.output:a.output).replace(/\{page([\-+]\d+)?\}/gi,function(c,b){return a.totalPages?a.page+(b?parseInt(b, 10):1):0}).replace(/\{\w+(\s*:\s*\w+)?\}/gi,function(c){c=c.replace(/[{}\s]/g,"");var b=c.split(":"),d=a.ajaxData,f=/(rows?|pages?)$/i.test(c)?0:"";return 1<b.length&&d&&d[b[0]]?d[b[0]][b[1]]:a[c]||(d?d[c]:f)||f}),d.length&&(d["INPUT"===d[0].tagName?"val":"html"](g),a.$goto.length))){g="";f=Math.min(a.totalPages,a.filteredPages);for(d=1;d<=f;d++)g+="<option>"+d+"</option>";a.$goto.html(g).val(a.page+1)}p(a);a.initialized&&!1!==b&&(l.$table.trigger("pagerComplete",a),a.savePages&&k.storage&&k.storage(c, a.storageKey,{page:a.page,size:a.size}))},u=function(c,a){var b,d=c.config,f=d.$tbodies.eq(0);a.fixedHeight&&(f.find("tr.pagerSavedHeightSpacer").remove(),b=h.data(c,"pagerSavedHeight"))&&(b-=f.height(),5<b&&h.data(c,"pagerLastSize")===a.size&&f.children("tr:visible").length<a.size&&f.append('<tr class="pagerSavedHeightSpacer '+d.selectorRemove.replace(/(tr)?\./g,"")+'" style="height:'+b+'px;"></tr>'))},z=function(c,a){var b=c.config.$tbodies.eq(0);b.find("tr.pagerSavedHeightSpacer").remove();h.data(c, "pagerSavedHeight",b.height());u(c,a);h.data(c,"pagerLastSize",a.size)},v=function(c,a){if(!a.ajaxUrl){var b,d=0,f=c.config,g=f.$tbodies.eq(0).children(),h=g.length,e=a.page*a.size,m=e+a.size,n=f.widgetOptions&&f.widgetOptions.filter_filteredRow||"filtered",r=0;for(b=0;b<h;b++)g[b].className.match(n)||(r===e&&g[b].className.match(f.cssChildRow)?g[b].style.display="none":(g[b].style.display=r>=e&&r<m?"":"none",r+=g[b].className.match(f.cssChildRow+"|"+f.selectorRemove.slice(1))&&!a.countChildRows? 0:1,r===m&&"none"!==g[b].style.display&&g[b].className.match(k.css.cssHasChild)&&(d=b)));if(0<d&&g[d].className.match(k.css.cssHasChild))for(;++d<h&&g[d].className.match(f.cssChildRow);)g[d].style.display=""}},A=function(c,a){a.size=parseInt(a.$size.val(),10)||a.size;h.data(c,"pagerLastSize",a.size);p(a);a.removeRows||(v(c,a),h(c).bind("sortEnd.pager filterEnd.pager",function(){v(c,a)}))},B=function(c,a,b,d,f){if("function"===typeof b.ajaxProcessing){var g,l,e,m,n,r,s=a.config,q=s.$table,p="";g=b.ajaxProcessing(c, a)||[0,[]];c=q.find("thead th").length;k.showError(a);if(f)s.debug&&k.log("Ajax Error",d,f),k.showError(a,0===d.status?"Not connected, verify Network":404===d.status?"Requested page not found [404]":500===d.status?"Internal Server Error [500]":"parsererror"===f?"Requested JSON parse failed":"timeout"===f?"Time out error":"abort"===f?"Ajax Request aborted":"Uncaught error: "+d.statusText+" ["+d.status+"]"),s.$tbodies.eq(0).empty(),b.totalRows=0;else{h.isArray(g)?(d=isNaN(g[0])&&!isNaN(g[1]),f=g[d? 1:0],b.totalRows=isNaN(f)?b.totalRows||0:f,d=0===b.totalRows?[""]:g[d?0:1]||[],n=g[2]):(b.ajaxData=g,b.totalRows=g.total,n=g.headers,d=g.rows);r=d.length;if(d instanceof jQuery)b.processAjaxOnInit&&s.$tbodies.eq(0).empty().append(d);else if(r){for(g=0;g<r;g++){p+="<tr>";for(f=0;f<d[g].length;f++)p+=/^\s*<td/.test(d[g][f])?h.trim(d[g][f]):"<td>"+d[g][f]+"</td>";p+="</tr>"}b.processAjaxOnInit&&s.$tbodies.eq(0).html(p)}b.processAjaxOnInit=!0;n&&n.length===c&&(m=(l=q.hasClass("hasStickyHeaders"))?s.widgetOptions.$sticky.children("thead:first").children().children(): "",e=q.find("tfoot tr:first").children(),s.$headers.filter("th").each(function(a){var c=h(this),b;c.find("."+k.css.icon).length?(b=c.find("."+k.css.icon).clone(!0),c.find(".tablesorter-header-inner").html(n[a]).append(b),l&&m.length&&(b=m.eq(a).find("."+k.css.icon).clone(!0),m.eq(a).find(".tablesorter-header-inner").html(n[a]).append(b))):(c.find(".tablesorter-header-inner").html(n[a]),l&&m.length&&m.eq(a).find(".tablesorter-header-inner").html(n[a]));e.eq(a).html(n[a])}))}s.showProcessing&&k.isProcessing(a); b.totalPages=Math.ceil(b.totalRows/(b.size||10));b.last.totalRows=b.totalRows;b.last.currentFilters=b.currentFilters;b.last.sortList=(s.sortList||[]).join(",");t(a,b);u(a,b);q.trigger("updateCache",[function(){b.initialized&&q.trigger("applyWidgets").trigger("pagerChange",b)}])}b.initialized||(b.initialized=!0,h(a).trigger("applyWidgets").trigger("pagerInitialized",b))},G=function(c,a){var b=F(c,a),d=h(document),f,g=c.config;""!==b&&(g.showProcessing&&k.isProcessing(c,!0),d.bind("ajaxError.pager", function(b,e,f,g){B(null,c,a,e,g);d.unbind("ajaxError.pager")}),f=++a.ajaxCounter,a.ajaxObject.url=b,a.ajaxObject.success=function(b){f<a.ajaxCounter||(B(b,c,a),d.unbind("ajaxError.pager"),"function"===typeof a.oldAjaxSuccess&&a.oldAjaxSuccess(b))},g.debug&&k.log("ajax initialized",a.ajaxObject),h.ajax(a.ajaxObject))},F=function(c,a){var b=c.config,d=a.ajaxUrl?a.ajaxUrl.replace(/\{page([\-+]\d+)?\}/,function(c,b){return a.page+(b?parseInt(b,10):0)}).replace(/\{size\}/g,a.size):"",f=b.sortList,g=a.currentFilters|| h(c).data("lastSearch")||[],l=d.match(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/),e=d.match(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/),m=[];l&&(l=l[1],h.each(f,function(a,b){m.push(l+"["+b[0]+"]="+b[1])}),d=d.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g,m.length?m.join("&"):l),m=[]);e&&(e=e[1],h.each(g,function(a,b){b&&m.push(e+"["+a+"]="+encodeURIComponent(b))}),d=d.replace(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g,m.length?m.join("&"):e),a.currentFilters=g);"function"===typeof a.customAjaxUrl&&(d=a.customAjaxUrl(c, d));b.debug&&k.log("Pager ajax url: "+d);return d},x=function(c,a,b){var d,f,g,l,e=h(c);d=c.config;var m=d.$table.hasClass("hasFilters"),n=b.page*b.size,r=b.size;if(!(1>(a&&a.length||0))){b.page>=b.totalPages&&C(c,b);b.isDisabled=!1;b.initialized&&e.trigger("pagerChange",b);if(b.removeRows){k.clearTableBody(c);d=k.processTbody(c,d.$tbodies.eq(0),!0);f=m?0:n;g=m?0:n;for(l=0;l<r&&f<a.length;)m&&/filtered/.test(a[f][0].className)||(g++,g>n&&l<=r&&(l++,d.append(a[f]))),f++;k.processTbody(c,d,!1)}else v(c, b);t(c,b);b.isDisabled||u(c,b);e.trigger("applyWidgets");c.isUpdating&&e.trigger("updateComplete",c)}},D=function(c,a){a.ajax?p(a,!0):(a.isDisabled=!0,h.data(c,"pagerLastPage",a.page),h.data(c,"pagerLastSize",a.size),a.page=0,a.size=a.totalRows,a.totalPages=1,h(c).addClass("pagerDisabled").removeAttr("aria-describedby").find("tr.pagerSavedHeightSpacer").remove(),x(c,c.config.rowsCopy,a),c.config.debug&&k.log("pager disabled"));a.$size.add(a.$goto).each(function(){h(this).attr("aria-disabled","true").addClass(a.cssDisabled)[0].disabled= !0})},q=function(c,a,b){if(!a.isDisabled){var d=c.config,f=h(c),g=a.last,l=Math.min(a.totalPages,a.filteredPages);0>a.page&&(a.page=0);a.page>l-1&&0!==l&&(a.page=l-1);g.currentFilters=""===(g.currentFilters||[]).join("")?[]:g.currentFilters;a.currentFilters=""===(a.currentFilters||[]).join("")?[]:a.currentFilters;if(g.page!==a.page||g.size!==a.size||g.totalRows!==a.totalRows||(g.currentFilters||[]).join(",")!==(a.currentFilters||[]).join(",")||g.sortList!==(d.sortList||[]).join(","))d.debug&&k.log("Pager changing to page "+ a.page),a.last={page:a.page,size:a.size,sortList:(d.sortList||[]).join(","),totalRows:a.totalRows,currentFilters:a.currentFilters||[]},a.ajax?G(c,a):a.ajax||x(c,d.rowsCopy,a),h.data(c,"pagerLastPage",a.page),a.initialized&&!1!==b&&(f.trigger("pageMoved",a).trigger("applyWidgets"),c.isUpdating&&f.trigger("updateComplete"))}},y=function(c,a,b){b.size=a||b.size||10;b.$size.val(b.size);h.data(c,"pagerLastPage",b.page);h.data(c,"pagerLastSize",b.size);b.totalPages=Math.ceil(b.totalRows/b.size);b.filteredPages= Math.ceil(b.filteredRows/b.size);q(c,b)},H=function(c,a){a.page=0;q(c,a)},C=function(c,a){a.page=Math.min(a.totalPages,a.filteredPages)-1;q(c,a)},I=function(c,a){a.page++;a.page>=Math.min(a.totalPages,a.filteredPages)-1&&(a.page=Math.min(a.totalPages,a.filteredPages)-1);q(c,a)},J=function(c,a){a.page--;0>=a.page&&(a.page=0);q(c,a)},E=function(c,a,b){var d,f=c.config;a.$size.add(a.$goto).removeClass(a.cssDisabled).removeAttr("disabled").attr("aria-disabled","false");a.isDisabled=!1;a.page=h.data(c, "pagerLastPage")||a.page||0;a.size=h.data(c,"pagerLastSize")||parseInt(a.$size.find("option[selected]").val(),10)||a.size||10;a.$size.val(a.size);a.totalPages=Math.ceil(Math.min(a.totalRows,a.filteredRows)/a.size);c.id&&(d=c.id+"_pager_info",a.$container.find(a.cssPageDisplay).attr("id",d),f.$table.attr("aria-describedby",d));b&&(f.$table.trigger("updateRows"),y(c,a.size,a),A(c,a),u(c,a),f.debug&&k.log("pager enabled"))};w.appender=function(c,a){var b=c.config,d=b.pager;d.ajax||(b.rowsCopy=a,d.totalRows= d.countChildRows?b.$tbodies.eq(0).children().length:a.length,d.size=h.data(c,"pagerLastSize")||d.size||10,d.totalPages=Math.ceil(d.totalRows/d.size),x(c,a,d),t(c,d,!1))};w.construct=function(c){return this.each(function(){if(this.config&&this.hasInitialized){var a,b,d,f=this,g=f.config,l=g.widgetOptions,e=g.pager=h.extend(!0,{},h.tablesorterPager.defaults,c),m=g.$table,n=e.$container=h(e.container).addClass("tablesorter-pager").show();g.debug&&k.log("Pager initializing");e.oldAjaxSuccess=e.oldAjaxSuccess|| e.ajaxObject.success;g.appender=w.appender;k.filter&&0<=h.inArray("filter",g.widgets)&&(e.currentFilters=g.$table.data("lastSearch")||k.filter.setDefaults(f,g,g.widgetOptions)||[],k.setFilters(f,e.currentFilters,!1));e.savePages&&k.storage&&(a=k.storage(f,e.storageKey)||{},e.page=isNaN(a.page)?e.page:a.page,e.size=(isNaN(a.size)?e.size:a.size)||10,h.data(f,"pagerLastSize",e.size));e.regexRows=RegExp("("+(l.filter_filteredRow||"filtered")+"|"+g.selectorRemove.substring(1)+"|"+g.cssChildRow+")");m.unbind("filterStart filterEnd sortEnd disable enable destroy update updateRows updateAll addRows pageSize ".split(" ").join(".pager ")).bind("filterStart.pager", function(a,b){e.currentFilters=b;!1!==e.pageReset&&(g.lastCombinedFilter||"")!==(b||[]).join("")&&(e.page=e.pageReset)}).bind("filterEnd.pager sortEnd.pager",function(){e.initialized&&(t(f,e,!1),q(f,e,!1),u(f,e))}).bind("disable.pager",function(a){a.stopPropagation();D(f,e)}).bind("enable.pager",function(a){a.stopPropagation();E(f,e,!0)}).bind("destroy.pager",function(a){a.stopPropagation();D(f,e);e.$container.hide();f.config.appender=null;e.initialized=!1;delete f.config.rowsCopy;h(f).unbind("destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager"); k.storage&&k.storage(f,e.storageKey,"")}).bind("update.pager updateRows.pager updateAll.pager addRows.pager ",function(a){a.stopPropagation();v(f,e)}).bind("pageSize.pager",function(a,b){a.stopPropagation();y(f,parseInt(b,10)||10,e);v(f,e);t(f,e,!1);e.$size.length&&e.$size.val(e.size)}).bind("pageSet.pager",function(a,b){a.stopPropagation();e.page=(parseInt(b,10)||1)-1;e.$goto.length&&e.$goto.val(e.size);q(f,e);t(f,e,!1)});b=[e.cssFirst,e.cssPrev,e.cssNext,e.cssLast];d=[H,J,I,C];n.find(b.join(",")).attr("tabindex", 0).unbind("click.pager").bind("click.pager",function(a){a.stopPropagation();var c=h(this),g=b.length;if(!c.hasClass(e.cssDisabled))for(a=0;a<g;a++)if(c.is(b[a])){d[a](f,e);break}});e.$goto=n.find(e.cssGoto);e.$goto.length&&e.$goto.unbind("change").bind("change",function(){e.page=h(this).val()-1;q(f,e);t(f,e,!1)});e.$size=n.find(e.cssPageSize);e.$size.length&&e.$size.unbind("change.pager").bind("change.pager",function(){e.$size.val(h(this).val());h(this).hasClass(e.cssDisabled)||(y(f,parseInt(h(this).val(), 10),e),z(f,e));return!1});e.initialized=!1;m.trigger("pagerBeforeInitialized",e);E(f,e,!1);"string"===typeof e.ajaxUrl?(e.ajax=!0,g.widgetOptions.filter_serversideFiltering=!0,g.serverSideSorting=!0,q(f,e)):(e.ajax=!1,h(this).trigger("appendCache",!0),A(f,e));z(f,e);e.ajax||(e.initialized=!0,h(f).trigger("pagerInitialized",e))}})}}});k.showError=function(k,p){h(k).each(function(){var k=this.config,u=k.pager&&k.pager.cssErrorRow||k.widgetOptions.pager_css&&k.widgetOptions.pager_css.errorRow||"tablesorter-errorRow"; k&&("undefined"===typeof p?k.$table.find("thead").find(k.selectorRemove).remove():(/tr\>/.test(p)?h(p):h('<tr><td colspan="'+k.columns+'">'+p+"</td></tr>")).click(function(){h(this).remove()}).appendTo(k.$table.find("thead:first")).addClass(u+" "+k.selectorRemove.replace(/^[.#]/,"")).attr({role:"alert","aria-live":"assertive"}))})};h.fn.extend({tablesorterPager:h.tablesorterPager.construct})})(jQuery);