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

2 lines
2.8 KiB
JavaScript
Raw Normal View History

/*! Widget: alignChar - updated 2/7/2015 (v2.19.0) */
2017-05-16 20:33:15 +00:00
!function(n){"use strict";var a=n.tablesorter;a.alignChar={init:function(i,t,r){t.$headers.filter("["+r.alignChar_charAttrib+"]").each(function(){var e=n(this),l={column:this.column,align:e.attr(r.alignChar_charAttrib),alignIndex:parseInt(e.attr(r.alignChar_indexAttrib)||0,10),adjust:parseFloat(e.attr(r.alignChar_adjustAttrib))||0};l.regex=new RegExp("\\"+l.align,"g"),void 0!==l.align&&(r.alignChar_savedVars[this.column]=l,a.alignChar.setup(i,t,r,l))})},setup:function(a,i,t,r){if(!n.isEmptyObject(i.cache)){var e,l,h,g,o,s,d,c,u,f,m,p,C,w,b=[],_=[];for(e=0;e<i.$tbodies.length;e++)for(f=(d=i.cache[e]).normalized.length,l=0;l<f;l++){if(w=d.row?d.row[l]:d.normalized[l][i.columns].$row,c=w.find("td").eq(r.column).text().replace(/[ ]/g," "),(u=(c.match(r.regex)||[]).length)>0&&r.alignIndex>0)for(g=Math.min(r.alignIndex,u),h=0,s=0,o=0;h++<g;)s=(o=c.indexOf(r.align,o+1))<0?s:o;else s=c.indexOf(r.align);s>=0?(b.push(c.substring(0,s)||""),_.push(c.substring(s,c.length)||"")):(b.push(u>=1&&r.alignIndex>=u?"":c||""),_.push(u>=1&&r.alignIndex>=u?c||"":""))}for(m=n.extend([],b).sort(function(n,a){return a.length-n.length})[0],p=n.extend([],_).sort(function(n,a){return a.length-n.length})[0],r.width=r.width||Math.floor(m.length/(m.length+p.length)*100)+r.adjust,m="min-width:"+r.width+"%",p="min-width:"+(100-r.width)+"%",e=0;e<i.$tbodies.length;e++)for(f=(d=i.cache[e]).normalized.length,l=0;l<f;l++)C=n(t.alignChar_wrap).length?n(t.alignChar_wrap).html(r.align)[0].outerHTML:r.align,w=d.row?d.row[l]:d.normalized[l][i.columns].$row,o=_[l].slice(r.align.length),w.find("td").eq(r.column).html('<span class="ts-align-wrap"><span class="ts-align-left" style="'+m+'">'+b[l]+'</span><span class="ts-align-right" style="'+p+'">'+(o.length?C+o:"")+"</span></span>");t.alignChar_initialized=!0}},remove:function(a,i,t){if(!n.isEmptyObject(i.cache)){var r,e,l,h,g;for(r=0;r<i.$tbodies.length;r++)for(l=(h=i.cache[r]).normalized.length,e=0;e<l;e++)(g=(h.row?h.row[e]:h.normalized[e][i.columns].$row).find("td").eq(t)).html(g.text().replace(/\s/g," "))}}},a.addWidget({id:"alignChar",priority:100,options:{alignChar_wrap:"",alignChar_charAttrib:"data-align-char",alignChar_indexAttrib:"data-align-index",alignChar_adjustAttrib:"data-align-adjust"},init:function(n,i,t,r){r.alignChar_initialized=!1,r.alignChar_savedVars=[],a.alignChar.init(n,t,r),t.$table.on("pagerEnd refreshAlign",function(){t.$headers.filter("["+r.alignChar_charAttrib+"]").each(function(){a.alignChar.remove(n,t,this.column)}),a.alignChar.init(n,t,r)})},format:function(n,a,i){i.alignChar_initialized||a.$table.triggerHandler("refreshAlign")},remove:function(n,i,t,r){r||(i.$headers.filter("["+t.alignChar_charAttrib+"]").each(function(){a.alignChar.remove(n,i,this.column)}),t.alignChar_initialized=!1)}})}(jQuery);