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

2 lines
7.2 KiB
JavaScript
Raw Normal View History

2015-10-31 16:06:09 +00:00
/*! Widget: math - updated 10/31/2015 (v2.24.0) */
!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=b.widgetOptions,f=[],g=d.closest("tr"),h=g.children().not("["+e.math_dataAttrib+"=ignore]");return g.hasClass(e.filter_filteredRow||"filtered")||(e.math_ignore.length&&(h=h.not("[data-column="+e.math_ignore.join("],[data-column=")+"]")),f=h.not(d).map(function(){return c.processText(b,a(this))}).get()),f},getColumn:function(a,b,d){var e,f,g,h,i,j=[],k=a.widgetOptions,l=k.math_dataAttrib,m=k.filter_filteredRow||"filtered",n=parseInt(b.attr("data-column"),10),o=a.$table.children("tbody").children(),p=b.closest("tr");if("above"===d)for(g=o.index(p),e=g;e>=0;)f=o.eq(e).children().filter("[data-column="+n+"]"),i=f.filter("["+l+"^=above]").length,(!o.eq(e).hasClass(m)&&o.eq(e).not("["+l+"=ignore]").length&&e!==g||i&&e!==g)&&(i?e=0:f.length&&j.push(c.processText(a,f))),e--;else if("below"===d)for(g=o.length,e=o.index(p)+1;g>e&&(f=o.eq(e).children().filter("[data-column="+n+"]"),!f.filter("["+l+"^=below]").length);e++)!o.eq(e).hasClass(m)&&o.eq(e).not("["+l+"=ignore]").length&&f.length&&j.push(c.processText(a,f));else for(h=o.not("["+l+"=ignore]"),g=h.length,e=0;g>e;e++)f=h.eq(e).children().filter("[data-column="+n+"]"),h.eq(e).hasClass(m)||!f.not("["+l+"^=above],["+l+"^=below],["+l+"^=col]").length||f.is(b)||j.push(c.processText(a,f));return j},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=b.$table.children("tbody").children().not("["+n+"=ignore]");for(h=p.length,g=0;h>g;g++)if(f=p.eq(g),!f.hasClass(o))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.find("["+g+"]"),c.mathType(a,h,d.math_priority),h=a.$table.children("."+a.cssInfoBlock+", tfoot").find("["+g+"]"),c.mathType(a,h,d.math_priority),h=a.$table.find("["+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.debug&&console.groupEnd&&console.groupEnd()}},output:function(a,c,d,e){var f=a.attr("data-"+c.math_data+"-mask")||c.math_mask,g=b.formatMask(f,d,c.math_wrapPrefix,c.math_wrapSuffix);"function"==typeof c.math_complete&&(g=c.math_complete(a,c,g,d,e)),g!