tablesorter/dist/js/widgets/widget-grouping.min.js

2 lines
7.2 KiB
JavaScript
Raw Normal View History

2017-09-28 02:07:28 +00:00
/*! Widget: grouping - updated 9/27/2017 (v2.29.0) */
!function(r){"use strict";var o=r.tablesorter,e=o.grouping={types:{number:function(r,e,u,p){var t,a=e.hasClass(o.css.sortAsc);return p>1&&""!==u?(t=a?Math.floor(parseFloat(u)/p)*p:Math.ceil(parseFloat(u)/p)*p,t+=" - "+(t+(p-1)*(a?1:-1))):t=parseFloat(u)||u,t},separator:function(o,e,u,p){var t=(u+"").split(o.widgetOptions.group_separator);return r.trim(t[p-1]||"")},text:function(r,o,e){return e},word:function(r,o,e,u){return((e+" ").match(/\w+/g)||[])[u-1]||""},letter:function(r,o,e,u){return e?(e+" ").substring(0,u):""},date:function(r,o,u,p,t){var a,n,s=r.widgetOptions,l=new Date(u||"");return l instanceof Date&&isFinite(l)?(a=l.getFullYear(),n=e.findMonth(s,l.getMonth()),"year"===p?a:"month"===p?n:"monthyear"===p?n+" "+a:"day"===p?n+" "+l.getDate():"week"===p?e.findWeek(s,l.getDay()):"time"===p?e.findTime(s,l):"hour"===p?e.findTime(s,l,"hour"):s.group_dateString(l,r,o)):s.group_dateInvalid}},findMonth:function(r,o){return r.group_months[o+(""===(r.group_months[0]||"")?1:0)]},findWeek:function(o,e){if(r.isArray(o.group_week))return o.group_week[e];if(!r.isEmptyObject(o.group_week)){var u=["sun","mon","tue","wed","thu","fri","sat"];return o.group_week[u[e]]}},findTime:function(r,o,e){var u,p=r.group_time.am&&r.group_time.pm,t=o.getHours(),a=t>=12?1:0,n=("00"+(r.group_time24Hour&&t>12?t-12:r.group_time24Hour&&0===t?t+12:t)).slice(-2),s=("00"+o.getMinutes()).slice(-2);return u=r.group_time[p?["am","pm"][a]:a],"hour"===e?n:n+":"+s+(r.group_time24Hour?"":" "+(u||""))},update:function(o){if(!r.isEmptyObject(o.config.cache)){var u=o.config,p=u.widgetOptions,t=void 0!==u.sortList[0],a={},n=r.isArray(p.group_forceColumn)&&void 0!==p.group_forceColumn[0]?p.group_enforceSort&&!t?-1:p.group_forceColumn[0]:t?u.sortList[0][0]:-1;u.$table.find("tr.group-hidden").removeClass("group-hidden").end().find("tr.group-header").remove(),p.group_collapsible&&u.$table.data("pagerSavedHeight",0),n>=0&&n<u.columns&&!u.$headerIndexed[n].hasClass("group-false")&&(p.group_collapsedGroup="",p.group_collapsedGroups={},a.column=n,a.groupClass=(u.$headerIndexed[n].attr("class")||"").match(/(group-\w+(-\w+)?)/g),a.grouping=a.groupClass?a.groupClass[0].split("-"):["group","letter",1],a.savedGroup=e.saveCurrentGrouping(u,p,a),e.findColumnGroups(u,p,a),e.processHeaders(u,p,a),u.$table.triggerHandler(p.group_complete))}},processHeaders:function(o,e,u){var p,t,a,n,s,l,g=o.$table.find("tr.group-header"),i=g.length;for(g.bind("selectstart",!1),p=0;p<i;p++)s=(l=g.eq(p)).nextUntil("tr.group-header").filter(":visible"),(e.group_count||r.isFunction(e.group_callback))&&(a=l.find(".group-count")).length&&(e.group_count&&a.html(e.group_count.toString().replace(/\{num\}/g,s.length)),r.isFunction(e.group_callback)&&e.group_callback(l.find("td"),s,u.column,o.table)),e.group_saveGroups&&!r.isEmptyObject(e.group_collapsedGroups)&&e.group_collapsedGroups[e.group_collapsedGroup].length?(n=l.find(".group-name").text().toLowerCase()+l.attr("data-group-index"),t=r.inArray(n,e.group_collapsedGroups[e.group_collapsedGroup])>-1,l.toggleClass("collapsed",t),s.toggleClass("group-hidden",t)):e.group_collapsed&&e.group_collapsible&&(l.addClass("collapsed"),s.addClass("group-hidden"))},groupHeaderHTML:function(r,o,e){var u=(e.currentGroup||"").toString().replace(/</g,"&lt;").replace(/>/g,"&gt;");return'<tr class="group-header '+r.selectorRemove.slice(1)+" "+(o.columnSelector_classHasSpan||"hasSpan")+'" unselectable="on" '+(r.tabIndex?'tabindex="0" ':"")+'data-group-index="'+e.groupIndex+'"><td colspan="'+r.columns+'">'+(o.group_collapsible?"<i/>":"")+'<span class="group-name">'+u+'</span><span class="group-count"></span></td></tr>'},saveCurrentGrouping:function(r,e,u){var p,t,a=!1;return e.group_collapsible&&e.group_saveGroups&&(e.group_collapsedGroups=o.storage&&o.storage(r.table,"tablesorter-groups")||{},t="dir"+r.sortList[0][1],p=e.group_collapsedGroup=""+r.sortList[0][0]+t+u.grouping.join(""),e.group_collapsedGroups[p]?a=!0:e.group_collapsedGroups[p]=[]),a},findColumnGroups:function(r,u,p){var t,a,n,s,l=o.hasWidget(r.table,"pager"),g=r.pager||{};for(p.groupIndex=0,t=0;t<r.$tbodies.