@osimatic/helpers-js 1.0.8 → 1.0.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/.idea/helpers-js.iml +8 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README +1 -0
- package/array.js +4 -6
- package/changelog.txt +28 -0
- package/duration.js +32 -28
- package/flash_message.js +1 -2
- package/form_helper.js +20 -0
- package/google_maps.js +1 -1
- package/google_recaptcha.js +78 -0
- package/index.js +29 -19
- package/location.js +249 -251
- package/number.js +69 -7
- package/open_street_map.js +132 -0
- package/package.json +1 -1
- package/paging.js +22 -19
- package/string.js +92 -51
- package/util.js +1 -9
- package/todos/google_recaptcha.js +0 -15
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://leafletjs.com/
|
|
3
|
+
* https://switch2osm.org/the-basics/
|
|
4
|
+
* https://www.openstreetmap.org/help
|
|
5
|
+
*/
|
|
6
|
+
class OpenStreetMap {
|
|
7
|
+
|
|
8
|
+
constructor(mapId, options) {
|
|
9
|
+
/*let [lat, lng] = button.data('coordinates').split(',');
|
|
10
|
+
let map = L.map('modal_map_canvas2').setView([lat, lng], 17);
|
|
11
|
+
|
|
12
|
+
L.marker([lat, lng], {
|
|
13
|
+
icon: L.icon({iconUrl: getIconOfMapMarker(button.data('type_marker'))}),
|
|
14
|
+
title: popoverContent.title
|
|
15
|
+
//popupopen: setTimeout(displayEmployeesAndCompaniesAndTasks, 250)
|
|
16
|
+
}).addTo(map)
|
|
17
|
+
.bindPopup(popoverContent.content)
|
|
18
|
+
//.openPopup()
|
|
19
|
+
;*/
|
|
20
|
+
|
|
21
|
+
this.markers = [];
|
|
22
|
+
this.locations = [];
|
|
23
|
+
this.mapId = mapId;
|
|
24
|
+
|
|
25
|
+
if (!$('#'+mapId).length) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.map = L.map(mapId, options || {});
|
|
30
|
+
|
|
31
|
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
32
|
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
33
|
+
}).addTo(this.map);
|
|
34
|
+
|
|
35
|
+
this.centerOnFrance();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static getUrl(latitude, longitude) {
|
|
39
|
+
return 'https://www.openstreetmap.org/?mlat='+latitude+'&mlon='+longitude+'#map=17/'+latitude+'/'+longitude+'&layers=N';
|
|
40
|
+
//return 'https://www.openstreetmap.org/#map=17/'+latitude+'/'+longitude+'';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getUrlFromCoordinates(locationCoordinates) {
|
|
44
|
+
locationCoordinates = locationCoordinates.split(',');
|
|
45
|
+
return this.getUrl(parseFloat(locationCoordinates[0]), parseFloat(locationCoordinates[1]));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setZoom(zoom) {
|
|
49
|
+
this.map.setZoom(zoom);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
deleteMarkers() {
|
|
53
|
+
this.locations = [];
|
|
54
|
+
|
|
55
|
+
//this.markers.forEach(marker => marker.setMap(null));
|
|
56
|
+
|
|
57
|
+
this.markers.length = 0;
|
|
58
|
+
this.markers = [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
addMarkers(listLocations, icon) {
|
|
62
|
+
if (listLocations.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
listLocations.forEach(location => this.addMarker(location, icon));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
addMarker(coordinates, options) {
|
|
70
|
+
let locationCoordinates = coordinates.split(',');
|
|
71
|
+
let latitude = parseFloat(locationCoordinates[0]);
|
|
72
|
+
let longitude = parseFloat(locationCoordinates[1]);
|
|
73
|
+
|
|
74
|
+
let marker = L.marker([latitude, longitude], {
|
|
75
|
+
icon: L.icon({
|
|
76
|
+
iconUrl: options['icon'],
|
|
77
|
+
iconSize: [22, 32],
|
|
78
|
+
}),
|
|
79
|
+
title: options['title'],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
//marker.on('click', () => {
|
|
83
|
+
marker.on('popupopen', () => {
|
|
84
|
+
console.log('popupopen');
|
|
85
|
+
if (typeof options['on_click'] == 'function') {
|
|
86
|
+
options['on_click']();
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
});
|
|
90
|
+
marker.addTo(this.map);
|
|
91
|
+
marker.bindPopup(options['popup_content']);
|
|
92
|
+
|
|
93
|
+
this.markers.push(marker);
|
|
94
|
+
this.locations.push([latitude, longitude]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
centerOnFrance() {
|
|
98
|
+
this.map.setView([46.52863469527167, 2.43896484375], 6);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
centerOnMarkers() {
|
|
102
|
+
this.map.invalidateSize(false);
|
|
103
|
+
|
|
104
|
+
if (this.locations.length === 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.map.fitBounds(new L.LatLngBounds(this.locations));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
connectMarkers() {
|
|
112
|
+
if (this.locations.length === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let prevLocation = null;
|
|
117
|
+
let listLineCoordinates = [];
|
|
118
|
+
this.locations.forEach(location => {
|
|
119
|
+
if (prevLocation != null) {
|
|
120
|
+
listLineCoordinates.push([prevLocation, location]);
|
|
121
|
+
}
|
|
122
|
+
prevLocation = location;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
listLineCoordinates.forEach(line => {
|
|
126
|
+
L.polyline(line, {color: '#728bec'}).addTo(this.map);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { OpenStreetMap };
|
package/package.json
CHANGED
package/paging.js
CHANGED
|
@@ -95,32 +95,34 @@ class Pagination {
|
|
|
95
95
|
|
|
96
96
|
update();
|
|
97
97
|
}
|
|
98
|
-
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
class Navigation {
|
|
101
|
+
static activateTab(a) {
|
|
102
|
+
//console.log(a);
|
|
103
|
+
//a.click();
|
|
104
|
+
let ulNav = a.closest('.nav');
|
|
105
|
+
let tabContent = ulNav.parent().find('.tab-content');
|
|
106
|
+
|
|
107
|
+
// déselection éventuel des onglets
|
|
108
|
+
ulNav.find('a.nav-link').each(function(idx, navLink) {
|
|
109
|
+
$(navLink).removeClass('active');
|
|
110
|
+
let id = $(navLink).attr('href');
|
|
111
|
+
if (id.substr(0, 1) === '#') {
|
|
112
|
+
tabContent.find(id).removeClass('active').removeClass('show');
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
// sélection de l'onglet correspondant au navLink passé en paramètre
|
|
117
|
+
a.addClass('active');
|
|
118
|
+
tabContent.find(a.attr('href')).addClass('active').addClass('show');
|
|
119
|
+
}
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
module.exports = { Pagination,
|
|
122
|
+
module.exports = { Pagination, Navigation };
|
|
122
123
|
|
|
123
124
|
// deprecated
|
|
125
|
+
/*
|
|
124
126
|
function paginationAsList(nbResultatsTotal, nbResultatsParPage, urlPage, nomParamPage) {
|
|
125
127
|
var currentUrl = urlPage || window.location.href;
|
|
126
128
|
var afficherLienFirstLastPage = true;
|
|
@@ -237,3 +239,4 @@ function paginationAsList(nbResultatsTotal, nbResultatsParPage, urlPage, nomPara
|
|
|
237
239
|
|
|
238
240
|
return strPagination;
|
|
239
241
|
}
|
|
242
|
+
*/
|
package/string.js
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
|
-
function selectionnerContenuNode(node) {
|
|
2
|
-
if (window.getSelection) {
|
|
3
|
-
var selection = window.getSelection();
|
|
4
|
-
var intervalle = document.createRange();
|
|
5
|
-
intervalle.selectNodeContents(node);
|
|
6
|
-
selection.removeAllRanges();
|
|
7
|
-
selection.addRange(intervalle);
|
|
8
|
-
}
|
|
9
|
-
else if (document.body.createTextRange) {
|
|
10
|
-
var intervalle = document.body.createTextRange();
|
|
11
|
-
intervalle.moveToElementText(node);
|
|
12
|
-
intervalle.select();
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
1
|
|
|
17
|
-
function
|
|
2
|
+
String.prototype.copyToClipboard = String.prototype.copyToClipboard || function() {
|
|
18
3
|
if (window.clipboardData && clipboardData.setData) {
|
|
19
|
-
window.clipboardData.setData('Text',
|
|
4
|
+
window.clipboardData.setData('Text', this);
|
|
20
5
|
}
|
|
21
6
|
else if (document.body.createTextRange) {
|
|
22
7
|
var textRange = document.body.createTextRange();
|
|
23
|
-
textRange.moveToElementText(
|
|
8
|
+
textRange.moveToElementText(this);
|
|
24
9
|
textRange.execCommand("Copy");
|
|
25
10
|
}
|
|
26
11
|
else {
|
|
27
12
|
try {
|
|
28
13
|
// On test si la configuration permet l'accès au presse-papier.
|
|
29
14
|
netscape.security.PrivilegeManager
|
|
30
|
-
|
|
15
|
+
.enablePrivilege("UniversalXPConnect");
|
|
31
16
|
}
|
|
32
17
|
catch (e) {
|
|
33
18
|
alert("Impossible d'accéder au presse-papier.");
|
|
@@ -35,79 +20,119 @@ function copierTexte(texte) {
|
|
|
35
20
|
// Initialisation du composant fournit par Mozilla.
|
|
36
21
|
var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
|
|
37
22
|
// Copie du texte dans le presse papier.
|
|
38
|
-
gClipboardHelper.copyString(
|
|
23
|
+
gClipboardHelper.copyString(this);
|
|
39
24
|
}
|
|
40
25
|
return false;
|
|
41
26
|
}
|
|
42
27
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
"&": "&",
|
|
46
|
-
"<": "<",
|
|
47
|
-
">": ">",
|
|
48
|
-
'"': '"',
|
|
49
|
-
"'": ''',
|
|
50
|
-
"/": '/'
|
|
51
|
-
};
|
|
52
|
-
return String(string).replace(/[&<>"'\/]/g, (s) => entityMap[s]);
|
|
28
|
+
String.prototype.reverseString = String.prototype.reverseString || function() {
|
|
29
|
+
return this.split('').reverse().join('');
|
|
53
30
|
}
|
|
54
31
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
String.prototype.truncateOnWord = String.prototype.truncateOnWord || function(limit, fromLeft) {
|
|
33
|
+
if (fromLeft) {
|
|
34
|
+
return this.reverseString(this.truncateOnWord(this.reverseString(), limit));
|
|
35
|
+
}
|
|
36
|
+
var TRIM_CHARS = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u2028\u2029\u3000\uFEFF';
|
|
37
|
+
var words = this.split(RegExp('(?=['+TRIM_CHARS+'])'));
|
|
38
|
+
var count = 0;
|
|
39
|
+
|
|
40
|
+
function filter(arr, fn) {
|
|
41
|
+
var result = [];
|
|
42
|
+
for (var i = 0, len = arr.length; i < len; i++) {
|
|
43
|
+
var el = arr[i];
|
|
44
|
+
if (i in arr && fn(el, i)) {
|
|
45
|
+
result.push(el);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return filter(words, function(word) {
|
|
52
|
+
count += word.length;
|
|
53
|
+
return count <= limit;
|
|
54
|
+
}).join('');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
String.prototype.truncateString = String.prototype.truncateString || function(length, from, ellipsis, split) {
|
|
58
|
+
let str1, str2, len1, len2;
|
|
59
|
+
if (this.length <= length) {
|
|
60
|
+
return this.toString();
|
|
59
61
|
}
|
|
60
62
|
ellipsis = typeof ellipsis === 'undefined' ? '…' : ellipsis;
|
|
61
63
|
switch(from) {
|
|
62
64
|
case 'left':
|
|
63
|
-
str2 = split ? truncateOnWord(
|
|
65
|
+
str2 = split ? this.truncateOnWord(length, true) : this.slice(this.length - length);
|
|
64
66
|
return ellipsis + str2;
|
|
65
67
|
case 'middle':
|
|
66
|
-
len1 = ceil(length / 2);
|
|
67
|
-
len2 = floor(length / 2);
|
|
68
|
-
str1 = split ? truncateOnWord(
|
|
69
|
-
str2 = split ? truncateOnWord(
|
|
68
|
+
len1 = Math.ceil(length / 2);
|
|
69
|
+
len2 = Math.floor(length / 2);
|
|
70
|
+
str1 = split ? this.truncateOnWord(len1) : this.slice(0, len1);
|
|
71
|
+
str2 = split ? this.truncateOnWord(len2, true) : this.slice(this.length - len2);
|
|
70
72
|
return str1 + ellipsis + str2;
|
|
71
73
|
default:
|
|
72
|
-
str1 = split ? truncateOnWord(
|
|
74
|
+
str1 = split ? this.truncateOnWord(length) : this.slice(0, length);
|
|
73
75
|
return str1 + ellipsis;
|
|
74
76
|
}
|
|
75
|
-
}
|
|
76
|
-
function truncateOnWord(str, length, from, ellipsis) {
|
|
77
|
-
return truncateString(str, length, from, ellipsis, true);
|
|
78
|
-
}
|
|
77
|
+
};
|
|
79
78
|
|
|
80
79
|
String.prototype.htmlentities = String.prototype.htmlentities || function() {
|
|
81
80
|
return this.replace(/[\u00A0-\u9999<>\&]/gim, (i) => '&#'+i.charCodeAt(0)+';');
|
|
82
81
|
};
|
|
83
82
|
|
|
84
83
|
String.prototype.escapeHtml = String.prototype.escapeHtml || function() {
|
|
85
|
-
|
|
84
|
+
let entityMap = {
|
|
85
|
+
"&": "&",
|
|
86
|
+
"<": "<",
|
|
87
|
+
">": ">",
|
|
88
|
+
'"': '"',
|
|
89
|
+
"'": ''',
|
|
90
|
+
"/": '/'
|
|
91
|
+
};
|
|
92
|
+
return this.replace(/[&<>"'\/]/g, (s) => entityMap[s]);
|
|
86
93
|
};
|
|
87
94
|
|
|
88
95
|
String.prototype.normalizeBreaks = String.prototype.normalizeBreaks || function(breaktype) {
|
|
89
|
-
|
|
96
|
+
// 20/01/2022 : modifié car ne fonctionnait pas pour les string en provenance de textarea, enregistrée en bd puis réaffiché depuis bd
|
|
97
|
+
//return this.replace(/$/mg, breaktype).replace(new RegExp('/'+breaktype.escapeRegExp()+'$/'), '');
|
|
98
|
+
return this.replace(/(?:\r\n|\r|\n)/g, breaktype);
|
|
99
|
+
//return this.replace('/(\r\n|\r|\n)/ms', breaktype);
|
|
90
100
|
//return this.replace('/(?:\r\n|\r|\n)/g', breaktype);
|
|
91
101
|
//console.log(breaktype);
|
|
92
102
|
//return this.replace(new RegExp('\r?\n','g'), breaktype);
|
|
93
103
|
};
|
|
94
|
-
|
|
104
|
+
String.prototype.escapeRegExp = String.prototype.escapeRegExp || function() {
|
|
105
|
+
return this.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
106
|
+
};
|
|
95
107
|
String.prototype.format = String.prototype.format || function() {
|
|
96
108
|
var args = arguments;
|
|
97
109
|
return this.replace(/{(\d+)}/g, (match, number) => (typeof args[number] != 'undefined' ? args[number] : match));
|
|
98
110
|
};
|
|
99
111
|
|
|
100
|
-
String.prototype.ucwords = function() {
|
|
112
|
+
String.prototype.ucwords = String.prototype.ucwords || function() {
|
|
101
113
|
return this.toLowerCase().replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g, ($1) => $1.toUpperCase());
|
|
102
114
|
};
|
|
103
|
-
String.prototype.capitalize = function() {
|
|
115
|
+
String.prototype.capitalize = String.prototype.capitalize || function() {
|
|
104
116
|
return this.charAt(0).toUpperCase() + this.slice(1);
|
|
105
117
|
}
|
|
106
118
|
|
|
107
|
-
String.prototype.encodeForHtmlDataAttribute = function() {
|
|
119
|
+
String.prototype.encodeForHtmlDataAttribute = String.prototype.encodeForHtmlDataAttribute || function() {
|
|
108
120
|
return this.replace(/\"/g, "'");
|
|
109
121
|
}
|
|
110
122
|
|
|
123
|
+
String.prototype.isNumeric = String.prototype.isNumeric || function() {
|
|
124
|
+
let ValidChars = "0123456789.";
|
|
125
|
+
let IsNumber = true;
|
|
126
|
+
let Char;
|
|
127
|
+
for (let i = 0; i < this.length && IsNumber === true; i++){
|
|
128
|
+
Char = this.charAt(i);
|
|
129
|
+
if (ValidChars.indexOf(Char) === -1) {
|
|
130
|
+
IsNumber = false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return IsNumber;
|
|
134
|
+
}
|
|
135
|
+
|
|
111
136
|
// s'utilise : "ma chaine {0} de caracteres"
|
|
112
137
|
if (!String.format) {
|
|
113
138
|
String.format = function(format) {
|
|
@@ -116,4 +141,20 @@ if (!String.format) {
|
|
|
116
141
|
};
|
|
117
142
|
}
|
|
118
143
|
|
|
119
|
-
|
|
144
|
+
/*
|
|
145
|
+
function selectionnerContenuNode(node) {
|
|
146
|
+
if (window.getSelection) {
|
|
147
|
+
var selection = window.getSelection();
|
|
148
|
+
var intervalle = document.createRange();
|
|
149
|
+
intervalle.selectNodeContents(node);
|
|
150
|
+
selection.removeAllRanges();
|
|
151
|
+
selection.addRange(intervalle);
|
|
152
|
+
}
|
|
153
|
+
else if (document.body.createTextRange) {
|
|
154
|
+
var intervalle = document.body.createTextRange();
|
|
155
|
+
intervalle.moveToElementText(node);
|
|
156
|
+
intervalle.select();
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
*/
|
package/util.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
function addBookmark(anchor) {
|
|
2
|
-
if (navigator.appName != 'Microsoft Internet Explorer') {
|
|
3
|
-
window.sidebar.addPanel(anchor.get('title'), anchor.get('href'),"");
|
|
4
|
-
}
|
|
5
|
-
else {
|
|
6
|
-
window.external.AddFavorite(anchor.get('href'), anchor.get('title'));
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
1
|
|
|
10
2
|
function sleep(milliseconds) {
|
|
11
3
|
var start = new Date().getTime();
|
|
@@ -22,4 +14,4 @@ function refresh() {
|
|
|
22
14
|
window.location.reload(true);
|
|
23
15
|
}
|
|
24
16
|
|
|
25
|
-
module.exports = {
|
|
17
|
+
module.exports = { sleep, refresh };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var grecaptchaWidgets = [];
|
|
3
|
-
|
|
4
|
-
function grecaptchaOnload () {
|
|
5
|
-
if (typeof grecaptcha == 'undefined') {
|
|
6
|
-
console.log('var grecaptcha undefined');
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
document.querySelectorAll('.grecaptcha').forEach(element => {
|
|
10
|
-
grecaptchaWidgets[element.id] = grecaptcha.render(element.id, googleReCaptchaDatas);
|
|
11
|
-
});
|
|
12
|
-
//$('.grecaptcha').each(function(idx, el) {
|
|
13
|
-
// grecaptchaWidgets[$(el).attr('id')] = grecaptcha.render($(el).attr('id'), googleReCaptchaDatas);
|
|
14
|
-
//});
|
|
15
|
-
}
|