@osimatic/helpers-js 1.5.3 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,19 +5,20 @@ class MultipleActionInTable {
5
5
  // Idempotent : sans effet si les colonnes existent déjà.
6
6
  // Doit être appelé AVANT l'initialisation DataTable.
7
7
  static initCols(table, cellSelector = 'select') {
8
- if (!table.hasClass('table-action_multiple')) {
8
+ if (!table.classList.contains('table-action_multiple')) {
9
9
  return;
10
10
  }
11
11
  if (MultipleActionInTable.getDivBtn(table) == null) {
12
12
  return;
13
13
  }
14
14
 
15
- if (table.find('thead tr th[data-key="select"]').length === 0) {
16
- table.find('thead tr').prepend($('<th class="' + cellSelector + '" data-key="select"></th>'));
15
+ const theadTr = table.querySelector('thead tr');
16
+ if (theadTr && !theadTr.querySelector('th[data-key="select"]')) {
17
+ theadTr.insertAdjacentHTML('afterbegin', '<th class="' + cellSelector + '" data-key="select"></th>');
17
18
  }
18
- table.find('tbody tr:not(.no_items)').each(function(idx, tr) {
19
- if ($(tr).find('td.select').length === 0) {
20
- $(tr).prepend($('<td class="select"><input type="checkbox" class="action_multiple_checkbox" name="' + $(tr).data('action_multiple_input_name') + '" value="' + $(tr).data('action_multiple_item_id') + '"></td>'));
19
+ table.querySelectorAll('tbody tr:not(.no_items)').forEach(tr => {
20
+ if (!tr.querySelector('td.select')) {
21
+ tr.insertAdjacentHTML('afterbegin', '<td class="select"><input type="checkbox" class="action_multiple_checkbox" name="' + tr.dataset.action_multiple_input_name + '" value="' + tr.dataset.action_multiple_item_id + '"></td>');
21
22
  }
22
23
  });
23
24
  }
@@ -27,7 +28,7 @@ class MultipleActionInTable {
27
28
  static init(table, options = {}) {
28
29
  const { cellSelector = 'select', imgArrow = '' } = options;
29
30
 
30
- if (!table.hasClass('table-action_multiple')) {
31
+ if (!table.classList.contains('table-action_multiple')) {
31
32
  return;
32
33
  }
33
34
 
@@ -38,33 +39,36 @@ class MultipleActionInTable {
38
39
 
39
40
  MultipleActionInTable.initCols(table, cellSelector);
40
41
 
41
- if (!divBtn.hasClass('action_multiple_buttons_initialized')) {
42
- divBtn.prepend($('<img src="'+imgArrow+'" alt="" /> &nbsp;'));
43
- divBtn.append($('<br/><br/>'));
44
- divBtn.addClass('action_multiple_buttons_initialized');
42
+ if (!divBtn.classList.contains('action_multiple_buttons_initialized')) {
43
+ divBtn.insertAdjacentHTML('afterbegin', '<img src="'+imgArrow+'" alt="" /> &nbsp;');
44
+ divBtn.insertAdjacentHTML('beforeend', '<br/><br/>');
45
+ divBtn.classList.add('action_multiple_buttons_initialized');
45
46
  }
46
47
 
47
- let firstTh = table.find('thead tr th').first();
48
- if (firstTh.find('input').length === 0) {
49
- firstTh.html('<input type="checkbox" class="action_multiple_check_all" />');
48
+ const firstTh = table.querySelector('thead tr th');
49
+ if (firstTh && !firstTh.querySelector('input')) {
50
+ firstTh.innerHTML = '<input type="checkbox" class="action_multiple_check_all" />';
50
51
  }
51
52
 
52
- table.find('input.action_multiple_checkbox').change(function() {
53
- MultipleActionInTable.updateCheckbox(table);
53
+ table.querySelectorAll('input.action_multiple_checkbox').forEach(cb => {
54
+ cb.addEventListener('change', () => {
55
+ MultipleActionInTable.updateCheckbox(table);
56
+ });
54
57
  });
55
58
 
56
- table.find('input.action_multiple_check_all').off('click').click(function() {
57
- let table = $(this).closest('table');
58
- let checkbox = table.find('input.action_multiple_checkbox');
59
- let checkboxChecked = table.find('input.action_multiple_checkbox:checked');
60
- if (checkbox.length === checkboxChecked.length) {
61
- checkbox.prop('checked', false);
62
- }
63
- else {
64
- checkbox.prop('checked', true);
65
- }
66
- MultipleActionInTable.updateCheckbox(table);
67
- });
59
+ const checkAll = table.querySelector('input.action_multiple_check_all');
60
+ if (checkAll) {
61
+ const checkAllClone = checkAll.cloneNode(true);
62
+ checkAll.parentElement.replaceChild(checkAllClone, checkAll);
63
+ checkAllClone.addEventListener('click', function() {
64
+ const t = this.closest('table');
65
+ const checkboxes = t.querySelectorAll('input.action_multiple_checkbox');
66
+ const checked = t.querySelectorAll('input.action_multiple_checkbox:checked');
67
+ const newState = checkboxes.length !== checked.length;
68
+ checkboxes.forEach(cb => { cb.checked = newState; });
69
+ MultipleActionInTable.updateCheckbox(t);
70
+ });
71
+ }
68
72
 
69
73
  MultipleActionInTable.updateCheckbox(table);
70
74
  }
@@ -72,60 +76,62 @@ class MultipleActionInTable {
72
76
  static updateCheckbox(table) {
73
77
  MultipleActionInTable.showButtonsAction(table);
74
78
 
75
- let allCheckbox = table.find('input.action_multiple_checkbox');
76
- let allCheckboxChecked = table.find('input.action_multiple_checkbox:checked');
77
- let checkboxSelectAll = table.find('thead tr th input.action_multiple_check_all');
79
+ const allCheckbox = table.querySelectorAll('input.action_multiple_checkbox');
80
+ const allCheckboxChecked = table.querySelectorAll('input.action_multiple_checkbox:checked');
81
+ const checkboxSelectAll = table.querySelector('thead tr th input.action_multiple_check_all');
78
82
 
79
- if (allCheckbox.length === 0) {
80
- checkboxSelectAll.addClass('hide');
83
+ if (!checkboxSelectAll) {
81
84
  return;
82
85
  }
83
86
 
84
- checkboxSelectAll.removeClass('hide');
85
- if (allCheckbox.length === allCheckboxChecked.length) {
86
- checkboxSelectAll.prop('checked', true);
87
- }
88
- else {
89
- checkboxSelectAll.prop('checked', false);
87
+ if (allCheckbox.length === 0) {
88
+ checkboxSelectAll.classList.add('hide');
89
+ return;
90
90
  }
91
+
92
+ checkboxSelectAll.classList.remove('hide');
93
+ checkboxSelectAll.checked = allCheckbox.length === allCheckboxChecked.length;
91
94
  }
92
95
 
93
96
  static getDivBtn(table) {
94
- let divTableResponsive = table.parent();
95
- let divBtn = divTableResponsive.next();
96
- if (divBtn.hasClass('action_multiple_buttons')) {
97
+ const divTableResponsive = table.parentElement;
98
+ let divBtn = divTableResponsive.nextElementSibling;
99
+ if (divBtn && divBtn.classList.contains('action_multiple_buttons')) {
97
100
  return divBtn;
98
101
  }
99
- divBtn = divTableResponsive.parent().parent().parent().next();
100
- if (divBtn.hasClass('action_multiple_buttons')) {
102
+ divBtn = divTableResponsive.parentElement?.parentElement?.parentElement?.nextElementSibling;
103
+ if (divBtn && divBtn.classList.contains('action_multiple_buttons')) {
101
104
  return divBtn;
102
105
  }
103
106
  return null;
104
107
  }
105
108
 
106
109
  static showButtonsAction(table) {
107
- let divBtn = MultipleActionInTable.getDivBtn(table);
110
+ const divBtn = MultipleActionInTable.getDivBtn(table);
108
111
  if (divBtn == null) {
109
112
  return;
110
113
  }
111
114
 
112
- // console.log(divBtn);
113
- //var nbItems = $('input[name="' + checkbox.attr('name') + '"]:checked').length;
114
- let nbItems = table.find('input.action_multiple_checkbox:checked').length;
115
+ const nbItems = table.querySelectorAll('input.action_multiple_checkbox:checked').length;
116
+ const isHidden = divBtn.classList.contains('hide');
117
+ const isVisible = !isHidden;
115
118
 
116
- if (nbItems > 0 && divBtn.is(':hidden')) {
117
- divBtn.removeClass('hide');
119
+ if (nbItems > 0 && isHidden) {
120
+ divBtn.classList.remove('hide');
118
121
  }
119
122
  // 13/04/2021 : si le tableau est caché cela veut dire qu'il est en train de s'initialiser (après avoir chargé les données) et donc s'il n'y a pas de ligne sélectionnées, on cache la div buttons
120
- else if ((nbItems === 0 && divBtn.is(':visible')) || (nbItems === 0 && table.is(':hidden'))) {
121
- divBtn.addClass('hide');
123
+ else if ((nbItems === 0 && isVisible) || (nbItems === 0 && table.classList.contains('hide'))) {
124
+ divBtn.classList.add('hide');
122
125
  }
123
126
 
124
127
  // affichage aucune action possible si aucun bouton n'est visible
125
- if (divBtn.is(':visible')) {
126
- divBtn.find('span.no_button').remove();
127
- if (divBtn.find('button:visible, a:visible').length === 0) {
128
- divBtn.find('img').after('<span class="no_button"><em>aucune action possible</em></span>');
128
+ if (!divBtn.classList.contains('hide')) {
129
+ divBtn.querySelectorAll('span.no_button').forEach(el => el.remove());
130
+ if (divBtn.querySelectorAll('button:not(.hide), a:not(.hide)').length === 0) {
131
+ const img = divBtn.querySelector('img');
132
+ if (img) {
133
+ img.insertAdjacentHTML('afterend', '<span class="no_button"><em>aucune action possible</em></span>');
134
+ }
129
135
  }
130
136
  }
131
137
  }
@@ -142,46 +148,49 @@ class MultipleActionInDivList {
142
148
  return;
143
149
  }
144
150
 
145
- buttonsDiv.addClass('hide');
151
+ buttonsDiv.classList.add('hide');
146
152
 
147
153
  // Si aucune div sélectionnable, on n'applique pas le plugin
148
- if (!contentDiv.find('.multiple_action').length) {
154
+ if (!contentDiv.querySelectorAll('.multiple_action').length) {
149
155
  return;
150
156
  }
151
157
 
152
- if (!buttonsDiv.data('action_multiple_buttons_initialized')) {
153
- buttonsDiv.prepend($('<img src="'+imgArrow+'" alt="" /> &nbsp;'));
154
- buttonsDiv.append($('<br/><br/>'));
155
- buttonsDiv.data('action_multiple_buttons_initialized', 1);
158
+ if (!buttonsDiv.dataset.action_multiple_buttons_initialized) {
159
+ buttonsDiv.insertAdjacentHTML('afterbegin', '<img src="'+imgArrow+'" alt="" /> &nbsp;');
160
+ buttonsDiv.insertAdjacentHTML('beforeend', '<br/><br/>');
161
+ buttonsDiv.dataset.action_multiple_buttons_initialized = '1';
156
162
  }
157
163
 
158
164
  // Ajout checkbox pour chaque div sélectionnable
159
- contentDiv.find('.multiple_action').each(function(idx, div) {
160
- if ($(div).find('div.multi_select').length === 0) {
161
- $(div).prepend($('<div class="multi_select float-start me-2"><input type="checkbox" class="action_multiple_checkbox" name="'+$(div).data('action_multiple_input_name')+'" value="'+$(div).data('action_multiple_item_id')+'"></div>'));
165
+ contentDiv.querySelectorAll('.multiple_action').forEach(div => {
166
+ if (!div.querySelector('div.multi_select')) {
167
+ div.insertAdjacentHTML('afterbegin', '<div class="multi_select float-start me-2"><input type="checkbox" class="action_multiple_checkbox" name="'+div.dataset.action_multiple_input_name+'" value="'+div.dataset.action_multiple_item_id+'"></div>');
162
168
  }
163
169
  });
164
170
 
165
171
  // Ajout checkbox select all
166
- if (contentDiv.find('input.action_multiple_check_all').length === 0) {
167
- contentDiv.prepend('<p class="mb-2"><input type="checkbox" class="action_multiple_check_all" /> Tout sélectionner</p>');
172
+ if (!contentDiv.querySelector('input.action_multiple_check_all')) {
173
+ contentDiv.insertAdjacentHTML('afterbegin', '<p class="mb-2"><input type="checkbox" class="action_multiple_check_all" /> Tout sélectionner</p>');
168
174
  }
169
175
 
170
- contentDiv.find('input.action_multiple_checkbox').change(function() {
171
- MultipleActionInDivList.updateCheckbox(contentDiv);
176
+ contentDiv.querySelectorAll('input.action_multiple_checkbox').forEach(cb => {
177
+ cb.addEventListener('change', () => {
178
+ MultipleActionInDivList.updateCheckbox(contentDiv);
179
+ });
172
180
  });
173
181
 
174
- contentDiv.find('input.action_multiple_check_all').off('click').click(function() {
175
- let checkbox = contentDiv.find('input.action_multiple_checkbox');
176
- let checkboxChecked = contentDiv.find('input.action_multiple_checkbox:checked');
177
- if (checkbox.length === checkboxChecked.length) {
178
- checkbox.prop('checked', false);
179
- }
180
- else {
181
- checkbox.prop('checked', true);
182
- }
183
- MultipleActionInDivList.updateCheckbox(contentDiv);
184
- });
182
+ const checkAll = contentDiv.querySelector('input.action_multiple_check_all');
183
+ if (checkAll) {
184
+ const checkAllClone = checkAll.cloneNode(true);
185
+ checkAll.parentElement.replaceChild(checkAllClone, checkAll);
186
+ checkAllClone.addEventListener('click', function() {
187
+ const checkboxes = contentDiv.querySelectorAll('input.action_multiple_checkbox');
188
+ const checked = contentDiv.querySelectorAll('input.action_multiple_checkbox:checked');
189
+ const newState = checkboxes.length !== checked.length;
190
+ checkboxes.forEach(cb => { cb.checked = newState; });
191
+ MultipleActionInDivList.updateCheckbox(contentDiv);
192
+ });
193
+ }
185
194
 
186
195
  MultipleActionInDivList.updateCheckbox(contentDiv);
187
196
  }
@@ -189,55 +198,57 @@ class MultipleActionInDivList {
189
198
  static updateCheckbox(contentDiv) {
190
199
  MultipleActionInDivList.showButtonsAction(contentDiv);
191
200
 
192
- let allCheckbox = contentDiv.find('input.action_multiple_checkbox');
193
- let allCheckboxChecked = contentDiv.find('input.action_multiple_checkbox:checked');
194
- let checkboxSelectAll = contentDiv.find('input.action_multiple_check_all');
201
+ const allCheckbox = contentDiv.querySelectorAll('input.action_multiple_checkbox');
202
+ const allCheckboxChecked = contentDiv.querySelectorAll('input.action_multiple_checkbox:checked');
203
+ const checkboxSelectAll = contentDiv.querySelector('input.action_multiple_check_all');
195
204
 
196
- if (allCheckbox.length === 0) {
197
- checkboxSelectAll.addClass('hide');
205
+ if (!checkboxSelectAll) {
198
206
  return;
199
207
  }
200
208
 
201
- checkboxSelectAll.removeClass('hide');
202
- if (allCheckbox.length === allCheckboxChecked.length) {
203
- checkboxSelectAll.prop('checked', true);
204
- }
205
- else {
206
- checkboxSelectAll.prop('checked', false);
209
+ if (allCheckbox.length === 0) {
210
+ checkboxSelectAll.classList.add('hide');
211
+ return;
207
212
  }
213
+
214
+ checkboxSelectAll.classList.remove('hide');
215
+ checkboxSelectAll.checked = allCheckbox.length === allCheckboxChecked.length;
208
216
  }
209
217
 
210
218
  static getButtonsDiv(contentDiv) {
211
- let buttonsDiv = contentDiv.next();
212
- if (buttonsDiv.hasClass('action_multiple_buttons')) {
219
+ const buttonsDiv = contentDiv.nextElementSibling;
220
+ if (buttonsDiv && buttonsDiv.classList.contains('action_multiple_buttons')) {
213
221
  return buttonsDiv;
214
222
  }
215
223
  return null;
216
224
  }
217
225
 
218
226
  static showButtonsAction(contentDiv) {
219
- let buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
227
+ const buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
220
228
  if (buttonsDiv == null) {
221
229
  return;
222
230
  }
223
231
 
224
- // console.log(divBtn);
225
- //var nbItems = $('input[name="' + checkbox.attr('name') + '"]:checked').length;
226
- let nbItems = contentDiv.find('input.action_multiple_checkbox:checked').length;
232
+ const nbItems = contentDiv.querySelectorAll('input.action_multiple_checkbox:checked').length;
233
+ const isHidden = buttonsDiv.classList.contains('hide');
234
+ const isVisible = !isHidden;
227
235
 
228
- if (nbItems > 0 && buttonsDiv.is(':hidden')) {
229
- buttonsDiv.removeClass('hide');
236
+ if (nbItems > 0 && isHidden) {
237
+ buttonsDiv.classList.remove('hide');
230
238
  }
231
239
  // 13/04/2021 : si le tableau est caché cela veut dire qu'il est en train de s'initialiser (après avoir chargé les données) et donc s'il n'y a pas de ligne sélectionnées, on cache la div buttons
232
- else if ((nbItems === 0 && buttonsDiv.is(':visible')) || (nbItems === 0 && contentDiv.is(':hidden'))) {
233
- buttonsDiv.addClass('hide');
240
+ else if ((nbItems === 0 && isVisible) || (nbItems === 0 && contentDiv.classList.contains('hide'))) {
241
+ buttonsDiv.classList.add('hide');
234
242
  }
235
243
 
236
244
  // affichage aucune action possible si aucun bouton n'est visible
237
- if (buttonsDiv.is(':visible')) {
238
- buttonsDiv.find('span.no_button').remove();
239
- if (buttonsDiv.find('button:visible, a:visible').length === 0) {
240
- buttonsDiv.find('img').after('<span class="no_button"><em>aucune action possible</em></span>');
245
+ if (!buttonsDiv.classList.contains('hide')) {
246
+ buttonsDiv.querySelectorAll('span.no_button').forEach(el => el.remove());
247
+ if (buttonsDiv.querySelectorAll('button:not(.hide), a:not(.hide)').length === 0) {
248
+ const img = buttonsDiv.querySelector('img');
249
+ if (img) {
250
+ img.insertAdjacentHTML('afterend', '<span class="no_button"><em>aucune action possible</em></span>');
251
+ }
241
252
  }
242
253
  }
243
254
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
package/paging.js CHANGED
@@ -1,146 +1,165 @@
1
1
  // Fonction commune de pagination
2
2
  //Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
3
3
 
4
+ const { UrlAndQueryString } = require('./network');
5
+
4
6
  class Pagination {
5
- static paginateCards(div, nbItemsPerPage, doublePagination) {
6
- Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage, undefined, doublePagination);
7
+ static paginateCards(div, nbItemsPerPage) {
8
+ Pagination.paginate(div, div.querySelectorAll('.pagination_item'), nbItemsPerPage, null);
7
9
  }
8
10
 
9
- static paginateTable(table, select, doublePagination) {
10
- Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select, doublePagination);
11
+ static paginateTable(table, select=null) {
12
+ Pagination.paginate(table, table.querySelectorAll('tbody tr:not(.hide)'), parseInt(table.dataset.max_rows), select);
11
13
  }
12
14
 
13
- static paginate(div, items, nbItemsPerPage, select, doublePagination) {
15
+ static paginate(div, items, nbItemsPerPage, select=null, labelDisplayAll=null) {
14
16
  let maxItems = nbItemsPerPage;
15
17
 
16
- if (typeof div == 'undefined' || !div.length) {
18
+ if (!div) {
17
19
  return;
18
20
  }
19
21
 
20
- if (typeof select != 'undefined' && select.length) {
21
- if (!select.children().length) {
22
- select.append('<option value="0">'+labelDisplayAll+'</option>');
23
- let nbRowsList = select.data('nb_rows_list') ? select.data('nb_rows_list').split(',') : [5, 10, 25, 50];
24
- $.each(nbRowsList, function(idx, nbRows) {
25
- select.append('<option value="'+nbRows+'">'+nbRows+'</option>');
22
+ if (select != null) {
23
+ if (!select.children.length) {
24
+ const opt0 = document.createElement('option');
25
+ opt0.value = '0';
26
+ opt0.textContent = labelDisplayAll ?? 'Afficher tout';
27
+ select.appendChild(opt0);
28
+
29
+ const nbRowsList = select.dataset.nb_rows_list ? select.dataset.nb_rows_list.split(',') : [5, 10, 25, 50];
30
+ nbRowsList.forEach(nbRows => {
31
+ const opt = document.createElement('option');
32
+ opt.value = nbRows;
33
+ opt.textContent = nbRows;
34
+ select.appendChild(opt);
26
35
  });
27
36
 
28
- if (select.data('default_nb_rows')) {
29
- select.val(select.data('default_nb_rows'))
37
+ if (select.dataset.default_nb_rows) {
38
+ select.value = select.dataset.default_nb_rows;
30
39
  }
31
40
  }
32
41
 
33
- maxItems = parseInt(select.val());
42
+ maxItems = parseInt(select.value);
34
43
 
35
- select.change(() => Pagination.paginate(div, items, nbItemsPerPage, select, doublePagination));
44
+ select.addEventListener('change', () => Pagination.paginate(div, items, nbItemsPerPage, select));
36
45
  }
37
46
 
38
- const ulPagination = $('ul.pagination');
39
- if (doublePagination) {
40
- ulPagination.each((index, ul) => $(ul).remove());
41
- Pagination.initPaginationDiv(div, ulPagination, true, true); //top
42
- Pagination.initPaginationDiv(div, ulPagination, false, true); //bottom
43
- } else {
44
- Pagination.initPaginationDiv(div, ulPagination, false, false); //bottom
45
- }
47
+ document.querySelectorAll('ul.pagination').forEach(ul => ul.remove());
48
+ Pagination.initPaginationDiv(div, true); // top
49
+ Pagination.initPaginationDiv(div, false); // bottom
46
50
 
47
- Pagination.initPaginationItems(items, maxItems, doublePagination);
51
+ Pagination.initPaginationItems(items, maxItems);
48
52
  }
49
53
 
50
- static initPaginationDiv(div, ulDiv, onTop, doublePagination) {
51
- if (!ulDiv.length || doublePagination) {
52
- ulDiv = $('<ul class="pagination"></ul>');
53
- if (div.find('.pagination_links').length) {
54
- (onTop ? div.find('.pagination_links').prepend(ulDiv) : div.find('.pagination_links').append(ulDiv))
54
+ static initPaginationDiv(div, onTop) {
55
+ const ul = document.createElement('ul');
56
+ ul.className = 'pagination';
57
+
58
+ const paginationLinks = div.querySelector('.pagination_links');
59
+ if (paginationLinks) {
60
+ if (onTop) {
61
+ paginationLinks.prepend(ul);
62
+ } else {
63
+ paginationLinks.appendChild(ul);
64
+ }
65
+ } else {
66
+ if (onTop) {
67
+ div.before(ul);
55
68
  } else {
56
- (onTop ? div.before(ulDiv) : div.after(ulDiv));
69
+ div.after(ul);
57
70
  }
58
71
  }
59
72
  }
60
73
 
61
- static initPaginationItems(items, maxItems, doublePagination) {
62
- const paginationUl = $('ul.pagination');
74
+ static initPaginationItems(items, maxItems) {
75
+ const paginationUls = [...document.querySelectorAll('ul.pagination')];
63
76
 
64
- let totalItems = items.length;
77
+ const totalItems = items.length;
65
78
 
66
79
  let lineNum = 0;
67
- items.each(function () {
80
+ items.forEach(item => {
68
81
  lineNum++;
69
82
  if (0 === maxItems || lineNum <= maxItems) {
70
- $(this).show();
71
- }
72
- else {
73
- $(this).hide();
83
+ item.style.display = '';
84
+ } else {
85
+ item.style.display = 'none';
74
86
  }
75
87
  });
76
88
 
77
- paginationUl.each((index, ul) => $(ul).find('li').remove());
89
+ paginationUls.forEach(ul => ul.querySelectorAll('li').forEach(li => li.remove()));
78
90
 
79
91
  if (0 === maxItems || totalItems < maxItems) {
80
- paginationUl.each((index, ul) => $(ul).addClass('hide'));
92
+ paginationUls.forEach(ul => ul.classList.add('hide'));
81
93
  return;
82
94
  }
83
95
 
84
- let nbPages = Math.ceil(totalItems/maxItems);
85
- for (let i=1; i <= nbPages; i++) {
86
- paginationUl.each((index, ul) => $(ul).append('<li class="page-item" data-page="'+i+'"><a href="#" class="page-link">'+i+'<span class="sr-only">(current)</span></a></li>').show());
96
+ const nbPages = Math.ceil(totalItems / maxItems);
97
+ for (let i = 1; i <= nbPages; i++) {
98
+ paginationUls.forEach(ul => {
99
+ ul.insertAdjacentHTML('beforeend', '<li class="page-item" data-page="' + i + '"><a href="#" class="page-link">' + i + '<span class="sr-only">(current)</span></a></li>');
100
+ });
87
101
  }
88
102
 
89
- paginationUl.each((index, ul) => $(ul).removeClass('hide'));
90
- paginationUl.each((index, ul) => $(ul).find('li:first-child').addClass('active'));
91
- paginationUl.each((index, ul) => $(ul).find('li').click(function () {
92
- paginationUl.each((index, ul) => $(ul).find('li').removeClass('active'));
93
-
94
- let pageNum = $(this).data('page');
95
- let trIndex = 0;
96
-
97
- if (doublePagination) {
98
- $('li[data-page="' + pageNum + '"]').each((index, li) => $(li).addClass('active'));
99
- } else {
100
- $(this).addClass('active');
101
- }
102
-
103
- items.each(function () {
104
- trIndex++;
105
- if (trIndex > (maxItems*pageNum) || trIndex <= ((maxItems*pageNum)-maxItems)) {
106
- $(this).hide();
107
- }
108
- else{
109
- $(this).show();
110
- }
103
+ paginationUls.forEach(ul => ul.classList.remove('hide'));
104
+ paginationUls.forEach(ul => {
105
+ const firstLi = ul.querySelector('li:first-child');
106
+ if (firstLi) firstLi.classList.add('active');
107
+ });
108
+ paginationUls.forEach(ul => {
109
+ ul.querySelectorAll('li').forEach(li => {
110
+ li.addEventListener('click', function(e) {
111
+ e.preventDefault();
112
+ paginationUls.forEach(ul2 => ul2.querySelectorAll('li').forEach(l => l.classList.remove('active')));
113
+
114
+ const pageNum = parseInt(this.dataset.page);
115
+ let trIndex = 0;
116
+
117
+ document.querySelectorAll('li[data-page="' + pageNum + '"]').forEach(l => l.classList.add('active'));
118
+
119
+ items.forEach(item => {
120
+ trIndex++;
121
+ if (trIndex > (maxItems * pageNum) || trIndex <= ((maxItems * pageNum) - maxItems)) {
122
+ item.style.display = 'none';
123
+ } else {
124
+ item.style.display = '';
125
+ }
126
+ });
127
+ });
111
128
  });
112
-
113
- return false;
114
- }));
129
+ });
115
130
  }
116
131
  }
117
132
 
118
133
  class Navigation {
119
134
  static activateTab(a) {
120
- //console.log(a);
121
- //a.click();
122
135
  let ulNav = a.closest('.nav');
123
- let tabContent = ulNav.parent().find('.tab-content');
124
-
125
- // déselection éventuel des onglets
126
- ulNav.find('a.nav-link').each(function(idx, navLink) {
127
- $(navLink).removeClass('active');
128
- let id = $(navLink).attr('href');
129
- if (id.substr(0, 1) === '#') {
130
- tabContent.find(id).removeClass('active').removeClass('show');
136
+ let tabContent = ulNav.parentElement.querySelector('.tab-content');
137
+
138
+ ulNav.querySelectorAll('a.nav-link').forEach(navLink => {
139
+ navLink.classList.remove('active');
140
+ const id = navLink.getAttribute('href');
141
+ if (id && id.charAt(0) === '#') {
142
+ const pane = tabContent.querySelector(id);
143
+ if (pane) {
144
+ pane.classList.remove('active');
145
+ pane.classList.remove('show');
146
+ }
131
147
  }
132
148
  });
133
149
 
134
- // sélection de l'onglet correspondant au navLink passé en paramètre
135
- a.addClass('active');
136
- tabContent.find(a.attr('href')).addClass('active').addClass('show');
150
+ a.classList.add('active');
151
+ const targetPane = tabContent.querySelector(a.getAttribute('href'));
152
+ if (targetPane) {
153
+ targetPane.classList.add('active');
154
+ targetPane.classList.add('show');
155
+ }
137
156
  }
138
157
 
139
158
  static showTab(a) {
140
159
  if (typeof bootstrap == 'undefined') {
141
160
  return;
142
161
  }
143
- let tab = new bootstrap.Tab(a[0]);
162
+ let tab = new bootstrap.Tab(a);
144
163
  tab.show();
145
164
  }
146
165
 
@@ -180,7 +199,7 @@ function paginationAsList(nbResultatsTotal, nbResultatsParPage, urlPage, nomPara
180
199
 
181
200
  // Initialisation du numéro de la page courante
182
201
  //var query = window.location.search.substring(1).query.split("&");
183
-
202
+
184
203
  var url = new URL(currentUrl);
185
204
  var params = url.searchParams;
186
205