@osimatic/helpers-js 1.1.8 → 1.1.10

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.
@@ -102,14 +102,16 @@ class OpenStreetMap {
102
102
  this.map.setView([46.52863469527167, 2.43896484375], 6);
103
103
  }
104
104
 
105
- centerOnMarkers() {
105
+ centerOnMarkers(padding) {
106
106
  this.map.invalidateSize(false);
107
107
 
108
108
  if (this.locations.length === 0) {
109
109
  return;
110
110
  }
111
111
 
112
- 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
+ });
113
115
  }
114
116
 
115
117
  connectMarkers() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/paging.js CHANGED
@@ -2,15 +2,15 @@
2
2
  //Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
3
3
 
4
4
  class Pagination {
5
- static paginateCards(div, nbItemsPerPage) {
6
- Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage);
5
+ static paginateCards(div, nbItemsPerPage, doublePagination) {
6
+ Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage, undefined, doublePagination);
7
7
  }
8
8
 
9
- static paginateTable(table, select) {
10
- Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select);
9
+ static paginateTable(table, select, doublePagination) {
10
+ Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select, doublePagination);
11
11
  }
12
12
 
13
- static paginate(div, items, nbItemsPerPage, select) {
13
+ static paginate(div, items, nbItemsPerPage, select, doublePagination) {
14
14
  let maxItems = nbItemsPerPage;
15
15
 
16
16
  if (typeof div == 'undefined' || !div.length) {
@@ -35,65 +35,83 @@ class Pagination {
35
35
  select.change(update);
36
36
  }
37
37
 
38
- let paginationUl = $('ul.pagination');
39
- if (!paginationUl.length) {
40
- paginationUl = $('<ul class="pagination"></ul>');
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
+ }
46
+
47
+ Pagination.initPaginationItems(items, maxItems, doublePagination);
48
+ }
49
+
50
+ static initPaginationDiv(div, ulDiv, onTop, doublePagination) {
51
+ if (!ulDiv.length || doublePagination) {
52
+ ulDiv = $('<ul class="pagination"></ul>');
41
53
  if (div.find('.pagination_links').length) {
42
- div.find('.pagination_links').append(paginationUl);
43
- }
44
- else {
45
- div.after(paginationUl);
54
+ (onTop ? div.find('.pagination_links').prepend(ulDiv) : div.find('.pagination_links').append(ulDiv))
55
+ } else {
56
+ (onTop ? div.before(ulDiv) : div.after(ulDiv));
46
57
  }
47
58
  }
59
+ }
48
60
 
49
- function update() {
50
- let totalItems = items.length;
61
+ static initPaginationItems(items, maxItems, doublePagination) {
62
+ const paginationUl = $('ul.pagination');
51
63
 
52
- let lineNum = 0;
53
- items.each(function () {
54
- lineNum++;
55
- if (0 === maxItems || lineNum <= maxItems) {
56
- $(this).show();
57
- }
58
- else {
59
- $(this).hide();
60
- }
61
- });
62
- paginationUl.find('li').remove();
64
+ let totalItems = items.length;
63
65
 
64
- if (0 === maxItems || totalItems < maxItems) {
65
- paginationUl.addClass('hide');
66
- return;
66
+ let lineNum = 0;
67
+ items.each(function () {
68
+ lineNum++;
69
+ if (0 === maxItems || lineNum <= maxItems) {
70
+ $(this).show();
67
71
  }
68
-
69
- let nbPages = Math.ceil(totalItems/maxItems);
70
- for (let i=1; i <= nbPages; i++) {
71
- paginationUl.append('<li class="page-item" data-page="'+i+'"><a href="#" class="page-link">'+i+'<span class="sr-only">(current)</span></a></li>').show();
72
+ else {
73
+ $(this).hide();
72
74
  }
73
- paginationUl.removeClass('hide');
75
+ });
74
76
 
75
- paginationUl.find('li:first-child').addClass('active');
76
- paginationUl.find('li').click(function () {
77
- paginationUl.find('li').removeClass('active');
77
+ paginationUl.each((index, ul) => $(ul).find('li').remove());
78
78
 
79
- let pageNum = $(this).data('page');
80
- let trIndex = 0;
79
+ if (0 === maxItems || totalItems < maxItems) {
80
+ paginationUl.each((index, ul) => $(ul).addClass('hide'));
81
+ return;
82
+ }
83
+
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());
87
+ }
88
+
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 {
81
100
  $(this).addClass('active');
82
- items.each(function () {
83
- trIndex++;
84
- if (trIndex > (maxItems*pageNum) || trIndex <= ((maxItems*pageNum)-maxItems)) {
85
- $(this).hide();
86
- }
87
- else{
88
- $(this).show();
89
- }
90
- });
101
+ }
91
102
 
92
- return false;
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
+ }
93
111
  });
94
- }
95
112
 
96
- update();
113
+ return false;
114
+ }));
97
115
  }
98
116
  }
99
117