@osimatic/helpers-js 1.5.5 → 1.5.7

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.
package/media.js CHANGED
@@ -1,3 +1,6 @@
1
+ const { FormHelper } = require('./form_helper');
2
+ const { HTTPClient } = require('./http_client');
3
+
1
4
  class AudioMedia {
2
5
 
3
6
  static getPlayer(playUrl) {
@@ -6,37 +9,42 @@ class AudioMedia {
6
9
 
7
10
  static initPlayLinks(div) {
8
11
  // Affiche un lecteur audio
9
- div.find('.play_link').off('click').click(function () {
10
- let audio = $(AudioMedia.getPlayer($(this).data('play_url')));
11
- audio[0].play();
12
- $(this).after(audio);
13
- $(this).remove();
14
- return false;
12
+ div.querySelectorAll('.play_link').forEach(link => {
13
+ link.addEventListener('click', function(e) {
14
+ e.preventDefault();
15
+ const template = document.createElement('template');
16
+ template.innerHTML = AudioMedia.getPlayer(this.dataset.play_url);
17
+ const audio = template.content.firstChild;
18
+ audio.play();
19
+ this.insertAdjacentElement('afterend', audio);
20
+ this.remove();
21
+ });
15
22
  });
16
23
 
17
- div.find('.play_asynchronously_link').off('click').click(function () {
18
- //if (FormHelper.buttonLoader($(this), 'loading') != null) {
19
- let button = FormHelper.buttonLoader($(this), 'loading');
20
- AudioMedia.playAudioUrl($(this).data('url'), () => FormHelper.buttonLoader(button, 'reset'));
21
- //} else {
22
- // let button = $(this).attr('disabled', true).button('loading');
23
- // AudioMedia.playAudioUrl($(this).data('url'), () => button.attr('disabled', false).button('reset'));
24
- //}
25
- return false;
24
+ div.querySelectorAll('.play_asynchronously_link').forEach(link => {
25
+ link.addEventListener('click', function(e) {
26
+ e.preventDefault();
27
+ let button = FormHelper.buttonLoader(this, 'loading');
28
+ AudioMedia.playAudioUrl(this.dataset.url, () => FormHelper.buttonLoader(button, 'reset'));
29
+ });
26
30
  });
27
31
 
28
- div.find('.modal_play_link').off('click').click(function () {
29
- $('#modal_voice_message_play').on('show.bs.modal', function (event) {
30
- let button = $(event.relatedTarget);
31
- let modal = $(this);
32
-
33
- let player = modal.find('audio');
34
- player.prop('src', button.data('play_url'));
35
- player.play();
32
+ div.querySelectorAll('.modal_play_link').forEach(link => {
33
+ link.addEventListener('click', function(e) {
34
+ e.preventDefault();
35
+ const modalEl = document.getElementById('modal_voice_message_play');
36
+ if (!modalEl) return;
37
+ const currentLink = this;
38
+ modalEl.addEventListener('show.bs.modal', function handler(event) {
39
+ modalEl.removeEventListener('show.bs.modal', handler);
40
+ const player = modalEl.querySelector('audio');
41
+ if (player) {
42
+ player.src = (event.relatedTarget || currentLink).dataset.play_url;
43
+ player.play();
44
+ }
45
+ });
46
+ bootstrap.Modal.getOrCreateInstance(modalEl).show(this);
36
47
  });
37
-
38
- $('#modal_voice_message_play').modal('show', $(this));
39
- return false;
40
48
  });
41
49
  }
42
50
 
@@ -117,12 +125,12 @@ class AudioMedia {
117
125
 
118
126
  class VideoMedia {
119
127
  static initPlayPauseClick(videoElement) {
120
- $(videoElement).click(function(e) {
128
+ videoElement.addEventListener('click', function(e) {
121
129
  // handle click if not Firefox (Firefox supports this feature natively)
122
130
  if (typeof InstallTrigger === 'undefined') {
123
131
  // get click position
124
- let clickY = (e.pageY - $(this).offset().top);
125
- let height = parseFloat( $(this).height() );
132
+ let clickY = e.pageY - (this.getBoundingClientRect().top + window.scrollY);
133
+ let height = this.offsetHeight;
126
134
 
127
135
  // avoids interference with controls
128
136
  if (clickY > 0.82*height) return;
@@ -1,8 +1,10 @@
1
1
  require('./string');
2
2
  const { FlashMessage } = require('./flash_message');
3
+ const { toEl } = require('./util');
3
4
 
4
5
  class MultiFilesInput {
5
6
  static init(fileInput, setFilesList, nbMaxFiles, maxFileSize) {
7
+ fileInput = toEl(fileInput);
6
8
  let filesList = [];
7
9
  const formGroup = fileInput.closest('.form-group');
8
10
 
@@ -1,3 +1,4 @@
1
+ const { toEl } = require('./util');
1
2
 
2
3
  class MultipleActionInTable {
3
4
 
@@ -5,6 +6,7 @@ class MultipleActionInTable {
5
6
  // Idempotent : sans effet si les colonnes existent déjà.
6
7
  // Doit être appelé AVANT l'initialisation DataTable.
7
8
  static initCols(table, cellSelector = 'select') {
9
+ table = toEl(table);
8
10
  if (!table.classList.contains('table-action_multiple')) {
9
11
  return;
10
12
  }
@@ -26,6 +28,7 @@ class MultipleActionInTable {
26
28
  // Initialise les colonnes (via initCols) puis branche les event handlers.
27
29
  // Peut être appelé après l'initialisation DataTable.
28
30
  static init(table, options = {}) {
31
+ table = toEl(table);
29
32
  const { cellSelector = 'select', imgArrow = '' } = options;
30
33
 
31
34
  if (!table.classList.contains('table-action_multiple')) {
@@ -141,6 +144,7 @@ class MultipleActionInTable {
141
144
  class MultipleActionInDivList {
142
145
  // init checkbox
143
146
  static init(contentDiv, options = {}) {
147
+ contentDiv = toEl(contentDiv);
144
148
  const { imgArrow = '' } = options;
145
149
 
146
150
  let buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
@@ -254,115 +258,4 @@ class MultipleActionInDivList {
254
258
  }
255
259
  }
256
260
 
257
- module.exports = { MultipleActionInTable, MultipleActionInDivList };
258
-
259
- /*
260
- // init checkbox
261
- function initTableActionMultiple(table) {
262
- if (!table.hasClass('table-action_multiple')) {
263
- return;
264
- }
265
-
266
- var divBtn = tableActionMultipleGetDivBtn(table);
267
- if (divBtn == null) {
268
- return;
269
- }
270
-
271
- if (table.find('thead tr th[data-key="select"]').length === 0) {
272
- table.find('thead tr').prepend($('<th class="select no-sort" data-key="select"></th>'));
273
- }
274
- table.find('tbody tr:not(.no_items)').each(function(idx, tr) {
275
- if ($(tr).find('td.select').length === 0) {
276
- $(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>'));
277
- }
278
- });
279
-
280
- table.find('input.action_multiple_checkbox').each(function(idx, el) {
281
- var th = $(el).closest('table').find('thead tr th').first();
282
- if (th.find('input').length === 0) {
283
- // console.log(th);
284
- th.html('<input type="checkbox" class="action_multiple_check_all" />');
285
- // th.html('Coucou');
286
- }
287
- });
288
-
289
- table.find('input.action_multiple_checkbox').change(function() {
290
- majCheckbox(table);
291
- });
292
-
293
- table.find('input.action_multiple_check_all').off('click').click(function() {
294
- var table = $(this).closest('table');
295
- var checkbox = table.find('input.action_multiple_checkbox');
296
- var checkboxChecked = table.find('input.action_multiple_checkbox:checked');
297
- if (checkbox.length === checkboxChecked.length) {
298
- checkbox.prop('checked', false);
299
- }
300
- else {
301
- checkbox.prop('checked', true);
302
- }
303
- majCheckbox(table);
304
- });
305
- }
306
-
307
- function majCheckbox(table) {
308
- showButtonsAction(table);
309
-
310
- var allCheckbox = table.find('input.action_multiple_checkbox');
311
- var allCheckboxChecked = table.find('input.action_multiple_checkbox:checked');
312
- var checkboxSelectAll = table.find('thead tr th input.action_multiple_check_all');
313
- if (allCheckbox.length === allCheckboxChecked.length) {
314
- checkboxSelectAll.prop('checked', true);
315
- }
316
- else {
317
- checkboxSelectAll.prop('checked', false);
318
- }
319
- }
320
-
321
- function tableActionMultipleGetDivBtn(table) {
322
- var divTableResponsive = table.parent();
323
- var divBtn = divTableResponsive.next();
324
- if (divBtn.hasClass('action_multiple_buttons')) {
325
- return divBtn;
326
- }
327
- divBtn = divTableResponsive.parent().parent().parent().next();
328
- if (divBtn.hasClass('action_multiple_buttons')) {
329
- return divBtn;
330
- }
331
- return null;
332
- }
333
-
334
- function showButtonsAction(table) {
335
- var divBtn = tableActionMultipleGetDivBtn(table);
336
- if (divBtn == null) {
337
- return;
338
- }
339
-
340
- // console.log(divBtn);
341
- //var nbItems = $('input[name="' + checkbox.attr('name') + '"]:checked').length;
342
- var nbItems = table.find('input.action_multiple_checkbox:checked').length;
343
-
344
- if (nbItems > 0 && divBtn.is(':hidden')) {
345
- divBtn.removeClass('hide');
346
- }
347
- else if (nbItems === 0 && divBtn.is(':visible')) {
348
- divBtn.addClass('hide');
349
- }
350
-
351
- // affichage aucune action possible si aucun bouton n'est visible
352
- if (divBtn.is(':visible')) {
353
- divBtn.find('span.no_button').remove();
354
- if (divBtn.find('button:visible, a:visible').length === 0) {
355
- divBtn.find('img').after('<span class="no_button"><em>aucune action possible</em></span>');
356
- }
357
- }
358
- }
359
-
360
- $(function() {
361
- $('.action_multiple_buttons').prepend($('<img src="'+ROOT_PATH+DOSSIER_IMAGES+'arrow_ltr.png" alt="" /> &nbsp;'));
362
- $('.action_multiple_buttons').append($('<br/><br/>'));
363
-
364
- $('table.table-action_multiple').each(function(idx, table) {
365
- initTableActionMultiple($(table));
366
- });
367
- });
368
- */
261
+ module.exports = { MultipleActionInTable, MultipleActionInDivList };
package/network.js CHANGED
@@ -94,7 +94,7 @@ class UrlAndQueryString {
94
94
  let params = UrlAndQueryString.parseQuery(queryString);
95
95
  //console.log(params);
96
96
  params[name] = value;
97
- return decodeURI($.param(params));
97
+ return decodeURI(new URLSearchParams(params).toString());
98
98
  }
99
99
 
100
100
  static setParamOfUrl(name, value, url) {
@@ -1,4 +1,5 @@
1
1
  const L = require('leaflet');
2
+ const { toEl } = require('./util');
2
3
 
3
4
  /**
4
5
  * https://leafletjs.com/
@@ -8,6 +9,7 @@ const L = require('leaflet');
8
9
  class OpenStreetMap {
9
10
 
10
11
  constructor(mapContainer, options={}) {
12
+ mapContainer = toEl(mapContainer);
11
13
  /*let [lat, lng] = button.data('coordinates').split(',');
12
14
  let map = L.map('modal_map_canvas2').setView([lat, lng], 17);
13
15
 
@@ -27,6 +29,7 @@ class OpenStreetMap {
27
29
  }
28
30
 
29
31
  static createMap(mapContainer, options={}) {
32
+ mapContainer = toEl(mapContainer);
30
33
  if (!mapContainer.length) {
31
34
  return null;
32
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -13,6 +13,7 @@
13
13
  "license": "ISC",
14
14
  "description": "",
15
15
  "dependencies": {
16
+ "deepmerge": "^4.3.1",
16
17
  "ilib": "^14.21",
17
18
  "libphonenumber-js": "^1.12.39",
18
19
  "ua-parser-js": "^2.0.9"
package/paging.js CHANGED
@@ -2,17 +2,21 @@
2
2
  //Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
3
3
 
4
4
  const { UrlAndQueryString } = require('./network');
5
+ const { toEl } = require('./util');
5
6
 
6
7
  class Pagination {
7
8
  static paginateCards(div, nbItemsPerPage) {
9
+ div = toEl(div);
8
10
  Pagination.paginate(div, div.querySelectorAll('.pagination_item'), nbItemsPerPage, null);
9
11
  }
10
12
 
11
13
  static paginateTable(table, select=null) {
14
+ table = toEl(table); select = toEl(select);
12
15
  Pagination.paginate(table, table.querySelectorAll('tbody tr:not(.hide)'), parseInt(table.dataset.max_rows), select);
13
16
  }
14
17
 
15
18
  static paginate(div, items, nbItemsPerPage, select=null, labelDisplayAll=null) {
19
+ div = toEl(div); select = toEl(select);
16
20
  let maxItems = nbItemsPerPage;
17
21
 
18
22
  if (!div) {
package/select_all.js CHANGED
@@ -1,8 +1,11 @@
1
+ const { toEl } = require('./util');
2
+
1
3
  class SelectAll {
2
4
 
3
5
  // Dans un form-group
4
6
 
5
7
  static initLinkInFormGroup(link) {
8
+ link = toEl(link);
6
9
  const linkClone = link.cloneNode(true);
7
10
  link.parentElement.replaceChild(linkClone, link);
8
11
  linkClone.addEventListener('click', function(e) {
@@ -43,6 +46,7 @@ class SelectAll {
43
46
  // Dans tableau
44
47
 
45
48
  static initInTable(table) {
49
+ table = toEl(table);
46
50
  const inputCheckAll = table.querySelector('tr input.check_all');
47
51
  if (!inputCheckAll) {
48
52
  return;
@@ -78,6 +82,7 @@ class SelectAll {
78
82
  // Dans un div
79
83
 
80
84
  static initDiv(contentDiv) {
85
+ contentDiv = toEl(contentDiv);
81
86
  contentDiv.querySelectorAll('input.check_all').forEach(inputCheckAll => {
82
87
  const div = inputCheckAll.closest('div.checkbox_with_check_all');
83
88
 
package/sortable_list.js CHANGED
@@ -1,5 +1,8 @@
1
+ const { toEl } = require('./util');
2
+
1
3
  class SortableList {
2
4
  static init(sortableList, clientYOffset=0) {
5
+ sortableList = toEl(sortableList);
3
6
  sortableList.querySelectorAll('[draggable="true"]').forEach(item => {
4
7
  item.addEventListener('dragstart', () => {
5
8
  // Adding dragging class to an item after a delay