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

2 lines
8.0 KiB
JavaScript
Raw Normal View History

2015-11-23 04:05:06 +00:00
/*! Widget: math - updated 11/22/2015 (v2.24.6) */
!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.log(b,c.error[d]),a&&a.widgetOptions.math_none||"none"},events:"tablesorter-initialized update updateAll updateRows addRows updateCell filterReset filterEnd ".split(" ").join(".tsmath "),processText:function(a,c){var d=c.attr(a.textAttribute);return"undefined"==typeof d&&(d=c[0].textContent||c.text()),d=b.formatFloat(d.replace(/[^\w,. \-()]/g,""),a.table)||0,isNaN(d)?0:d},getRow:function(b,d){var e,f=b.widgetOptions,g=[],h=d.closest("tr"),i=h.hasClass(f.filter_filteredRow||"filtered"),j=h.attr(f.math_dataAttrib+"-filter")||f.math_rowFilter;return j&&(h=h.filter(j)),(!i||j)&&(e=h.children().not("["+f.math_dataAttrib+"=ignore]"),f.math_ignore.length&&(e=e.filter(function(b){return-1===a.inArray(c.getCellIndex(a(this)),f.math_ignore)})),g=e.not(d).map(function(){return c.processText(b,a(this))}).get()),g},getColumn:function(b,d,e){var f,g,h,i,j,k,l=b.widgetOptions,m=[],n=d.closest("tr"),o=l.math_dataAttrib,p=n.attr(o+"-filter")||l.math_rowFilter,q=l.filter_filteredRow||"filtered",r=c.getCellIndex(d),s=b.$table.children("tbody").children();if("above"===e)for(i=s.index(n),f=i;f>=0;)h=s.eq(f),p&&(h=h.filter(p)),g=h.children().filter(function(b){return c.getCellIndex(a(this))===r}),k=g.filter("["+o+"^=above]").length,((!h.hasClass(q)||p)&&h.not("["+o+"=ignore]").length&&f!==i||k&&f!==i)&&(k?f=0:g.length&&m.push(c.processText(b,g))),f--;else if("below"===e)for(i=s.length,f=s.index(n)+1;i>f&&(h=s.eq(f),p&&(h=h.filter(p)),g=h.children().filter(function(b){return c.getCellIndex(a(this))===r}),!g.filter("["+o+"^=below]").length);f++)(!h.hasClass(q)||p)&&h.not("["+o+"=ignore]").length&&g.length&&m.push(c.processText(b,g));else for(j=s.not("["+o+"=ignore]"),i=j.length,f=0;i>f;f++)h=j.eq(f),p&&(h=h.filter(p)),g=h.children().filter(function(b){return c.getCellIndex(a(this))===r}),h.hasClass(q)&&!p||!g.not("["+o+"^=above],["+o+"^=below],["+o+"^=col]").length||g.is(d)||m.push(c.processText(b,g));return m},getAll:function(b){var d,e,f,g,h,i,j,k,l=[],m=b.widgetOptions,n=m.math_dataAttrib,o=m.filter_filteredRow||"filtered",p=m.filter_rowFilter,q=b.$table.children("tbody").children().not("["+n+"=ignore]");for(h=q.length,g=0;h>g;g++)if(f=q.eq(g),p&&(f=f.filter(p)),!f.hasClass(o)||p)for(i=f.children().not("["+n+"=ignore]"),k=i.length,j=0;k>j;j++)d=i.eq(j),e=c.getCellIndex(d),!d.filter("["+n+"]").length&&a.inArray(e,m.math_ignore)<0&&l.push(c.processText(b,d));return l},setColumnIndexes:function(c){c.$table.after('<div id="_tablesorter_table_placeholder"></div>');var d=c.$table.detach(),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),a("#_tablesorter_table_placeholder").after(d).remove()},getCellIndex:function(a){var b=a.attr("data-column");return"undefined"==typeof b?a[0].cellIndex:parseInt(b,10)},recalculate:function(a,d,e){if(a&&(!d.math_isUpdating||e)){var f,g,h,i;a.debug&&(g=new Date),e&&c.setColumnIndexes(a),d.math_dataAttrib="data-"+(d.math_data||"math"),h=d.math_dataAttrib,i=a.$tbodies.children("tr").children("["+h+"]"),c.mathType(a,i,d.math_priority),i=a.$table.children("."+a.cssInfoBlock+", tfoot").children("tr").children("["+h+"]"),c.mathType(a,i,d.math_priority),i=a.$table.children().children("tr").children("["+h+"^=all]"),c.mathType(a,i,["all"]),d.math_isUpdating=!0,a.debug&&console[console.group?"group":"log"]("Math widget triggering an update after recalculation"),b.update(a,f,function(){c.updateComplete(a)}),a.debug&&console.log("Math widget update completed"+b.benchmark(g))}},updateComplete:function(a){var b=a.widgetOptions;b.math_isUpdating&&a.debug&&console.groupEnd&&console.groupEnd(),b.math_isUpdating=!1},mathType:function(d,e,f){if(e.length){var g,h,i,j,k,l,m,n,o=d.widgetOptions,p=o.math_dataAtt