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

5 lines
9.1 KiB
JavaScript
Raw Normal View History

2018-08-27 16:00:49 +00:00
(function(factory){if (typeof define === 'function' && define.amd){define(['jquery'], factory);} else if (typeof module === 'object' && typeof module.exports === 'object'){module.exports = factory(require('jquery'));} else {factory(jQuery);}}(function(jQuery){
2018-11-20 21:54:28 +00:00
/*! Widget: math - updated 11/20/2018 (v2.31.1) */
!function(v){"use strict";var _=v.tablesorter,x={error:{0:"Infinity result: Divide by zero",1:"Need more than one element to make this calculation",undef:"No elements found"},invalid:function(t,e,n){return console.warn(e,x.error[n]),t&&t.widgetOptions.math_none||""},events:"tablesorter-initialized update updateAll updateRows addRows updateCell filterReset ".split(" ").join(".tsmath "),processText:function(t,e){var n,a=t.widgetOptions,r=_.getElementText(t,e,x.getCellIndex(e)),i=t.widgetOptions.math_prefix;return a.math_textAttr&&(r=e.attr(a.math_textAttr)||r),/</.test(i)&&(n=v("<div>"+i+"</div>").text().replace(/\{content\}/g,"").trim(),r=r.replace(n,"")),r=_.formatFloat(r.replace(/[^\w,. \-()]/g,""),t.table)||0,isNaN(r)?0:r},getRow:function(t,e,n){var a,r=t.widgetOptions,i=[],l=e.closest("tr"),o=l.hasClass(r.filter_filteredRow||"filtered");return n&&(l=l.filter(n)),!n&&o||(a=l.children().not("["+r.math_dataAttrib+"=ignore]"),r.math_ignore.length&&(a=a.filter(function(){return-1===v.inArray(x.getCellIndex(v(this)),r.math_ignore)})),i=a.not(e).map(function(){return x.processText(t,v(this))}).get()),i},getColumn:function(t,e,n,a){var r,i,l,o,h,s,d=t.widgetOptions,u=[],c=e.closest("tr"),g=d.math_dataAttrib,f="["+g+"=ignore]",m=d.filter_filteredRow||"filtered",p=x.getCellIndex(e),_=t.$table.children("tbody").children(),b=["["+g+"^=above]","["+g+"^=below]","["+g+"^=col]","["+g+"^=all]"];if("above"===n)for(r=o=_.index(c);0<=r;)s=(l=_.eq(r)).children().filter(b[0]).length,a&&(l=l.filter(a)),i=l.children().filter(function(){return x.getCellIndex(v(this))===p}),((a||!l.hasClass(m))&&l.not(f).length&&r!==o||s&&r!==o)&&(s?r=0:i.length&&(u[u.length]=x.processText(t,i))),r--;else if("below"===n)for(o=_.length,r=_.index(c)+1;r<o&&!(l=_.eq(r)).children().filter(b[1]).length;r++)a&&(l=l.filter(a)),i=l.children().filter(function(){return x.getCellIndex(v(this))===p}),(a||!l.hasClass(m))&&l.not(f).length&&i.length&&(u[u.length]=x.processText(t,i));else for(o=(h=_.not(f)).length,r=0;r<o;r++)l=h.eq(r),a&&(l=l.filter(a)),i=l.children().filter(function(){return x.getCellIndex(v(this))===p}),!a&&l.hasClass(m)||!i.not(b.join(",")).length||i.is(e)||(u[u.length]=x.processText(t,i));return u},getAll:function(t,e){var n,a,r,i,l,o,h,s,d=[],u=t.widgetOptions,c=u.math_dataAttrib,g="["+c+"=ignore]",f=u.filter_filteredRow||"filtered",m=t.$table.children("tbody").children().not(g);for(l=m.length,i=0;i<l;i++)if(r=m.eq(i),e&&(r=r.filter(e)),e||!r.hasClass(f))for(s=(o=r.children().not(g)).length,h=0;h<s;h++)n=o.eq(h),a=x.getCellIndex(n),!n.filter("["+c+"]").length&&v.inArray(a,u.math_ignore)<0&&(d[d.length]=x.processText(t,n));return d},setColumnIndexes:function(t){var e=t.$table,r=1,n=e.children("tbody").children().filter(function(){var t,e,n=v(this),a=0<n.children("[colspan]").length;if(1<r?(r--,a=!0):r<1&&(r=1),0<n.children("[rowspan]").length)for(t=this.cells,e=0;e<t.length;e++)r=Math.max(t[e].rowSpan,r);return a});_.computeColumnIndex(n,t)},getCellIndex:function(t){var e=t.attr("data-column");return void 0===e?t[0].cellIndex:parseInt(e,10)},recalculate:function(n,t,e){if(n&&(!t.math_isUpdating||e)){var a,r,i,l,o,h=!1,s={};for((n.debug||t.math_debug)&&(a=new Date),e&&x.setColumnIndexes(n),t.math_dataAttrib="data-"+(t.math_data||"math"),r=t.math_dataAttrib,i=n.$tbodies.children("tr").children("["+r+"]"),h=x.mathType(n,i,t.math_priority)||h,i=n.$table.children("."+n.cssInfoBlock+", tfoot").children("tr").children("["+r+"]"),x.mathType(n,i,t.math_priority),o=(i=n.$table.children().children("tr").children("["+r+"^=all]")).length,l=0;l<o;l++){var d=i.eq(l),u=d.attr(r+"-filter")||t.math_rowFilter;s[u]=s[u]?s[u].add(d):d}v.each(s,function(t,e){h=x.mathType(n,e,["all"],t)||h}),h?(t.math_isUpdating=!0,(n.debug||t.math_debug)&&console[console.group?"group":"log"]("Math widget updating the cache after recalculation"),_.updateCache(n,function(){x.updateComplete(n),e||"function"!=typeof t.math_completed||t.math_completed(n),(n.debug||t.math_debug)&&console.log("Math widget update completed"+_.benchmark(a))})):(e||"function"!=typeof t.math_completed||t.math_completed