@osimatic/helpers-js 1.1.9 → 1.1.11

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/array.js CHANGED
@@ -63,6 +63,12 @@ Object.filter = (obj, predicate) => {
63
63
  .reduce( (res, key) => (res[key] = obj[key], res), {} );
64
64
  };
65
65
 
66
+ Object.filterKeys = (obj, predicate) => {
67
+ return Object.keys(obj)
68
+ .filter( key => predicate(key) )
69
+ .reduce( (res, key) => (res[key] = obj[key], res), {} );
70
+ };
71
+
66
72
  Object.renameKeys = function(obj, keysMap) {
67
73
  return Object.keys(obj).reduce(
68
74
  (acc, key) => ({
@@ -94,18 +94,24 @@ class OpenStreetMap {
94
94
  this.locations.push([latitude, longitude]);
95
95
  }
96
96
 
97
+ setView(location, zoom) {
98
+ this.map.setView(location, zoom);
99
+ }
100
+
97
101
  centerOnFrance() {
98
102
  this.map.setView([46.52863469527167, 2.43896484375], 6);
99
103
  }
100
104
 
101
- centerOnMarkers() {
105
+ centerOnMarkers(padding) {
102
106
  this.map.invalidateSize(false);
103
107
 
104
108
  if (this.locations.length === 0) {
105
109
  return;
106
110
  }
107
111
 
108
- this.map.fitBounds(new L.LatLngBounds(this.locations));
112
+ this.map.fitBounds(new L.LatLngBounds(this.locations), {
113
+ padding: typeof padding != 'undefined' ? padding : [0, 0]
114
+ });
109
115
  }
110
116
 
111
117
  connectMarkers() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/paging.js CHANGED
@@ -135,6 +135,14 @@ class Navigation {
135
135
  a.addClass('active');
136
136
  tabContent.find(a.attr('href')).addClass('active').addClass('show');
137
137
  }
138
+
139
+ static showTab(a) {
140
+ if (typeof bootstrap == 'undefined') {
141
+ return;
142
+ }
143
+ let tab = new bootstrap.Tab(a[0]);
144
+ tab.show();
145
+ }
138
146
  }
139
147
 
140
148
  module.exports = { Pagination, Navigation };
package/package.json.bak DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "name": "@osimatic/helpers-js",
3
- "version": "1.1.7",
4
- "main": "main.js",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
7
- },
8
- "keywords": [],
9
- "author": "",
10
- "license": "ISC",
11
- "description": "",
12
- "dependencies": {
13
- "ilib": "^14.16.0"
14
- }
15
- }
package/paging.js.bak DELETED
@@ -1,258 +0,0 @@
1
- // Fonction commune de pagination
2
- //Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
3
-
4
- class Pagination {
5
- static paginateCards(div, nbItemsPerPage, doublePagination) {
6
- Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage, undefined, doublePagination);
7
- }
8
-
9
- static paginateTable(table, select, doublePagination) {
10
- Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select, doublePagination);
11
- }
12
-
13
- static paginate(div, items, nbItemsPerPage, select, doublePagination) {
14
- let maxItems = nbItemsPerPage;
15
-
16
- if (typeof div == 'undefined' || !div.length) {
17
- return;
18
- }
19
-
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>');
26
- });
27
-
28
- if (select.data('default_nb_rows')) {
29
- select.val(select.data('default_nb_rows'))
30
- }
31
- }
32
-
33
- maxItems = parseInt(select.val());
34
-
35
- select.change(update);
36
- }
37
-
38
- if (doublePagination) {
39
- Pagination.initPaginationDiv(div, $('ul.pagination'), true, true); //top
40
- Pagination.initPaginationDiv(div, $('ul.pagination'), false, true); //bottom
41
- } else {
42
- Pagination.initPaginationDiv(div, $('ul.pagination'), false, false); //bottom
43
- }
44
-
45
- Pagination.initPaginationItems(items, maxItems, doublePagination);
46
- }
47
-
48
- static initPaginationDiv(div, ulDiv, onTop, doublePagination) {
49
- if (!ulDiv.length || doublePagination) {
50
- ulDiv = $('<ul class="pagination"></ul>');
51
- if (div.find('.pagination_links').length) {
52
- (onTop ? div.find('.pagination_links').prepend(ulDiv) : div.find('.pagination_links').append(ulDiv))
53
- } else {
54
- (onTop ? div.before(ulDiv) : div.after(ulDiv));
55
- }
56
- }
57
- }
58
-
59
- static initPaginationItems(items, maxItems, doublePagination) {
60
- const paginationUl = $('ul.pagination');
61
-
62
- let totalItems = items.length;
63
-
64
- let lineNum = 0;
65
- items.each(function () {
66
- lineNum++;
67
- if (0 === maxItems || lineNum <= maxItems) {
68
- $(this).show();
69
- }
70
- else {
71
- $(this).hide();
72
- }
73
- });
74
-
75
- paginationUl.each((index, ul) => $(ul).find('li').remove());
76
-
77
- if (0 === maxItems || totalItems < maxItems) {
78
- paginationUl.each((index, ul) => $(ul).addClass('hide'));
79
- return;
80
- }
81
-
82
- let nbPages = Math.ceil(totalItems/maxItems);
83
- for (let i=1; i <= nbPages; i++) {
84
- 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());
85
- }
86
-
87
- paginationUl.each((index, ul) => $(ul).removeClass('hide'));
88
- paginationUl.each((index, ul) => $(ul).find('li:first-child').addClass('active'));
89
- paginationUl.each((index, ul) => $(ul).find('li').click(function () {
90
- paginationUl.each((index, ul) => $(ul).find('li').removeClass('active'));
91
-
92
- let pageNum = $(this).data('page');
93
- let trIndex = 0;
94
-
95
- if (doublePagination) {
96
- $('li[data-page="' + pageNum + '"]').each((index, li) => $(li).addClass('active'));
97
- } else {
98
- $(this).addClass('active');
99
- }
100
-
101
- items.each(function () {
102
- trIndex++;
103
- if (trIndex > (maxItems*pageNum) || trIndex <= ((maxItems*pageNum)-maxItems)) {
104
- $(this).hide();
105
- }
106
- else{
107
- $(this).show();
108
- }
109
- });
110
-
111
- return false;
112
- }));
113
- }
114
- }
115
-
116
- class Navigation {
117
- static activateTab(a) {
118
- //console.log(a);
119
- //a.click();
120
- let ulNav = a.closest('.nav');
121
- let tabContent = ulNav.parent().find('.tab-content');
122
-
123
- // déselection éventuel des onglets
124
- ulNav.find('a.nav-link').each(function(idx, navLink) {
125
- $(navLink).removeClass('active');
126
- let id = $(navLink).attr('href');
127
- if (id.substr(0, 1) === '#') {
128
- tabContent.find(id).removeClass('active').removeClass('show');
129
- }
130
- });
131
-
132
- // sélection de l'onglet correspondant au navLink passé en paramètre
133
- a.addClass('active');
134
- tabContent.find(a.attr('href')).addClass('active').addClass('show');
135
- }
136
- }
137
-
138
- module.exports = { Pagination, Navigation };
139
-
140
- // deprecated
141
- /*
142
- function paginationAsList(nbResultatsTotal, nbResultatsParPage, urlPage, nomParamPage) {
143
- var currentUrl = urlPage || window.location.href;
144
- var afficherLienFirstLastPage = true;
145
- var afficherLienPagePrecedenteSuivante = true;
146
- var emptyStringIfOnlyOnePage = true;
147
- var nbLiensPageDebutFin = 3;
148
- var nbLiensPageAvantApresPageCourante = 2;
149
- var strEntreLiensPageDebutFinEtAvantApresPageCourante = '…';
150
- nomParamPage = nomParamPage || 'page';
151
-
152
- // Si le nombre de résultat total est inférieur au nombre d'affichage par page, il n'y a qu'une seule page.
153
- if (nbResultatsTotal < nbResultatsParPage && emptyStringIfOnlyOnePage) {
154
- return '';
155
- }
156
-
157
- // Initialisation du nombre de pages
158
- var nbPages = Math.ceil(nbResultatsTotal/nbResultatsParPage);
159
-
160
- // Initialisation du numéro de la page courante
161
- //var query = window.location.search.substring(1).query.split("&");
162
-
163
- var url = new URL(currentUrl);
164
- var params = url.searchParams;
165
-
166
- var numPageCourante = 1;
167
- if (typeof params.get(nomParamPage) != 'undefined' && params.get(nomParamPage) != null) {
168
- numPageCourante = parseInt(params.get(nomParamPage));
169
- }
170
- if (numPageCourante < 0) {
171
- numPageCourante = 1;
172
- }
173
- if (numPageCourante > nbPages) {
174
- numPageCourante = nbPages;
175
- }
176
-
177
- var strPagination = '<ul class="pagination">';
178
-
179
- // Lien pour la première page
180
- if (afficherLienFirstLastPage) {
181
- var strLienFirstPage = '&lt;&lt;';
182
- if (numPageCourante > 1) {
183
- strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, 1, currentUrl)+'">'+strLienFirstPage+'</a></li>';
184
- }
185
- else {
186
- strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienFirstPage+'</a></li>';
187
- }
188
- }
189
-
190
- // Lien pour la page précédente
191
- if (afficherLienPagePrecedenteSuivante) {
192
- var strLienPagePrecedente = '&lt;';
193
- if (numPageCourante > 1) {
194
- strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, (numPageCourante - 1), currentUrl)+'">'+strLienPagePrecedente+'</a></li>';
195
- }
196
- else {
197
- strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienPagePrecedente+'</a></li>';
198
- }
199
- }
200
-
201
- var strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche = false;
202
- var strEntreLiensPageFinEtApresPageCouranteDejaAffiche = false;
203
-
204
- for (var numPage=1; numPage<=nbPages; numPage++) {
205
- if (numPage < numPageCourante) {
206
- if (numPage <= nbLiensPageDebutFin || numPage >= (numPageCourante-nbLiensPageAvantApresPageCourante)) {
207
- strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, numPage, currentUrl)+'">'+numPage+'</a></li>';
208
- }
209
- else {
210
- if (!strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche) {
211
- strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strEntreLiensPageDebutFinEtAvantApresPageCourante+'</a></li>';
212
- strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche = true;
213
- }
214
- }
215
- }
216
- else if (numPage > numPageCourante) {
217
- if (numPage >= (nbPages-(nbLiensPageDebutFin-1)) || numPage <= (numPageCourante+nbLiensPageAvantApresPageCourante)) {
218
- strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, numPage, currentUrl)+'">'+numPage+'</a></li>';
219
- }
220
- else {
221
- if (!strEntreLiensPageFinEtApresPageCouranteDejaAffiche) {
222
- strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strEntreLiensPageDebutFinEtAvantApresPageCourante+'</a></li>';
223
- strEntreLiensPageFinEtApresPageCouranteDejaAffiche = true;
224
- }
225
- }
226
- }
227
- else {
228
- strPagination += '<li class="page-item active"><a class="page-link" href="#">'+numPage+'</a></li>';
229
- }
230
- }
231
-
232
- // Lien pour la page suivante
233
- if (afficherLienPagePrecedenteSuivante) {
234
- var strLienPageSuivante = '&gt;';
235
- if (numPageCourante < nbPages) {
236
- strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, (numPageCourante + 1), currentUrl)+'">'+strLienPageSuivante+'</a></li>';
237
- }
238
- else {
239
- strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienPageSuivante+'</a></li>';
240
- }
241
- }
242
-
243
- // Lien pour la dernière page
244
- if (afficherLienFirstLastPage) {
245
- var strLienLastPage = '&gt;&gt;';
246
- if (numPageCourante < nbPages) {
247
- strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, nbPages, currentUrl)+'">'+strLienLastPage+'</a></li>';
248
- }
249
- else {
250
- strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienLastPage+'</a></li>';
251
- }
252
- }
253
-
254
- strPagination += '</ul>';
255
-
256
- return strPagination;
257
- }
258
- */