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

2 lines
8.4 KiB
JavaScript
Raw Normal View History

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