@osimatic/helpers-js 1.1.77 → 1.1.78
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/CHANGELOG +76 -76
- package/array.js +93 -90
- package/bank.js +20 -20
- package/contact_details.js +194 -194
- package/count_down.js +102 -102
- package/data_table.js +416 -416
- package/date_time.js +592 -592
- package/details_sub_array.js +123 -123
- package/draw.js +52 -52
- package/duration.js +198 -198
- package/event_bus.js +38 -38
- package/file.js +146 -146
- package/flash_message.js +35 -35
- package/form_date.js +610 -610
- package/form_helper.js +410 -410
- package/google_charts.js +347 -347
- package/google_maps.js +169 -169
- package/google_recaptcha.js +87 -87
- package/http_client.js +469 -469
- package/import_from_csv.js +273 -273
- package/index.js +55 -55
- package/jwt.js +288 -288
- package/list_box.js +112 -112
- package/location.js +431 -431
- package/media.js +218 -218
- package/multiple_action_in_table.js +336 -336
- package/network.js +756 -756
- package/number.js +99 -99
- package/open_street_map.js +142 -142
- package/package.json +15 -15
- package/paging.js +278 -278
- package/php.min.js +5 -5
- package/revolut.js +22 -22
- package/select_all.js +121 -121
- package/shopping_cart.js +31 -31
- package/social_network.js +109 -109
- package/sortable_list.js +37 -37
- package/string.js +162 -162
- package/util.js +16 -16
- package/visitor.js +77 -77
- package/web_rtc.js +114 -114
- package/web_socket.js +97 -97
package/file.js
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
class File {
|
|
3
|
-
static download(data, contentType, contentDisposition) {
|
|
4
|
-
let filename = "";
|
|
5
|
-
let disposition = contentDisposition;
|
|
6
|
-
if (disposition && (disposition.indexOf('inline') !== -1 || disposition.indexOf('attachment') !== -1)) {
|
|
7
|
-
let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
8
|
-
let matches = filenameRegex.exec(disposition);
|
|
9
|
-
if (matches != null && matches[1]) {
|
|
10
|
-
filename = matches[1].replace(/['"]/g, '');
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let blob = new Blob([data], {
|
|
15
|
-
type: contentType
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
//console.log('disposition: '+disposition+' ; filename: '+filename+' ; type: '+type);
|
|
19
|
-
//console.log('blob: %o', blob);
|
|
20
|
-
|
|
21
|
-
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
22
|
-
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
|
|
23
|
-
window.navigator.msSaveBlob(blob, filename);
|
|
24
|
-
} else {
|
|
25
|
-
let URL = window.URL || window.webkitURL;
|
|
26
|
-
let downloadUrl = URL.createObjectURL(blob);
|
|
27
|
-
|
|
28
|
-
let a = document.createElement("a");
|
|
29
|
-
// safari doesn't support this yet
|
|
30
|
-
if (typeof a.download === 'undefined') {
|
|
31
|
-
window.location = downloadUrl;
|
|
32
|
-
} else {
|
|
33
|
-
a.href = downloadUrl;
|
|
34
|
-
a.download = (filename?filename:'file.pdf');
|
|
35
|
-
document.body.appendChild(a);
|
|
36
|
-
a.click();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setTimeout(function () {
|
|
40
|
-
URL.revokeObjectURL(downloadUrl);
|
|
41
|
-
}, 100); // cleanup
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static formatFileSize(fileSizeInBytes, fractionDigits=2, locale='fr-FR') {
|
|
46
|
-
let i = -1;
|
|
47
|
-
let byteUnits = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
48
|
-
if (fileSizeInBytes === 0) {
|
|
49
|
-
return '0 ' + byteUnits[0];
|
|
50
|
-
}
|
|
51
|
-
do {
|
|
52
|
-
fileSizeInBytes = fileSizeInBytes / 1024;
|
|
53
|
-
i++;
|
|
54
|
-
}
|
|
55
|
-
while (fileSizeInBytes > 1024);
|
|
56
|
-
//var size = Math.max(fileSizeInBytes, 0.1).toFixed(fractionDigits);
|
|
57
|
-
let size = Math.max(fileSizeInBytes, 0.1);
|
|
58
|
-
return (new Intl.NumberFormat(locale, {
|
|
59
|
-
maximumFractionDigits: fractionDigits
|
|
60
|
-
}).format(size)) + ' ' + byteUnits[i];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
static blobToBase64(blob, callback) {
|
|
64
|
-
let reader = new FileReader();
|
|
65
|
-
reader.onload = function() {
|
|
66
|
-
//let dataUrl = reader.result;
|
|
67
|
-
//let base64 = dataUrl.split(',')[1];
|
|
68
|
-
callback(reader.result);
|
|
69
|
-
};
|
|
70
|
-
reader.readAsDataURL(blob);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const CSV_FILE_EXTENSION = "csv";
|
|
75
|
-
const CSV_MIME_TYPES = [
|
|
76
|
-
'text/csv',
|
|
77
|
-
'txt/csv',
|
|
78
|
-
'application/octet-stream',
|
|
79
|
-
'application/csv-tab-delimited-table',
|
|
80
|
-
'application/vnd.ms-excel',
|
|
81
|
-
'application/vnd.ms-pki.seccat',
|
|
82
|
-
'text/plain',
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
class CSV {
|
|
86
|
-
static checkFile(filename, fileType) {
|
|
87
|
-
return CSV_MIME_TYPES.indexOf(fileType) !== -1 && filename.split('.').pop().toLowerCase() === CSV_FILE_EXTENSION;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
class Img {
|
|
93
|
-
static compress(oData) {
|
|
94
|
-
let a = [];
|
|
95
|
-
let len = oData.length;
|
|
96
|
-
let p = -1;
|
|
97
|
-
for (let i=0;i<len;i+=4) {
|
|
98
|
-
if (oData[i] > 0)
|
|
99
|
-
a[++p] = String.fromCharCode(oData[i]);
|
|
100
|
-
}
|
|
101
|
-
return a.join("");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
static initImg(div) {
|
|
105
|
-
div.find('.asynchronously_img').each(function(idx, img) {
|
|
106
|
-
Img.loadImgUrl($(img).data('url'), $(img));
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static loadImgUrl(url, img) {
|
|
111
|
-
$.ajax({
|
|
112
|
-
type: 'GET',
|
|
113
|
-
url: url,
|
|
114
|
-
headers: HTTPClient.getHeaders(true),
|
|
115
|
-
cache: false,
|
|
116
|
-
xhrFields: {responseType: 'blob'},
|
|
117
|
-
success: (data) => {
|
|
118
|
-
// var urlCreator = window.URL || window.webkitURL;
|
|
119
|
-
// $(img).attr('src', urlCreator.createObjectURL(data));
|
|
120
|
-
Img.setBlobToImg($(img), data);
|
|
121
|
-
},
|
|
122
|
-
error: (jqxhr, status, errorThrown) => HTTPClient.logJqueryRequestFailure(jqxhr, status, errorThrown),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
static setBlobToImg(img, blob) {
|
|
127
|
-
// img.attr('src', btoa(unescape(encodeURIComponent(data))));
|
|
128
|
-
// img.attr('src', 'data:image/png;base64, '+btoa(unescape(encodeURIComponent(data))));
|
|
129
|
-
let urlCreator = window.URL || window.webkitURL;
|
|
130
|
-
img.attr('src', urlCreator.createObjectURL(blob));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
static async getBase64FromUrl(url) {
|
|
134
|
-
const data = await fetch(url);
|
|
135
|
-
const blob = await data.blob();
|
|
136
|
-
return new Promise((resolve) => {
|
|
137
|
-
const reader = new FileReader();
|
|
138
|
-
reader.readAsDataURL(blob);
|
|
139
|
-
reader.onloadend = () => {
|
|
140
|
-
const base64data = reader.result;
|
|
141
|
-
resolve(base64data);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
1
|
+
|
|
2
|
+
class File {
|
|
3
|
+
static download(data, contentType, contentDisposition) {
|
|
4
|
+
let filename = "";
|
|
5
|
+
let disposition = contentDisposition;
|
|
6
|
+
if (disposition && (disposition.indexOf('inline') !== -1 || disposition.indexOf('attachment') !== -1)) {
|
|
7
|
+
let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
8
|
+
let matches = filenameRegex.exec(disposition);
|
|
9
|
+
if (matches != null && matches[1]) {
|
|
10
|
+
filename = matches[1].replace(/['"]/g, '');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let blob = new Blob([data], {
|
|
15
|
+
type: contentType
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//console.log('disposition: '+disposition+' ; filename: '+filename+' ; type: '+type);
|
|
19
|
+
//console.log('blob: %o', blob);
|
|
20
|
+
|
|
21
|
+
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
22
|
+
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
|
|
23
|
+
window.navigator.msSaveBlob(blob, filename);
|
|
24
|
+
} else {
|
|
25
|
+
let URL = window.URL || window.webkitURL;
|
|
26
|
+
let downloadUrl = URL.createObjectURL(blob);
|
|
27
|
+
|
|
28
|
+
let a = document.createElement("a");
|
|
29
|
+
// safari doesn't support this yet
|
|
30
|
+
if (typeof a.download === 'undefined') {
|
|
31
|
+
window.location = downloadUrl;
|
|
32
|
+
} else {
|
|
33
|
+
a.href = downloadUrl;
|
|
34
|
+
a.download = (filename?filename:'file.pdf');
|
|
35
|
+
document.body.appendChild(a);
|
|
36
|
+
a.click();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setTimeout(function () {
|
|
40
|
+
URL.revokeObjectURL(downloadUrl);
|
|
41
|
+
}, 100); // cleanup
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static formatFileSize(fileSizeInBytes, fractionDigits=2, locale='fr-FR') {
|
|
46
|
+
let i = -1;
|
|
47
|
+
let byteUnits = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
48
|
+
if (fileSizeInBytes === 0) {
|
|
49
|
+
return '0 ' + byteUnits[0];
|
|
50
|
+
}
|
|
51
|
+
do {
|
|
52
|
+
fileSizeInBytes = fileSizeInBytes / 1024;
|
|
53
|
+
i++;
|
|
54
|
+
}
|
|
55
|
+
while (fileSizeInBytes > 1024);
|
|
56
|
+
//var size = Math.max(fileSizeInBytes, 0.1).toFixed(fractionDigits);
|
|
57
|
+
let size = Math.max(fileSizeInBytes, 0.1);
|
|
58
|
+
return (new Intl.NumberFormat(locale, {
|
|
59
|
+
maximumFractionDigits: fractionDigits
|
|
60
|
+
}).format(size)) + ' ' + byteUnits[i];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static blobToBase64(blob, callback) {
|
|
64
|
+
let reader = new FileReader();
|
|
65
|
+
reader.onload = function() {
|
|
66
|
+
//let dataUrl = reader.result;
|
|
67
|
+
//let base64 = dataUrl.split(',')[1];
|
|
68
|
+
callback(reader.result);
|
|
69
|
+
};
|
|
70
|
+
reader.readAsDataURL(blob);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const CSV_FILE_EXTENSION = "csv";
|
|
75
|
+
const CSV_MIME_TYPES = [
|
|
76
|
+
'text/csv',
|
|
77
|
+
'txt/csv',
|
|
78
|
+
'application/octet-stream',
|
|
79
|
+
'application/csv-tab-delimited-table',
|
|
80
|
+
'application/vnd.ms-excel',
|
|
81
|
+
'application/vnd.ms-pki.seccat',
|
|
82
|
+
'text/plain',
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
class CSV {
|
|
86
|
+
static checkFile(filename, fileType) {
|
|
87
|
+
return CSV_MIME_TYPES.indexOf(fileType) !== -1 && filename.split('.').pop().toLowerCase() === CSV_FILE_EXTENSION;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
class Img {
|
|
93
|
+
static compress(oData) {
|
|
94
|
+
let a = [];
|
|
95
|
+
let len = oData.length;
|
|
96
|
+
let p = -1;
|
|
97
|
+
for (let i=0;i<len;i+=4) {
|
|
98
|
+
if (oData[i] > 0)
|
|
99
|
+
a[++p] = String.fromCharCode(oData[i]);
|
|
100
|
+
}
|
|
101
|
+
return a.join("");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static initImg(div) {
|
|
105
|
+
div.find('.asynchronously_img').each(function(idx, img) {
|
|
106
|
+
Img.loadImgUrl($(img).data('url'), $(img));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static loadImgUrl(url, img) {
|
|
111
|
+
$.ajax({
|
|
112
|
+
type: 'GET',
|
|
113
|
+
url: url,
|
|
114
|
+
headers: HTTPClient.getHeaders(true),
|
|
115
|
+
cache: false,
|
|
116
|
+
xhrFields: {responseType: 'blob'},
|
|
117
|
+
success: (data) => {
|
|
118
|
+
// var urlCreator = window.URL || window.webkitURL;
|
|
119
|
+
// $(img).attr('src', urlCreator.createObjectURL(data));
|
|
120
|
+
Img.setBlobToImg($(img), data);
|
|
121
|
+
},
|
|
122
|
+
error: (jqxhr, status, errorThrown) => HTTPClient.logJqueryRequestFailure(jqxhr, status, errorThrown),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static setBlobToImg(img, blob) {
|
|
127
|
+
// img.attr('src', btoa(unescape(encodeURIComponent(data))));
|
|
128
|
+
// img.attr('src', 'data:image/png;base64, '+btoa(unescape(encodeURIComponent(data))));
|
|
129
|
+
let urlCreator = window.URL || window.webkitURL;
|
|
130
|
+
img.attr('src', urlCreator.createObjectURL(blob));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static async getBase64FromUrl(url) {
|
|
134
|
+
const data = await fetch(url);
|
|
135
|
+
const blob = await data.blob();
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
const reader = new FileReader();
|
|
138
|
+
reader.readAsDataURL(blob);
|
|
139
|
+
reader.onloadend = () => {
|
|
140
|
+
const base64data = reader.result;
|
|
141
|
+
resolve(base64data);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
147
|
module.exports = { File, CSV, Img };
|
package/flash_message.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
class FlashMessage {
|
|
2
|
-
static displaySuccess(message, reload=false, modal=null, onMessageHidden=null, domId=null) {
|
|
3
|
-
this.display('success', message, reload, modal, onMessageHidden, domId);
|
|
4
|
-
}
|
|
5
|
-
static displayWarning(message, modal=null, onMessageHidden=null, domId=null) {
|
|
6
|
-
this.display('warning', message, false, modal, onMessageHidden, domId);
|
|
7
|
-
}
|
|
8
|
-
static displayError(message, modal=null, onMessageHidden=null, domId=null) {
|
|
9
|
-
this.display('danger', message, false, modal, onMessageHidden, domId);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static display(type, message, reload=false, modal=null, onMessageHidden=null, domId=null) {
|
|
13
|
-
if (null !== modal) {
|
|
14
|
-
modal.modal('hide');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
$('div.snackbar').remove();
|
|
18
|
-
let snackbar = $('<div class="snackbar '+type+'" '+(null !== domId ? 'id="'+domId+'"' : '')+'></div>');
|
|
19
|
-
$('html body').append(snackbar);
|
|
20
|
-
snackbar.html(message);
|
|
21
|
-
snackbar.addClass('show');
|
|
22
|
-
|
|
23
|
-
setTimeout(function () {
|
|
24
|
-
$('div.snackbar').remove();
|
|
25
|
-
if (typeof onMessageHidden == 'function') {
|
|
26
|
-
onMessageHidden();
|
|
27
|
-
}
|
|
28
|
-
}, 6000);
|
|
29
|
-
|
|
30
|
-
if (true === reload) {
|
|
31
|
-
document.location.reload();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
1
|
+
class FlashMessage {
|
|
2
|
+
static displaySuccess(message, reload=false, modal=null, onMessageHidden=null, domId=null) {
|
|
3
|
+
this.display('success', message, reload, modal, onMessageHidden, domId);
|
|
4
|
+
}
|
|
5
|
+
static displayWarning(message, modal=null, onMessageHidden=null, domId=null) {
|
|
6
|
+
this.display('warning', message, false, modal, onMessageHidden, domId);
|
|
7
|
+
}
|
|
8
|
+
static displayError(message, modal=null, onMessageHidden=null, domId=null) {
|
|
9
|
+
this.display('danger', message, false, modal, onMessageHidden, domId);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static display(type, message, reload=false, modal=null, onMessageHidden=null, domId=null) {
|
|
13
|
+
if (null !== modal) {
|
|
14
|
+
modal.modal('hide');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$('div.snackbar').remove();
|
|
18
|
+
let snackbar = $('<div class="snackbar '+type+'" '+(null !== domId ? 'id="'+domId+'"' : '')+'></div>');
|
|
19
|
+
$('html body').append(snackbar);
|
|
20
|
+
snackbar.html(message);
|
|
21
|
+
snackbar.addClass('show');
|
|
22
|
+
|
|
23
|
+
setTimeout(function () {
|
|
24
|
+
$('div.snackbar').remove();
|
|
25
|
+
if (typeof onMessageHidden == 'function') {
|
|
26
|
+
onMessageHidden();
|
|
27
|
+
}
|
|
28
|
+
}, 6000);
|
|
29
|
+
|
|
30
|
+
if (true === reload) {
|
|
31
|
+
document.location.reload();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
36
|
module.exports = { FlashMessage };
|