Debian Codegraph @

js/widgets/widget-uitheme.js

raw symbols SCIP
1 /*! Widget: uitheme - updated 2018-03-18 (v2.30.0) */
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 // header class names
11 header : 'bootstrap-header', // give the header a gradient background (theme.bootstrap_2.css)
12 sortNone : '',
13 sortAsc : '',
14 sortDesc : '',
15 active : '', // applied when column is sorted
16 hover : '', // custom css required - a defined bootstrap style may not override other classes
17 // icon class names
18 icons : '', // add 'bootstrap-icon-white' to make them white; this icon class is added to the <i> in the header
19 iconSortNone : 'bootstrap-icon-unsorted', // class name added to icon when column is not sorted
20 iconSortAsc : 'glyphicon glyphicon-chevron-up', // class name added to icon when column has ascending sort
21 iconSortDesc : 'glyphicon glyphicon-chevron-down', // class name added to icon when column has descending sort
22 filterRow : '', // filter row class
23 footerRow : '',
24 footerCells : '',
25 even : '', // even row zebra striping
26 odd : '' // odd row zebra striping
27 },
28 'jui' : {
29 table : 'ui-widget ui-widget-content ui-corner-all', // table classes
30 caption : 'ui-widget-content',
31 // header class names
32 header : 'ui-widget-header ui-corner-all ui-state-default', // header classes
33 sortNone : '',
34 sortAsc : '',
35 sortDesc : '',
36 active : 'ui-state-active', // applied when column is sorted
37 hover : 'ui-state-hover', // hover class
38 // icon class names
39 icons : 'ui-icon', // icon class added to the <i> in the header
40 iconSortNone : 'ui-icon-carat-2-n-s ui-icon-caret-2-n-s', // class name added to icon when column is not sorted
41 iconSortAsc : 'ui-icon-carat-1-n ui-icon-caret-1-n', // class name added to icon when column has ascending sort
42 iconSortDesc : 'ui-icon-carat-1-s ui-icon-caret-1-s', // class name added to icon when column has descending sort
43 filterRow : '',
44 footerRow : '',
45 footerCells : '',
46 even : 'ui-widget-content', // even row zebra striping
47 odd : 'ui-state-default' // odd row zebra striping
48 }
49 };
50
51 $.extend(ts.css, {
52 wrapper : 'tablesorter-wrapper' // ui theme & resizable
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 // initialization code - run once
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 // update zebra stripes
82 if (themes.even) { wo.zebra[0] += ' ' + themes.even; }
83 if (themes.odd) { wo.zebra[1] += ' ' + themes.odd; }
84 // add caption style
85 $table.children('caption')
86 .removeClass(oldtheme.caption || '')
87 .addClass(themes.caption);
88 // add table/footer class names
89 $tfoot = $table
90 // remove other selected themes
91 .removeClass( (c.appliedTheme ? 'tablesorter-' + (c.appliedTheme || '') : '') + ' ' + (oldtheme.table || '') )
92 .addClass('tablesorter-' + theme + ' ' + (themes.table || '')) // add theme widget class name
93 .children('tfoot');
94 c.appliedTheme = c.theme;
95
96 if ($tfoot.length) {
97 $tfoot
98 // if oldtheme.footerRow or oldtheme.footerCells are undefined, all class names are removed
99 .children('tr').removeClass(oldtheme.footerRow || '').addClass(themes.footerRow)
100 .children('th, td').removeClass(oldtheme.footerCells || '').addClass(themes.footerCells);
101 }
102 // update header classes
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 // toggleClass with switch added in jQuery 1.3
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 // Firefox needs this inner div to position the icon & resizer correctly
117 $this.wrapInner('<div class="' + ts.css.wrapper + '" style="position:relative;height:100%;width:100%"></div>');
118 }
119 });
120 if (c.cssIcon) {
121 // if c.cssIcon is '', then no <i> is added to the header
122 $headers
123 .find('.' + ts.css.icon)
124 .removeClass(hasOldTheme ? [ oldtheme.icons, oldIconRmv ].join(' ') : '')
125 .addClass(themes.icons || '');
126 }
127 // filter widget initializes after uitheme
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 // no sort arrows for disabled columns!
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') // remove hover
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);