adblocker-image-data.js
1 year ago
admin-global.js
1 year ago
admin.js
1 year ago
admin.min.js
1 year ago
advertisement.js
9 years ago
conditions.js
1 year ago
dialog-advads-modal.js
1 year ago
groups.js
1 year ago
termination.js
1 year ago
ui.js
3 years ago
wizard.js
1 year ago
groups.js
58 lines
| 1 | jQuery(document).ready(function ($) { |
| 2 | function getCellValue(row, sortby, index) { |
| 3 | const $td = $(row).find('td'); |
| 4 | |
| 5 | if ('weight' === sortby) { |
| 6 | return parseInt($td.eq(index).find('select').val()) || 0; |
| 7 | } |
| 8 | if ('ad' === sortby) { |
| 9 | return $td.eq(index).find('a').text().trim(); |
| 10 | } |
| 11 | |
| 12 | return $td.eq(index).text().trim(); |
| 13 | } |
| 14 | |
| 15 | function sortAds(sortby, isAscending, table) { |
| 16 | const colIndex = $(table).find(`th[data-sortby=${sortby}]`).index(); |
| 17 | const tbody = $(table).find('tbody'); |
| 18 | const rows = tbody.find('tr').toArray(); |
| 19 | |
| 20 | rows.sort(function (a, b) { |
| 21 | const aValue = getCellValue(a, sortby, colIndex); |
| 22 | const bValue = getCellValue(b, sortby, colIndex); |
| 23 | |
| 24 | if (isNaN(aValue) || isNaN(bValue)) { |
| 25 | return isAscending |
| 26 | ? aValue.localeCompare(bValue) |
| 27 | : bValue.localeCompare(aValue); |
| 28 | } |
| 29 | |
| 30 | return isAscending ? aValue - bValue : bValue - aValue; |
| 31 | }); |
| 32 | |
| 33 | tbody.append(rows); |
| 34 | |
| 35 | $(table) |
| 36 | .find('th.group-sort') |
| 37 | .removeClass('asc desc') |
| 38 | .eq(colIndex) |
| 39 | .addClass(isAscending ? 'asc' : 'desc'); |
| 40 | } |
| 41 | |
| 42 | $('.advads-group-ads').each(function () { |
| 43 | const $this = $(this); |
| 44 | // eslint-disable-next-line prefer-const |
| 45 | let sortStates = { |
| 46 | ad: true, |
| 47 | status: true, |
| 48 | weight: true, |
| 49 | }; |
| 50 | |
| 51 | $this.find('th.group-sort').on('click', function () { |
| 52 | const sortby = $(this).data('sortby'); |
| 53 | sortAds(sortby, sortStates[sortby], this.closest('table')); |
| 54 | sortStates[sortby] = !sortStates[sortby]; |
| 55 | }); |
| 56 | }); |
| 57 | }); |
| 58 |