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) */
!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(d,e){var f,g=b.getElementText(d,e,c.getCellIndex(e)),h=d.widgetOptions.math_prefix;return/</.test(h)&&(f=a("<div>"+h+"</div>").text().replace(/\{content\}/g,"").trim(),g=g.replace(f,"")),g=b.formatFloat(g.replace(/[^\w,. \-()]/g,""),d.table)||0,isNaN(g)?0:g},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;g<j&&(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;g<j;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;h<i;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;k<l;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):e<1&&(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 void 0===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=!1,m={};for((d.debug||e.math_debug)&&(g=new Date),f&&c.setColumnIndexes(d),e.math_dataAttrib="data-"+(e.math_data||"math"),h=e.math_dataAttrib,i=d.$tbodies.children("tr").children("["+h+"]"),l=c.mathType(d,i,e.math_priority)||l,i=d.$table.children("."+d.cssInfoBlock+", tfoot").children("tr").children("["+h+"]"),c.mathType(d,i,e.math_priority),i=d.$table.children().children("tr").children("["+h+"^=all]"),k=i.length,j=0;j<k;j++){var n=i.eq(j),o=n.attr(h+"-filter")||e.math_rowFilter;m[o]=m[o]?m[o].add(n):n}a.each(m,function(a,b){l=c.mathType(d,b,["all"],a)||l}),l?(e.math_isUpdating=!0,(d.debug||e.math_debug)&&console[console.group?"group":"log"]("Math widget updating the cache after recalculation"),b.updateCache(d,function(){c.updateComplete(d),f||"function"!=typeof e.math_completed||e.math_completed(d),(d.debug||e.math_debug)&&console.log("Math widget update completed"+b.benchmark(g))})):(f||"function"!=typeof e.math_completed||e.math_completed(d),(d.debug||e.math_debug)&&console.log("Math widget found no