tablesorter/dist/js/widgets/widget-uitheme.min.js
2015-10-31 10:20:22 -05:00

28 lines
4.9 KiB
JavaScript

/*! Widget: uitheme - updated 3/26/2015 (v2.21.3) */
!function(a){"use strict";var b=a.tablesorter||{};b.themes={bootstrap:{table:"table table-bordered table-striped",caption:"caption",
// header class names
header:"bootstrap-header",// give the header a gradient background (theme.bootstrap_2.css)
sortNone:"",sortAsc:"",sortDesc:"",active:"",// applied when column is sorted
hover:"",// custom css required - a defined bootstrap style may not override other classes
// icon class names
icons:"",// add 'icon-white' to make them white; this icon class is added to the <i> in the header
iconSortNone:"bootstrap-icon-unsorted",// class name added to icon when column is not sorted
iconSortAsc:"icon-chevron-up glyphicon glyphicon-chevron-up",// class name added to icon when column has ascending sort
iconSortDesc:"icon-chevron-down glyphicon glyphicon-chevron-down",// class name added to icon when column has descending sort
filterRow:"",// filter row class
footerRow:"",footerCells:"",even:"",// even row zebra striping
odd:""},jui:{table:"ui-widget ui-widget-content ui-corner-all",// table classes
caption:"ui-widget-content",
// header class names
header:"ui-widget-header ui-corner-all ui-state-default",// header classes
sortNone:"",sortAsc:"",sortDesc:"",active:"ui-state-active",// applied when column is sorted
hover:"ui-state-hover",// hover class
// icon class names
icons:"ui-icon",// icon class added to the <i> in the header
iconSortNone:"ui-icon-carat-2-n-s",// class name added to icon when column is not sorted
iconSortAsc:"ui-icon-carat-1-n",// class name added to icon when column has ascending sort
iconSortDesc:"ui-icon-carat-1-s",// class name added to icon when column has descending sort
filterRow:"",footerRow:"",footerCells:"",even:"ui-widget-content",// even row zebra striping
odd:"ui-state-default"}},a.extend(b.css,{wrapper:"tablesorter-wrapper"}),b.addWidget({id:"uitheme",priority:10,format:function(c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q,r=b.themes,s=d.$table.add(a(d.namespace+"_extra_table")),t=d.$headers.add(a(d.namespace+"_extra_headers")),u=d.theme||"jui",v=r[u]||{},w=a.trim([v.sortNone,v.sortDesc,v.sortAsc,v.active].join(" ")),x=a.trim([v.iconSortNone,v.iconSortDesc,v.iconSortAsc].join(" "));for(d.debug&&(i=new Date),
// initialization code - run once
s.hasClass("tablesorter-"+u)&&d.theme===d.appliedTheme&&e.uitheme_applied||(e.uitheme_applied=!0,n=r[d.appliedTheme]||{},q=!a.isEmptyObject(n),o=q?[n.sortNone,n.sortDesc,n.sortAsc,n.active].join(" "):"",p=q?[n.iconSortNone,n.iconSortDesc,n.iconSortAsc].join(" "):"",q&&(e.zebra[0]=a.trim(" "+e.zebra[0].replace(" "+n.even,"")),e.zebra[1]=a.trim(" "+e.zebra[1].replace(" "+n.odd,"")),d.$tbodies.children().removeClass([n.even,n.odd].join(" "))),v.even&&(e.zebra[0]+=" "+v.even),v.odd&&(e.zebra[1]+=" "+v.odd),s.children("caption").removeClass(n.caption||"").addClass(v.caption),l=s.removeClass((d.appliedTheme?"tablesorter-"+(d.appliedTheme||""):"")+" "+(n.table||"")).addClass("tablesorter-"+u+" "+(v.table||"")).children("tfoot"),d.appliedTheme=d.theme,l.length&&l.children("tr").removeClass(n.footerRow||"").addClass(v.footerRow).children("th, td").removeClass(n.footerCells||"").addClass(v.footerCells),t.removeClass((q?[n.header,n.hover,o].join(" "):"")||"").addClass(v.header).not(".sorter-false").unbind("mouseenter.tsuitheme mouseleave.tsuitheme").bind("mouseenter.tsuitheme mouseleave.tsuitheme",function(b){a(this)["mouseenter"===b.type?"addClass":"removeClass"](v.hover||"")}),t.each(function(){var c=a(this);c.find("."+b.css.wrapper).length||c.wrapInner('<div class="'+b.css.wrapper+'" style="position:relative;height:100%;width:100%"></div>')}),d.cssIcon&&t.find("."+b.css.icon).removeClass(q?[n.icons,p].join(" "):"").addClass(v.icons||""),s.hasClass("hasFilters")&&s.children("thead").children("."+b.css.filterRow).removeClass(q?n.filterRow||"":"").addClass(v.filterRow||"")),f=0;f<d.columns;f++)j=d.$headers.add(a(d.namespace+"_extra_headers")).not(".sorter-false").filter('[data-column="'+f+'"]'),k=b.css.icon?j.find("."+b.css.icon):a(),m=t.not(".sorter-false").filter('[data-column="'+f+'"]:last'),m.length&&(j.removeClass(w),k.removeClass(x),m[0].sortDisabled?k.removeClass(v.icons||""):(g=v.sortNone,h=v.iconSortNone,m.hasClass(b.css.sortAsc)?(g=[v.sortAsc,v.active].join(" "),h=v.iconSortAsc):m.hasClass(b.css.sortDesc)&&(g=[v.sortDesc,v.active].join(" "),h=v.iconSortDesc),j.addClass(g),k.addClass(h||"")));d.debug&&console.log("Applying "+u+" theme"+b.benchmark(i))},remove:function(a,c,d,e){if(d.uitheme_applied){var f=c.$table,g=c.appliedTheme||"jui",h=b.themes[g]||b.themes.jui,i=f.children("thead").children(),j=h.sortNone+" "+h.sortDesc+" "+h.sortAsc,k=h.iconSortNone+" "+h.iconSortDesc+" "+h.iconSortAsc;f.removeClass("tablesorter-"+g+" "+h.table),d.uitheme_applied=!1,e||(f.find(b.css.header).removeClass(h.header),i.unbind("mouseenter.tsuitheme mouseleave.tsuitheme").removeClass(h.hover+" "+j+" "+h.active).filter("."+b.css.filterRow).removeClass(h.filterRow),i.find("."+b.css.icon).removeClass(h.icons+" "+k))}}})}(jQuery);