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

2 lines
7.6 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.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=a.widgetOptions,l=[],m=b.closest("tr"),n=k.math_dataAttrib,o=m.attr(n+"-filter")||k.math_rowFilter,p=k.filter_filteredRow||"filtered",q=parseInt(b.attr("data-column"),10),r=a.$table.children("tbody").children();if("above"===d)for(h=r.index(m),e=h;e>=0;)g=r.eq(e),o&&(g=g.filter(o)),f=g.children().filter("[data-column="+q+"]"),j=f.filter("["+n+"^=above]").length,((!g.hasClass(p)||o)&&g.not("["+n+"=ignore]").length&&e!==h||j&&e!==h)&&(j?e=0:f.length&&l.push(c.processText(a,f))),e--;else if("below"===d)for(h=r.length,e=r.index(m)+1;h>e&&(g=r.eq(e),o&&(g=g.filter(o)),f=g.children().filter("[data-column="+q+"]"),!f.filter("["+n+"^=below]").length);e++)(!g.hasClass(p)||o)&&g.not("["+n+"=ignore]").length&&f.length&&l.push(c.processText(a,f));else for(i=r.not("["+n+"=ignore]"),h=i.length,e=0;h>e;e++)g=i.eq(e),o&&(g=g.filter(o)),f=g.children().filter("[data-column="+q+"]"),g.hasClass(p)&&!o||!f.not("["+n+"^=above],["+n+"^=below],["+n+"^=col]").length||f.is(b)||l.push(c.processText(a,f));return l},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,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_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