tablesorter/js/jquery.tablesorter.widgets.min.js

9 lines
4.8 KiB
JavaScript
Raw Normal View History

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