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

2 lines
8.7 KiB
JavaScript
Raw Normal View History

2017-05-03 22:22:27 +00:00
/*! Widget: math - updated 5/3/2017 (v2.28.9) */
2018-03-18 13:49:07 +00:00
!function(t){"use strict";var e=t.tablesorter,n={error:{0:"Infinity result: Divide by zero",1:"Need more than one element to make this calculation",undef:"No elements found"},invalid:function(t,e,a){return console.warn(e,n.error[a]),t&&t.widgetOptions.math_none||""},events:"tablesorter-initialized update updateAll updateRows addRows updateCell filterReset ".split(" ").join(".tsmath "),processText:function(a,r){var i,l=e.getElementText(a,r,n.getCellIndex(r)),o=a.widgetOptions.math_prefix;return/</.test(o)&&(i=t("<div>"+o+"</div>").text().replace(/\{content\}/g,"").trim(),l=l.replace(i,"")),l=e.formatFloat(l.replace(/[^\w,. \-()]/g,""),a.table)||0,isNaN(l)?0:l},getRow:function(e,a,r){var i,l=e.widgetOptions,o=[],h=a.closest("tr"),s=h.hasClass(l.filter_filteredRow||"filtered");return r&&(h=h.filter(r)),!r&&s||(i=h.children().not("["+l.math_dataAttrib+"=ignore]"),l.math_ignore.length&&(i=i.filter(function(){return-1===t.inArray(n.getCellIndex(t(this)),l.math_ignore)})),o=i.not(a).map(function(){return n.processText(e,t(this))}).get()),o},getColumn:function(e,a,r,i){var l,o,h,s,d,u,c=e.widgetOptions,g=[],f=a.closest("tr"),m=c.math_dataAttrib,p="["+m+"=ignore]",_=c.filter_filteredRow||"filtered",b=n.getCellIndex(a),v=e.$table.children("tbody").children(),x=["["+m+"^=above]","["+m+"^=below]","["+m+"^=col]","["+m+"^=all]"];if("above"===r)for(l=s=v.index(f);l>=0;)u=(h=v.eq(l)).children().filter(x[0]).length,i&&(h=h.filter(i)),o=h.children().filter(function(){return n.getCellIndex(t(this))===b}),((i||!h.hasClass(_))&&h.not(p).length&&l!==s||u&&l!==s)&&(u?l=0:o.length&&(g[g.length]=n.processText(e,o))),l--;else if("below"===r)for(s=v.length,l=v.index(f)+1;l<s&&!(h=v.eq(l)).children().filter(x[1]).length;l++)i&&(h=h.filter(i)),o=h.children().filter(function(){return n.getCellIndex(t(this))===b}),(i||!h.hasClass(_))&&h.not(p).length&&o.length&&(g[g.length]=n.processText(e,o));else for(s=(d=v.not(p)).length,l=0;l<s;l++)h=d.eq(l),i&&(h=h.filter(i)),o=h.children().filter(function(){return n.getCellIndex(t(this))===b}),!i&&h.hasClass(_)||!o.not(x.join(",")).length||o.is(a)||(g[g.length]=n.processText(e,o));return g},getAll:function(e,a){var r,i,l,o,h,s,d,u,c=[],g=e.widgetOptions,f=g.math_dataAttrib,m="["+f+"=ignore]",p=g.filter_filteredRow||"filtered",_=e.$table.children("tbody").children().not(m);for(h=_.length,o=0;o<h;o++)if(l=_.eq(o),a&&(l=l.filter(a)),a||!l.hasClass(p))for(u=(s=l.children().not(m)).length,d=0;d<u;d++)r=s.eq(d),i=n.getCellIndex(r),!r.filter("["+f+"]").length&&t.inArray(i,g.math_ignore)<0&&(c[c.length]=n.processText(e,r));return c},setColumnIndexes:function(n){var a=1,r=n.$table.children("tbody").children().filter(function(){var e,n,r=t(this),i=r.children("[colspan]").length>0;if(a>1?(a--,i=!0):a<1&&(a=1),r.children("[rowspan]").length>0)for(e=this.cells,n=0;n<e.length;n++)a=Math.max(e[n].rowSpan,a);return i});e.computeColumnIndex(r,n)},getCellIndex:function(t){var e=t.attr("data-column");return void 0===e?t[0].cellIndex:parseInt(e,10)},recalculate:function(a,r,i){if(a&&(!r.math_isUpdating||i)){var l,o,h,s,d,u=!1,c={};for((a.debug||r.math_debug)&&(l=new Date),i&&n.setColumnIndexes(a),r.math_dataAttrib="data-"+(r.math_data||"math"),o=r.math_dataAttrib,h=a.$tbodies.children("tr").children("["+o+"]"),u=n.mathType(a,h,r.math_priority)||u,h=a.$table.children("."+a.cssInfoBlock+", tfoot").children("tr").children("["+o+"]"),n.mathType(a,h,r.math_priority),d=(h=a.$table.children().children("tr").children("["+o+"^=all]")).length,s=0;s<d;s++){var g=h.eq(s),f=g.attr(o+"-filter")||r.math_rowFilter;c[f]=c[f]?c[f].add(g):g}t.each(c,function(t,e){u=n.mathType(a,e,["all"],t)||u}),u?(r.math_isUpdating=!0,(a.debug||r.math_debug)&&console[console.group?"group":"log"]("Math widget updating the cache after recalculation"),e.updateCache(a,function(){n.updateComplete(a),i||"function"!=typeof r.math_completed||r.math_completed(a),(a.debug||r.math_debug)&&console.log("Math widget update completed"+e.benchmark(l))})):(i||"function"!=typeof r.math_completed||r.math_completed(a),(a.debug||r.math_debug)&&console.log("Math widget found no changes