tablesorter/js/jquery.tablesorter.widgets.min.js
2011-12-06 09:25:51 -06:00

9 lines
4.7 KiB
JavaScript

/* TableSorter 2.0 Widgets - updated 12/6/2011 */
(function(a){
a.tablesorter.addWidget({id:"uitheme",format:function(d){var c,b,g,f=d.config,e=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"];f.widgetUitheme&&f.widgetUitheme.hasOwnProperty("css")&&(e=f.widgetUitheme.css||e);g=e.join(" ");f.debug&&(c=new Date);a(d).is(".ui-theme")||(a(d).addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),a.each(f.headerList,function(){a(this).addClass("ui-widget-header ui-corner-all").append('<span class="ui-icon"/>').hover(function(){a(this).addClass("ui-state-hover")}, function(){a(this).removeClass("ui-state-hover")})}));a.each(f.headerList,function(c){f.headers[c]&&!1===f.headers[c].sorter?a(this).find("span.ui-icon").removeClass(g+" ui-icon"):(b=a(this).is("."+f.cssAsc)?e[1]:a(this).is("."+f.cssDesc)?e[2]:a(this).is("."+f.cssHeader)?e[0]:"",a(this)[b===e[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(g).addClass(b))});f.debug&&a.tablesorter.benchmark("Applying uitheme widget",c)}});
a.tablesorter.addWidget({id:"columns",format:function(d){var c, b,g,f,e=d.config,i=e.sortList,h=i.length,j=["primary","secondary","tertiary"];e.widgetColumns&&e.widgetColumns.hasOwnProperty("css")&&(j=e.widgetColumns.css||j);g=j.length-1;f=j.join(" ");e.debug&&(b=new Date);i&&i[0]&&a("tr:visible",d.tBodies[0]).each(function(b){c=a(this).children().removeClass(f);c.eq(i[0][0]).addClass(j[0]);if(1<h)for(b=1;b<h;b++)c.eq(i[b][0]).addClass(j[b]||j[g])});e.debug&&a.tablesorter.benchmark("Applying Columns widget",b)}});
a.tablesorter.addWidget({id:"filter",format:function(d){if(!d.config.filtering){var c, b,g,f,e,i,h=d.config,j=h.headerList.length,k=a(d),d='<tr class="filters">',l;h.debug&&(l=new Date);for(c=0;c<j;c++)d+='<td><input type="text" class="filter" data-col="'+c+'" style="',d+=h.headers[c]&&"filter"in h.headers[c]&&!1===h.headers[c].filter||a(h.headerList[c]).is(".filter-false")?"display:none":"",d+='"></td>';k.find("thead").append(d+="</tr>").find(".filter").bind("keyup",function(){b=k.find(".filter").map(function(){return(a(this).val()||"").toLowerCase()}).get();""===b.join("")?k.find("tr").show(): k.find("tbody").find("tr:not(.expand-child)").each(function(){g=!0;e=a(this).nextUntil("tr:not(.expand-child)");f=e.length&&("undefined"!==typeof h.widgetFilterChildRows?h.widgetFilterChildRows:1)?e.text():"";i=a(this).find("td");for(c=0;c<j;c++)""!==b[c]&&0<=(i.eq(c).text()+f).toLowerCase().indexOf(b[c])?g=g?!0:!1:""!==b[c]&&(g=!1);a(this)[g?"show":"hide"]();if(e.length)e[g?"show":"hide"]()});k.trigger("applyWidgets")});h.filtering=!0;h.debug&&a.tablesorter.benchmark("Applying Filter widget",l)}}});
a.tablesorter.addWidget({id:"stickyHeaders",format:function(d){if(!a(d).find(".stickyHeader").length){var c=a(d),b=a(window),g=a(d).find("thead"),f=g.find("tr").children(),e=parseInt(f.eq(0).css("border-left-width"),10),i=g.find("tr").clone().addClass("stickyHeader").css({width:g.outerWidth()+2*e,position:"fixed",top:0,marginLeft:-e,visibility:"hidden",zIndex:10}),h=i.children();c.bind("sortEnd",function(b,c){var d=a(c).find("thead tr"),e=d.filter(".stickyHeader").children();d.filter(":not(.stickyHeader)").children().each(function(b){e.eq(b).attr("class", a(this).attr("class"))})});f.each(function(b){var c=a(this);h.eq(b).width(c.width()).bind("click",function(b){c.trigger(b)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1})});g.prepend(i);b.scroll(function(){var a=c.offset(),d=b.scrollTop(),d=d>a.top&&d<a.top+c.find("tbody").height()?"visible":"hidden";i.css({left:a.left-b.scrollLeft(),visibility:d})}).resize(function(){i.css({left:a(d).offset().left-b.scrollLeft(),width:g.outerWidth()+2*e});h.each(function(b){a(this).width(f.eq(b).width())})})}}});
a.tablesorter.addWidget({id:"resizable",format:function(d){if(!d.config.resizable){var c,b=d.config,g=b.headerList,f=g.length,e=function(){b.resizable_position=0;b.resizable_target=null;a(window).trigger("resize")};b.resizable_target=null;b.resizable_position=0;for(c=1;c<f;c++)a(g[c]).append('<div class="resizer" style="cursor:w-resize;position:absolute;height:100%;width:20px;left:-20px;top:0;z-index:1;"></div>').wrapInner('<div style="position:relative;height:100%;width:100%"></div>').find(".resizer").bind("mousedown", function(c){b.resizable_target=a(c.target).closest("th");b.resizable_position=c.pageX}).end().bind("mousemove",function(a){if(!(0===b.resizable_position||null===typeof b.resizable_target)){var c=a.pageX-b.resizable_position,d=b.resizable_target.closest("th").prev();if(!(b.resizable_target.width()<-c||d&&d.width()<=c))d.width(d.width()+c),b.resizable_position=a.pageX}}).bind("mouseup",function(){e();return!1});a(d).find("thead").bind("mouseup mouseleave",function(){e()});b.resizable=!0}}})
})(jQuery);