| 1 |
|
| 2 |
;(function ($) { |
| 3 |
'use strict'; |
| 4 |
var ts = $.tablesorter || {}; |
| 5 |
|
| 6 |
ts.themes = { |
| 7 |
'bootstrap' : { |
| 8 |
table : 'table table-bordered table-striped', |
| 9 |
caption : 'caption', |
| 10 |
|
| 11 |
header : 'bootstrap-header', |
| 12 |
sortNone : '', |
| 13 |
sortAsc : '', |
| 14 |
sortDesc : '', |
| 15 |
active : '', |
| 16 |
hover : '', |
| 17 |
|
| 18 |
icons : '', |
| 19 |
iconSortNone : 'bootstrap-icon-unsorted', |
| 20 |
iconSortAsc : 'glyphicon glyphicon-chevron-up', |
| 21 |
iconSortDesc : 'glyphicon glyphicon-chevron-down', |
| 22 |
filterRow : '', |
| 23 |
footerRow : '', |
| 24 |
footerCells : '', |
| 25 |
even : '', |
| 26 |
odd : '' |
| 27 |
}, |
| 28 |
'jui' : { |
| 29 |
table : 'ui-widget ui-widget-content ui-corner-all', |
| 30 |
caption : 'ui-widget-content', |
| 31 |
|
| 32 |
header : 'ui-widget-header ui-corner-all ui-state-default', |
| 33 |
sortNone : '', |
| 34 |
sortAsc : '', |
| 35 |
sortDesc : '', |
| 36 |
active : 'ui-state-active', |
| 37 |
hover : 'ui-state-hover', |
| 38 |
|
| 39 |
icons : 'ui-icon', |
| 40 |
iconSortNone : 'ui-icon-carat-2-n-s ui-icon-caret-2-n-s', |
| 41 |
iconSortAsc : 'ui-icon-carat-1-n ui-icon-caret-1-n', |
| 42 |
iconSortDesc : 'ui-icon-carat-1-s ui-icon-caret-1-s', |
| 43 |
filterRow : '', |
| 44 |
footerRow : '', |
| 45 |
footerCells : '', |
| 46 |
even : 'ui-widget-content', |
| 47 |
odd : 'ui-state-default' |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
$.extend(ts.css, { |
| 52 |
wrapper : 'tablesorter-wrapper' |
| 53 |
}); |
| 54 |
|
| 55 |
ts.addWidget({ |
| 56 |
id: 'uitheme', |
| 57 |
priority: 10, |
| 58 |
format: function(table, c, wo) { |
| 59 |
var i, tmp, hdr, icon, time, $header, $icon, $tfoot, $h, oldtheme, oldremove, oldIconRmv, hasOldTheme, |
| 60 |
themesAll = ts.themes, |
| 61 |
$table = c.$table.add( $( c.namespace + '_extra_table' ) ), |
| 62 |
$headers = c.$headers.add( $( c.namespace + '_extra_headers' ) ), |
| 63 |
theme = c.theme || 'jui', |
| 64 |
themes = themesAll[theme] || {}, |
| 65 |
remove = $.trim( [ themes.sortNone, themes.sortDesc, themes.sortAsc, themes.active ].join( ' ' ) ), |
| 66 |
iconRmv = $.trim( [ themes.iconSortNone, themes.iconSortDesc, themes.iconSortAsc ].join( ' ' ) ), |
| 67 |
debug = ts.debug(c, 'uitheme'); |
| 68 |
if (debug) { time = new Date(); } |
| 69 |
|
| 70 |
if (!$table.hasClass('tablesorter-' + theme) || c.theme !== c.appliedTheme || !wo.uitheme_applied) { |
| 71 |
wo.uitheme_applied = true; |
| 72 |
oldtheme = themesAll[c.appliedTheme] || {}; |
| 73 |
hasOldTheme = !$.isEmptyObject(oldtheme); |
| 74 |
oldremove = hasOldTheme ? [ oldtheme.sortNone, oldtheme.sortDesc, oldtheme.sortAsc, oldtheme.active ].join( ' ' ) : ''; |
| 75 |
oldIconRmv = hasOldTheme ? [ oldtheme.iconSortNone, oldtheme.iconSortDesc, oldtheme.iconSortAsc ].join( ' ' ) : ''; |
| 76 |
if (hasOldTheme) { |
| 77 |
wo.zebra[0] = $.trim( ' ' + wo.zebra[0].replace(' ' + oldtheme.even, '') ); |
| 78 |
wo.zebra[1] = $.trim( ' ' + wo.zebra[1].replace(' ' + oldtheme.odd, '') ); |
| 79 |
c.$tbodies.children().removeClass( [ oldtheme.even, oldtheme.odd ].join(' ') ); |
| 80 |
} |
| 81 |
|
| 82 |
if (themes.even) { wo.zebra[0] += ' ' + themes.even; } |
| 83 |
if (themes.odd) { wo.zebra[1] += ' ' + themes.odd; } |
| 84 |
|
| 85 |
$table.children('caption') |
| 86 |
.removeClass(oldtheme.caption || '') |
| 87 |
.addClass(themes.caption); |
| 88 |
|
| 89 |
$tfoot = $table |
| 90 |
|
| 91 |
.removeClass( (c.appliedTheme ? 'tablesorter-' + (c.appliedTheme || '') : '') + ' ' + (oldtheme.table || '') ) |
| 92 |
.addClass('tablesorter-' + theme + ' ' + (themes.table || '')) |
| 93 |
.children('tfoot'); |
| 94 |
c.appliedTheme = c.theme; |
| 95 |
|
| 96 |
if ($tfoot.length) { |
| 97 |
$tfoot |
| 98 |
|
| 99 |
.children('tr').removeClass(oldtheme.footerRow || '').addClass(themes.footerRow) |
| 100 |
.children('th, td').removeClass(oldtheme.footerCells || '').addClass(themes.footerCells); |
| 101 |
} |
| 102 |
|
| 103 |
$headers |
| 104 |
.removeClass( (hasOldTheme ? [ oldtheme.header, oldtheme.hover, oldremove ].join(' ') : '') || '' ) |
| 105 |
.addClass(themes.header) |
| 106 |
.not('.sorter-false') |
| 107 |
.unbind('mouseenter.tsuitheme mouseleave.tsuitheme') |
| 108 |
.bind('mouseenter.tsuitheme mouseleave.tsuitheme', function(event) { |
| 109 |
|
| 110 |
$(this)[ event.type === 'mouseenter' ? 'addClass' : 'removeClass' ](themes.hover || ''); |
| 111 |
}); |
| 112 |
|
| 113 |
$headers.each(function() { |
| 114 |
var $this = $(this); |
| 115 |
if (!$this.find('.' + ts.css.wrapper).length) { |
| 116 |
|
| 117 |
$this.wrapInner('<div class="' + ts.css.wrapper + '" style="position:relative;height:100%;width:100%"></div>'); |
| 118 |
} |
| 119 |
}); |
| 120 |
if (c.cssIcon) { |
| 121 |
|
| 122 |
$headers |
| 123 |
.find('.' + ts.css.icon) |
| 124 |
.removeClass(hasOldTheme ? [ oldtheme.icons, oldIconRmv ].join(' ') : '') |
| 125 |
.addClass(themes.icons || ''); |
| 126 |
} |
| 127 |
|
| 128 |
if (ts.hasWidget( c.table, 'filter' )) { |
| 129 |
tmp = function() { |
| 130 |
$table.children('thead').children('.' + ts.css.filterRow) |
| 131 |
.removeClass(hasOldTheme ? oldtheme.filterRow || '' : '') |
| 132 |
.addClass(themes.filterRow || ''); |
| 133 |
}; |
| 134 |
if (wo.filter_initialized) { |
| 135 |
tmp(); |
| 136 |
} else { |
| 137 |
$table.one('filterInit', function() { |
| 138 |
tmp(); |
| 139 |
}); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
for (i = 0; i < c.columns; i++) { |
| 144 |
$header = c.$headers |
| 145 |
.add($(c.namespace + '_extra_headers')) |
| 146 |
.not('.sorter-false') |
| 147 |
.filter('[data-column="' + i + '"]'); |
| 148 |
$icon = (ts.css.icon) ? $header.find('.' + ts.css.icon) : $(); |
| 149 |
$h = $headers.not('.sorter-false').filter('[data-column="' + i + '"]:last'); |
| 150 |
if ($h.length) { |
| 151 |
$header.removeClass(remove); |
| 152 |
$icon.removeClass(iconRmv); |
| 153 |
if ($h[0].sortDisabled) { |
| 154 |
|
| 155 |
$icon.removeClass(themes.icons || ''); |
| 156 |
} else { |
| 157 |
hdr = themes.sortNone; |
| 158 |
icon = themes.iconSortNone; |
| 159 |
if ($h.hasClass(ts.css.sortAsc)) { |
| 160 |
hdr = [ themes.sortAsc, themes.active ].join(' '); |
| 161 |
icon = themes.iconSortAsc; |
| 162 |
} else if ($h.hasClass(ts.css.sortDesc)) { |
| 163 |
hdr = [ themes.sortDesc, themes.active ].join(' '); |
| 164 |
icon = themes.iconSortDesc; |
| 165 |
} |
| 166 |
$header.addClass(hdr); |
| 167 |
$icon.addClass(icon || ''); |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
if (debug) { |
| 172 |
console.log('uitheme >> Applied ' + theme + ' theme' + ts.benchmark(time)); |
| 173 |
} |
| 174 |
}, |
| 175 |
remove: function(table, c, wo, refreshing) { |
| 176 |
if (!wo.uitheme_applied) { return; } |
| 177 |
var $table = c.$table, |
| 178 |
theme = c.appliedTheme || 'jui', |
| 179 |
themes = ts.themes[ theme ] || ts.themes.jui, |
| 180 |
$headers = $table.children('thead').children(), |
| 181 |
remove = themes.sortNone + ' ' + themes.sortDesc + ' ' + themes.sortAsc, |
| 182 |
iconRmv = themes.iconSortNone + ' ' + themes.iconSortDesc + ' ' + themes.iconSortAsc; |
| 183 |
$table.removeClass('tablesorter-' + theme + ' ' + themes.table); |
| 184 |
wo.uitheme_applied = false; |
| 185 |
if (refreshing) { return; } |
| 186 |
$table.find(ts.css.header).removeClass(themes.header); |
| 187 |
$headers |
| 188 |
.unbind('mouseenter.tsuitheme mouseleave.tsuitheme') |
| 189 |
.removeClass(themes.hover + ' ' + remove + ' ' + themes.active) |
| 190 |
.filter('.' + ts.css.filterRow) |
| 191 |
.removeClass(themes.filterRow); |
| 192 |
$headers.find('.' + ts.css.icon).removeClass(themes.icons + ' ' + iconRmv); |
| 193 |
} |
| 194 |
}); |
| 195 |
|
| 196 |
})(jQuery); |