|
13 | 13 | bootstrapVersion = parseInt($.fn.dropdown.Constructor.VERSION, 10) |
14 | 14 | } catch (e) {} |
15 | 15 |
|
16 | | - const Utils = { |
17 | | - bs: { |
18 | | - 3: { |
19 | | - buttonsClass: 'default', |
20 | | - iconsPrefix: 'glyphicon', |
21 | | - icons: { |
22 | | - paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down', |
23 | | - paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up', |
24 | | - refresh: 'glyphicon-refresh icon-refresh', |
25 | | - toggleOff: 'glyphicon-list-alt icon-list-alt', |
26 | | - toggleOn: 'glyphicon-list-alt icon-list-alt', |
27 | | - columns: 'glyphicon-th icon-th', |
28 | | - detailOpen: 'glyphicon-plus icon-plus', |
29 | | - detailClose: 'glyphicon-minus icon-minus', |
30 | | - fullscreen: 'glyphicon-fullscreen' |
31 | | - }, |
32 | | - pullClass: 'pull', |
33 | | - toobarDropdowHtml: ['<ul class="dropdown-menu" role="menu">', '</ul>'], |
34 | | - toobarDropdowItemHtml: '<li role="menuitem"><label>%s</label></li>', |
35 | | - pageDropdownHtml: ['<ul class="dropdown-menu" role="menu">', '</ul>'], |
36 | | - pageDropdownItemHtml: '<li role="menuitem" class="%s"><a href="#">%s</a></li>' |
| 16 | + const bootstrap = { |
| 17 | + 3: { |
| 18 | + iconsPrefix: 'glyphicon', |
| 19 | + icons: { |
| 20 | + paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down', |
| 21 | + paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up', |
| 22 | + refresh: 'glyphicon-refresh icon-refresh', |
| 23 | + toggleOff: 'glyphicon-list-alt icon-list-alt', |
| 24 | + toggleOn: 'glyphicon-list-alt icon-list-alt', |
| 25 | + columns: 'glyphicon-th icon-th', |
| 26 | + detailOpen: 'glyphicon-plus icon-plus', |
| 27 | + detailClose: 'glyphicon-minus icon-minus', |
| 28 | + fullscreen: 'glyphicon-fullscreen' |
37 | 29 | }, |
38 | | - 4: { |
39 | | - buttonsClass: 'secondary', |
40 | | - iconsPrefix: 'fa', |
41 | | - icons: { |
42 | | - paginationSwitchDown: 'fa-toggle-down', |
43 | | - paginationSwitchUp: 'fa-toggle-up', |
44 | | - refresh: 'fa-refresh', |
45 | | - toggleOff: 'fa-toggle-off', |
46 | | - toggleOn: 'fa-toggle-on', |
47 | | - columns: 'fa-th-list', |
48 | | - detailOpen: 'fa-plus', |
49 | | - detailClose: 'fa-minus', |
50 | | - fullscreen: 'fa-arrows-alt' |
51 | | - }, |
52 | | - pullClass: 'float', |
53 | | - toobarDropdowHtml: ['<div class="dropdown-menu dropdown-menu-right">', '</div>'], |
54 | | - toobarDropdowItemHtml: '<label class="dropdown-item">%s</label>', |
55 | | - pageDropdownHtml: ['<div class="dropdown-menu">', '</div>'], |
56 | | - pageDropdownItemHtml: '<a class="dropdown-item %s" href="#">%s</a>' |
| 30 | + classes: { |
| 31 | + buttons: 'default', |
| 32 | + pull: 'pull' |
| 33 | + }, |
| 34 | + html: { |
| 35 | + toobarDropdow: ['<ul class="dropdown-menu" role="menu">', '</ul>'], |
| 36 | + toobarDropdowItem: '<li role="menuitem"><label>%s</label></li>', |
| 37 | + pageDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'], |
| 38 | + pageDropdownItem: '<li role="menuitem" class="%s"><a href="#">%s</a></li>' |
57 | 39 | } |
58 | | - }[bootstrapVersion], |
| 40 | + }, |
| 41 | + 4: { |
| 42 | + iconsPrefix: 'fa', |
| 43 | + icons: { |
| 44 | + paginationSwitchDown: 'fa-toggle-down', |
| 45 | + paginationSwitchUp: 'fa-toggle-up', |
| 46 | + refresh: 'fa-refresh', |
| 47 | + toggleOff: 'fa-toggle-off', |
| 48 | + toggleOn: 'fa-toggle-on', |
| 49 | + columns: 'fa-th-list', |
| 50 | + detailOpen: 'fa-plus', |
| 51 | + detailClose: 'fa-minus', |
| 52 | + fullscreen: 'fa-arrows-alt' |
| 53 | + }, |
| 54 | + classes: { |
| 55 | + buttons: 'secondary', |
| 56 | + pull: 'float' |
| 57 | + }, |
| 58 | + html: { |
| 59 | + toobarDropdow: ['<div class="dropdown-menu dropdown-menu-right">', '</div>'], |
| 60 | + toobarDropdowItem: '<label class="dropdown-item">%s</label>', |
| 61 | + pageDropdown: ['<div class="dropdown-menu">', '</div>'], |
| 62 | + pageDropdownItem: '<a class="dropdown-item %s" href="#">%s</a>' |
| 63 | + } |
| 64 | + } |
| 65 | + }[bootstrapVersion] |
| 66 | + |
| 67 | + const Utils = { |
| 68 | + bootstrapVersion, |
59 | 69 |
|
60 | 70 | // it only does '%s', and return '' when arguments are undefined |
61 | 71 | sprintf (str, ...args) { |
|
92 | 102 | } |
93 | 103 |
|
94 | 104 | for (let i = 0; i < columns.length; i++) { |
95 | | - flag[i] = []; |
96 | | - for (let j = 0; j < totalCol; j++) { |
97 | | - flag[i][j] = false; |
98 | | - } |
| 105 | + flag[i] = [] |
| 106 | + for (let j = 0; j < totalCol; j++) { |
| 107 | + flag[i][j] = false |
| 108 | + } |
99 | 109 | } |
100 | 110 |
|
101 | 111 | for (let i = 0; i < columns.length; i++) { |
|
332 | 342 | searchTimeOut: 500, |
333 | 343 | searchText: '', |
334 | 344 | iconSize: undefined, |
335 | | - buttonsClass: Utils.bs.buttonsClass, |
336 | | - iconsPrefix: Utils.bs.iconsPrefix, // glyphicon or fa(font-awesome) |
337 | | - icons: Utils.bs.icons, |
| 345 | + buttonsClass: bootstrap.classes.buttons, |
| 346 | + iconsPrefix: bootstrap.iconsPrefix, // glyphicon or fa(font-awesome) |
| 347 | + icons: bootstrap.icons, |
338 | 348 | customSearch: $.noop, |
339 | 349 | customSort: $.noop, |
340 | 350 | ignoreClickToSelectOn (element) { |
|
942 | 952 |
|
943 | 953 | if (index !== -1) { |
944 | 954 | if (this.options.sortStable) { |
945 | | - this.data.forEach(row => { |
| 955 | + this.data.forEach((row, i) => { |
946 | 956 | row._position = i |
947 | 957 | }) |
948 | 958 | } |
|
1061 | 1071 | this.$toolbar.html('') |
1062 | 1072 |
|
1063 | 1073 | if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') { |
1064 | | - $(Utils.sprintf('<div class="bs-bars %s-%s"></div>', Utils.bs.pullClass, this.options.toolbarAlign)) |
| 1074 | + $(Utils.sprintf('<div class="bs-bars %s-%s"></div>', bootstrap.classes.pull, this.options.toolbarAlign)) |
1065 | 1075 | .appendTo(this.$toolbar) |
1066 | 1076 | .append($(this.options.toolbar)) |
1067 | 1077 | } |
1068 | 1078 |
|
1069 | 1079 | // showColumns, showToggle, showRefresh |
1070 | 1080 | html = [Utils.sprintf('<div class="columns columns-%s btn-group %s-%s">', |
1071 | | - this.options.buttonsAlign, Utils.bs.pullClass, this.options.buttonsAlign)] |
| 1081 | + this.options.buttonsAlign, bootstrap.classes.pull, this.options.buttonsAlign)] |
1072 | 1082 |
|
1073 | 1083 | if (typeof this.options.icons === 'string') { |
1074 | 1084 | this.options.icons = Utils.calculateObjectValue(null, this.options.icons) |
|
1114 | 1124 | Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns), |
1115 | 1125 | ' <span class="caret"></span>', |
1116 | 1126 | '</button>', |
1117 | | - Utils.bs.toobarDropdowHtml[0]) |
| 1127 | + bootstrap.html.toobarDropdow[0]) |
1118 | 1128 |
|
1119 | 1129 | $.each(this.columns, (i, column) => { |
1120 | 1130 | if (column.radio || column.checkbox) { |
|
1128 | 1138 | const checked = column.visible ? ' checked="checked"' : '' |
1129 | 1139 |
|
1130 | 1140 | if (column.switchable) { |
1131 | | - html.push(Utils.sprintf(Utils.bs.toobarDropdowItemHtml, |
| 1141 | + html.push(Utils.sprintf(bootstrap.html.toobarDropdowItem, |
1132 | 1142 | Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s> %s', |
1133 | 1143 | column.field, i, checked, column.title))) |
1134 | 1144 | switchableCount++ |
1135 | 1145 | } |
1136 | 1146 | }) |
1137 | | - html.push(Utils.bs.toobarDropdowHtml[1], '</div>') |
| 1147 | + html.push(bootstrap.html.toobarDropdow[1], '</div>') |
1138 | 1148 | } |
1139 | 1149 |
|
1140 | 1150 | html.push('</div>') |
|
1182 | 1192 | if (this.options.search) { |
1183 | 1193 | html = [] |
1184 | 1194 | html.push( |
1185 | | - Utils.sprintf('<div class="%s-%s search">', Utils.bs.pullClass, this.options.searchAlign), |
| 1195 | + Utils.sprintf('<div class="%s-%s search">', bootstrap.classes.pull, this.options.searchAlign), |
1186 | 1196 | Utils.sprintf(`<input class="form-control${Utils.sprintf(' input-%s', this.options.iconSize)}" type="text" placeholder="%s">`, |
1187 | 1197 | this.options.formatSearch()), |
1188 | 1198 | '</div>') |
|
1367 | 1377 | } |
1368 | 1378 |
|
1369 | 1379 | html.push( |
1370 | | - Utils.sprintf('<div class="%s-%s pagination-detail">', Utils.bs.pullClass, this.options.paginationDetailHAlign), |
| 1380 | + Utils.sprintf('<div class="%s-%s pagination-detail">', bootstrap.classes.pull, this.options.paginationDetailHAlign), |
1371 | 1381 | '<span class="pagination-info">', |
1372 | 1382 | this.options.onlyInfoPagination ? this.options.formatDetailPagination(this.options.totalRows) |
1373 | 1383 | : this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows), |
|
1386 | 1396 | '</span>', |
1387 | 1397 | ' <span class="caret"></span>', |
1388 | 1398 | '</button>', |
1389 | | - Utils.bs.pageDropdownHtml[0] |
| 1399 | + bootstrap.html.pageDropdown[0] |
1390 | 1400 | ] |
1391 | 1401 |
|
1392 | 1402 | if (typeof this.options.pageList === 'string') { |
|
1408 | 1418 | } else { |
1409 | 1419 | active = page === this.options.pageSize ? 'active' : '' |
1410 | 1420 | } |
1411 | | - pageNumber.push(Utils.sprintf(Utils.bs.pageDropdownItemHtml, active, page)) |
| 1421 | + pageNumber.push(Utils.sprintf(bootstrap.html.pageDropdownItem, active, page)) |
1412 | 1422 | } |
1413 | 1423 | }) |
1414 | | - pageNumber.push(`${Utils.bs.pageDropdownHtml[1]}</span>`) |
| 1424 | + pageNumber.push(`${bootstrap.html.pageDropdown[1]}</span>`) |
1415 | 1425 |
|
1416 | 1426 | html.push(this.options.formatRecordsPerPage(pageNumber.join(''))) |
1417 | 1427 | html.push('</span>') |
1418 | 1428 |
|
1419 | 1429 | html.push('</div>', |
1420 | | - Utils.sprintf('<div class="%s-%s pagination">', Utils.bs.pullClass, this.options.paginationHAlign), |
| 1430 | + Utils.sprintf('<div class="%s-%s pagination">', bootstrap.classes.pull, this.options.paginationHAlign), |
1421 | 1431 | `<ul class="pagination${Utils.sprintf(' pagination-%s', this.options.iconSize)}">`, |
1422 | 1432 | Utils.sprintf('<li class="page-item page-pre"><a class="page-link" href="#">%s</a></li>', |
1423 | 1433 | this.options.paginationPreText)) |
|
0 commit comments