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

2 lines
7.4 KiB
JavaScript
Raw Normal View History

2015-11-10 21:27:30 +00:00
/*! Widget: math - updated 11/10/2015 (v2.24.4) */
!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=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.not("[data-column="+f.math_ignore.join("],[data-column=")+"]")),g=e.not(d).map(function(){return c.processText(b,a(this))}).get()),g},getColumn:function(a,b,d){var e,f,g,h,i,j,k=[],l=a.widgetOptions,m=l.math_rowFilter,n=l.math_dataAttrib,o=l.filter_filteredRow||"filtered",p=parseInt(b.attr("data-column"),10),q=a.$table.children("tbody").children(),r=b.closest("tr");if("above"===d)for(h=q.index(r),e=h;e>=0;)g=q.eq(e),m&&(g=g.filter(l.math_rowFilter)),f=g.children().filter("[data-column="+p+"]"),j=f.filter("["+n+"^=above]").length,((!g.hasClass(o)||m)&&g.not("["+n+"=ignore]").length&&e!==h||j&&e!==h)&&(j?e=0:f.length&&k.push(c.processText(a,f))),e--;else if("below"===d)for(h=q.length,e=q.index(r)+1;h>e&&(g=q.eq(e),m&&(g=g.filter(m)),f=g.children().filter("[data-column="+p+"]"),!f.filter("["+n+"^=below]").length);e++)(!g.hasClass(o)||m)&&g.not("["+n+"=ignore]").length&&f.length&&k.push(c.processText(a,f));else for(i=q.not("["+n+"=ignore]"),h=i.length,e=0;h>e;e++)g=i.eq(e),m&&(g=g.filter(m)),f=g.children().filter("[data-column="+p+"]"),g.hasClass(o)&&!m||!f.not("["+n+"^=above],["+n+"^=below],["+n+"^=col]").length||f.is(b)||k.push(c.processText(a,f));return k},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=parseInt(d.attr("data-column"),10),!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();b.computeColumnIndex(d.children("tbody").children()),a("#_tablesorter_table_placeholder").after(d).remove()},recalculate:function(a,d,e){if(a&&(!d.math_isUpdating||e)){var f,g,h;a.debug&&(f=new Date),e&&c.setColumnIndexes(a),d.math_dataAttrib="data-"+(d.math_data||"math"),g=d.math_dataAttrib,h=a.$tbodies.children("tr").children("["+g+"]"),c.mathType(a,h,d.math_priority),h=a.$table.children("."+a.cssInfoBlock+", tfoot").children("tr").children("["+g+"]"),c.mathType(a,h,d.math_priority),h=a.$table.children().children("tr").children("["+g+"^=all]"),c.mathType(a,h,["all"]),d.math_isUpdating=!0,a.debug&&console[console.group?"group":"log"]("Math widget triggering an update after recalculation"),b.update(a),a.debug&&console.log("Math widget update completed"+b.benchmark(f))}},mathType:function(d,e,f){if(e.length){var g,h,i,j,k,l,m,n,o=d.widgetOptions,p=o.math_dataAttrib,q=b.equations;"all"===f[0]&&(k=c.getAll(d)),d.debug&&console[console.group?"group":"log"]("Tablesorter Math widget recalculation"),a.each(f,function(a,b){if(l=e.filter("["+p+"^="+b+"]"),n=l.length){for(d.debug&&console[console.group?"group":"log"](b),m=0;n>m;m++)i=l.eq(m),i.parent().hasClass(o.filter_filteredRow||"filtered")||(g=(i.attr(p)||"").replace(b+"-",""),j="row"===b?c.getRow(d,i):"all"===b?k:c.getColumn(d,i,b),q[g]&&(j.length?(h=q[g](j,d),d.debug&&console.log(i.attr(p),j,"=",h)):h=c.invalid(d,g,"mean"===g?0:"undef"),c.output(i,o,h,j)));d.debug&&console.groupEnd&&console.groupEnd()}}),d.d