puvox-library 1.0.70 → 1.0.72
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/library_standard.js +468 -476
- package/package.json +1 -1
package/library_standard.js
CHANGED
@@ -15,40 +15,41 @@
|
|
15
15
|
*
|
16
16
|
*/
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
class PuvoxLibrary {
|
19
|
+
self = this;
|
20
|
+
|
20
21
|
// ########## ARRAY ########## //
|
21
22
|
arrayValue(obj_arr, key, default_){
|
22
23
|
return (obj_arr && key in obj_arr ? obj_arr[key] : default_);
|
23
|
-
}
|
24
|
+
}
|
24
25
|
arrayValueLower(obj_arr, key, default_){
|
25
26
|
const val = this.arrayValue(obj_arr, key, default_);
|
26
27
|
return (val===null ? null : val.toLowerCase());
|
27
|
-
}
|
28
|
+
}
|
28
29
|
arrayValueUpper(obj_arr, key, default_){
|
29
30
|
const val = this.arrayValue(obj_arr, key, default_);
|
30
31
|
return (val===null ? null : val.toUpperCase());
|
31
|
-
}
|
32
|
+
}
|
32
33
|
stringToArray(str, splitChar){
|
33
34
|
var splitChar= splitChar || '|';
|
34
35
|
let parts = str.split(splitChar);
|
35
36
|
return parts;
|
36
|
-
}
|
37
|
+
}
|
37
38
|
arrayColumn(array, columnName) {
|
38
39
|
return array.map(function(value,index) {
|
39
40
|
return value[columnName];
|
40
41
|
})
|
41
|
-
}
|
42
|
+
}
|
42
43
|
arrayUnique(array, removeEmpties){
|
43
44
|
//let uniqueItems = [...new Set(items)]
|
44
45
|
let res = array.filter(function(item, pos) {
|
45
46
|
return array.indexOf(item) == pos;
|
46
47
|
});
|
47
48
|
return (removeEmpties ? this.arrayRemoveEmpty(res) : res);
|
48
|
-
}
|
49
|
+
}
|
49
50
|
arrayMerge(ar1,ar2){
|
50
51
|
return ar1.concat(ar2);
|
51
|
-
}
|
52
|
+
}
|
52
53
|
objectsArrayTill(arrayBlocks, key, value)
|
53
54
|
{
|
54
55
|
let newArr = this.isObject(arrayBlocks) ? {} : [];
|
@@ -61,10 +62,10 @@ const puvox_library =
|
|
61
62
|
newArr[key_1] = obj_1;
|
62
63
|
}
|
63
64
|
return newArr;
|
64
|
-
}
|
65
|
-
arrayRemoveEmpty(array){ return array.filter(item => item); }
|
66
|
-
arrayLastMember(arr){ return arr[arr.length-1]; }
|
67
|
-
arrayLastItem(arr){ return this.arrayLastMember(arr); }
|
65
|
+
}
|
66
|
+
arrayRemoveEmpty(array){ return array.filter(item => item); }
|
67
|
+
arrayLastMember(arr){ return arr[arr.length-1]; }
|
68
|
+
arrayLastItem(arr){ return this.arrayLastMember(arr); }
|
68
69
|
removeKeys(obj, keysArr){
|
69
70
|
let newObj ={};
|
70
71
|
for (let [key,val] of Object.entries(obj)){
|
@@ -72,7 +73,7 @@ const puvox_library =
|
|
72
73
|
newObj[key]=val;
|
73
74
|
}
|
74
75
|
return newObj;
|
75
|
-
}
|
76
|
+
}
|
76
77
|
removeKeysExcept (obj, keysArr){
|
77
78
|
let newObj ={};
|
78
79
|
for (let [key,val] of Object.entries(obj)){
|
@@ -80,13 +81,13 @@ const puvox_library =
|
|
80
81
|
newObj[key]=val;
|
81
82
|
}
|
82
83
|
return newObj;
|
83
|
-
}
|
84
|
+
}
|
84
85
|
arrayDiff(source, comparedTo){
|
85
86
|
return source.filter(x => !comparedTo.includes(x));
|
86
|
-
}
|
87
|
+
}
|
87
88
|
arrayIntersect(source, comparedTo){
|
88
89
|
return source.filter(x => comparedTo.includes(x));
|
89
|
-
}
|
90
|
+
}
|
90
91
|
arrayDiffFull(o1,o2) {
|
91
92
|
const self = this;
|
92
93
|
const typeObject = function(o){
|
@@ -141,40 +142,40 @@ const puvox_library =
|
|
141
142
|
diff(o1,o2),
|
142
143
|
diff(o2,o1),
|
143
144
|
];
|
144
|
-
}
|
145
|
+
}
|
145
146
|
sortKeys (x, out = {}) {
|
146
147
|
for (const k of Object.keys (x).sort ()) {
|
147
148
|
out[k] = x[k]
|
148
149
|
}
|
149
150
|
return out
|
150
|
-
}
|
151
|
+
}
|
151
152
|
sortByValuesIntoArray(obj, ascending = true){
|
152
153
|
return Object.entries(obj).sort((a, b) => ascending ? a[1] - b[1] : b[1] - a[1]);
|
153
|
-
}
|
154
|
+
}
|
154
155
|
stringArrayToNumeric(arr){
|
155
156
|
let newArr = [];
|
156
157
|
for(let i=0; i<arr.length; i++){
|
157
158
|
newArr.push( parseFloat(arr[i]) );
|
158
159
|
}
|
159
160
|
return newArr;
|
160
|
-
}
|
161
|
+
}
|
161
162
|
stringToArrayToNumeric(arr){
|
162
163
|
return this.stringArrayToNumeric(this.stringToArray(arr));
|
163
|
-
}
|
164
|
+
}
|
164
165
|
|
165
166
|
objectCopy(obj){
|
166
167
|
return JSON.parse(JSON.stringify(obj));
|
167
|
-
}
|
168
|
+
}
|
168
169
|
// https://stackoverflow.com/a/44782052/2377343
|
169
170
|
cloneObjectDestructuve(orig){
|
170
171
|
return Object.assign(Object.create(Object.getPrototypeOf(orig)), orig);
|
171
|
-
}
|
172
|
+
}
|
172
173
|
// https://stackoverflow.com/a/41474987/2377343
|
173
174
|
cloneObjectWithPrototype(orig){
|
174
175
|
const clone = Object.assign( Object.create(orig), orig );
|
175
176
|
Object.setPrototypeOf( clone, Blah.prototype );
|
176
177
|
return clone;
|
177
|
-
}
|
178
|
+
}
|
178
179
|
getKeyByValue (object, value) {
|
179
180
|
const keys = Object.keys (object);
|
180
181
|
for (let i = 0; i < keys.length; i++) {
|
@@ -184,7 +185,7 @@ const puvox_library =
|
|
184
185
|
}
|
185
186
|
}
|
186
187
|
return undefined;
|
187
|
-
}
|
188
|
+
}
|
188
189
|
hasChildWithKeyValue (obj, targetKey, targetValue) {
|
189
190
|
const keys = Object.keys (obj);
|
190
191
|
for (let i = 0; i < keys.length; i++) {
|
@@ -196,8 +197,7 @@ const puvox_library =
|
|
196
197
|
}
|
197
198
|
}
|
198
199
|
return false;
|
199
|
-
}
|
200
|
-
|
200
|
+
}
|
201
201
|
|
202
202
|
|
203
203
|
|
@@ -219,7 +219,7 @@ const puvox_library =
|
|
219
219
|
}
|
220
220
|
});
|
221
221
|
}
|
222
|
-
}
|
222
|
+
}
|
223
223
|
|
224
224
|
// setTimeout( window[arguments.callee.name.toString() ], 500);
|
225
225
|
|
@@ -230,14 +230,14 @@ const puvox_library =
|
|
230
230
|
jQuery( this ).attr( 'src', jQuery( this ).attr( 'data-src' ) );
|
231
231
|
}
|
232
232
|
);
|
233
|
-
}
|
233
|
+
}
|
234
234
|
|
235
235
|
move_to_top_in_parent(el_tag)
|
236
236
|
{
|
237
237
|
$(el_tag).each(function() {
|
238
238
|
$(this).parent().prepend(this);
|
239
239
|
});
|
240
|
-
}
|
240
|
+
}
|
241
241
|
|
242
242
|
//window.onload REPLACEMENT Both methods are used to achieve the same goal of attaching an event to an element.
|
243
243
|
// ttachEvent can only be used on older trident rendering engines ( IE5+ IE5-8*) and addEventListener is a W3 standard that is implemented in the majority of other browsers (FF, Webkit, Opera, IE9+).
|
@@ -263,7 +263,7 @@ const puvox_library =
|
|
263
263
|
}
|
264
264
|
//append in head
|
265
265
|
(document.head || document.getElementsByTagName('head')[0]).appendChild(x);
|
266
|
-
}
|
266
|
+
}
|
267
267
|
Append_To_Head(elemntType, content) {
|
268
268
|
var Is_Link = content.split(/\r\n|\r|\n/).length <= 1 && content.indexOf("/") > -1 && (content.substring(0, 4) == 'http' || content.substring(0, 2) == '//' || content.substring(0, 2) == './' || content.substring(0, 1) == '/');
|
269
269
|
if (Is_Link) {
|
@@ -299,7 +299,7 @@ const puvox_library =
|
|
299
299
|
}
|
300
300
|
document.head.appendChild(x);
|
301
301
|
}
|
302
|
-
}
|
302
|
+
}
|
303
303
|
// loadScript
|
304
304
|
appendScript(url, callback, defer=false){
|
305
305
|
var script = document.createElement('script');
|
@@ -308,24 +308,24 @@ const puvox_library =
|
|
308
308
|
if (defer)
|
309
309
|
script.defer = true;
|
310
310
|
document.head.appendChild(script);
|
311
|
-
}
|
311
|
+
}
|
312
312
|
appendScript2(url){
|
313
313
|
var script = document.createElement('script');
|
314
314
|
document.head.appendChild(script);
|
315
315
|
script.onload = function () { };
|
316
316
|
script.src = url;
|
317
|
-
}
|
317
|
+
}
|
318
318
|
|
319
319
|
blackground2(){
|
320
320
|
var innerDiv = document.createElement("div"); innerDiv.id = "my_black_backgr";
|
321
321
|
innerDiv.setAttribute("style", "background:black; height:4000px; left:0px; opacity:0.9; position:fixed; top:0px; width:100%; z-index:9990;");
|
322
322
|
var BODYYY = document.body; BODYYY.insertBefore(innerDiv, BODYYY.childNodes[0]);
|
323
|
-
}
|
323
|
+
}
|
324
324
|
|
325
325
|
getFileExtension(filename){
|
326
326
|
var ext = filename.split('.').pop();
|
327
327
|
return (ext===filename) ? '' : ext;
|
328
|
-
}
|
328
|
+
}
|
329
329
|
|
330
330
|
// stackoverflow -best foreach
|
331
331
|
forEach(collection, callback, scope) {
|
@@ -340,30 +340,29 @@ const puvox_library =
|
|
340
340
|
callback.call(scope, collection[i], i, collection);
|
341
341
|
}
|
342
342
|
}
|
343
|
-
}
|
343
|
+
}
|
344
344
|
|
345
345
|
// ################
|
346
|
-
sanitize(str){ return str.trim().replace( /[^a-zA-Z0-9_\-]/g, "_"); }
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
{
|
351
|
-
|
352
|
-
}
|
353
|
-
|
346
|
+
sanitize(str){ return str.trim().replace( /[^a-zA-Z0-9_\-]/g, "_"); }
|
347
|
+
|
348
|
+
sanitize_key(str, use_dash){ return str.trim().toLowerCase().replace( /[^a-z0-9_\-]/g, (use_dash===true ? '_' : (use_dash ? use_dash :'')) ); } //same as wp
|
349
|
+
|
350
|
+
sanitize_key_dashed(str){ return this.sanitize_key(str, true).replace(/__/g,'_'); }
|
351
|
+
|
352
|
+
sanitize_variable_name(str) { return this.strip_non_word(str).replace(/-/g,"_"); }
|
353
|
+
|
354
|
+
sanitize_text(str, use_dash=false) { return str.trim().replace(/[^a-zA-Z0-9]+/g, (use_dash ? "_":"") ); }
|
354
355
|
|
355
356
|
//nonword
|
356
|
-
strip_non_word(str)
|
357
|
-
|
358
|
-
|
359
|
-
},
|
360
|
-
removeAllWhitespaces(content){ return content.replace(/\s/g,''); },
|
357
|
+
strip_non_word(str) { return str.replace(/[\W_]+/g,"-"); }
|
358
|
+
|
359
|
+
removeAllWhitespaces(content){ return content.replace(/\s/g,''); }
|
361
360
|
|
362
361
|
replaceAllOccurences (input, search, replacement) {
|
363
362
|
const splited = input.split (search);
|
364
363
|
const joined = splited.join (replacement);
|
365
364
|
return joined;
|
366
|
-
}
|
365
|
+
}
|
367
366
|
|
368
367
|
// ####################### TYPE ##############################
|
369
368
|
|
@@ -375,26 +374,26 @@ const puvox_library =
|
|
375
374
|
else if (this.isArray(x)) return "array";
|
376
375
|
else if (this.isObject(x)) return "object";
|
377
376
|
return typeof x;
|
378
|
-
}
|
379
|
-
isInteger(x) { return Number.isInteger(x); }
|
380
|
-
isNumeric(x) { return Number.isFinite(x); }
|
381
|
-
isDecimal(x) { return this.isNumeric(x) && (!isNaN(parseFloat(x))); }
|
382
|
-
isBoolean(x) { return this.isBooleanReal(x) || (this.isString(x) && (x.toLowerCase() =="true" || x.toLowerCase() =="false")); }
|
383
|
-
isBooleanReal(x) { return x === true || x === false || toString.call(x) === '[object Boolean]'; }
|
384
|
-
isString(x) { return Object.prototype.toString.call(x) === "[object String]"; }
|
377
|
+
}
|
378
|
+
isInteger(x) { return Number.isInteger(x); }
|
379
|
+
isNumeric(x) { return Number.isFinite(x); }
|
380
|
+
isDecimal(x) { return this.isNumeric(x) && (!isNaN(parseFloat(x))); } // avoid occasions like "1abc"
|
381
|
+
isBoolean(x) { return this.isBooleanReal(x) || (this.isString(x) && (x.toLowerCase() =="true" || x.toLowerCase() =="false")); }
|
382
|
+
isBooleanReal(x) { return x === true || x === false || toString.call(x) === '[object Boolean]'; }
|
383
|
+
isString(x) { return Object.prototype.toString.call(x) === "[object String]"; } // return (typeof content === 'string' || content instanceof String);
|
385
384
|
// https://stackoverflow.com/questions/8834126/
|
386
|
-
isObject(x) { return ( !Array.isArray(x) && Object.prototype.toString.call(x) !== '[object Array]' ) && ( (typeof x === 'object' && x !== null ) || ( (!!x) && (x.constructor === Object) ) || (typeof x === 'function' || typeof x === 'object' && !!x) ) ; }
|
385
|
+
isObject(x) { return ( !Array.isArray(x) && Object.prototype.toString.call(x) !== '[object Array]' ) && ( (typeof x === 'object' && x !== null ) || ( (!!x) && (x.constructor === Object) ) || (typeof x === 'function' || typeof x === 'object' && !!x) ) ; }
|
387
386
|
// https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript
|
388
387
|
isJsonObject(data){
|
389
388
|
// doesnt work for string return data!="" && (data=={} || JSON.stringify(data)!='{}');
|
390
389
|
return false;
|
391
|
-
}
|
392
|
-
isArray(x) { return ( (!!x) && (x.constructor === Array) ) || (Array.isArray(x)); }
|
390
|
+
}
|
391
|
+
isArray(x) { return ( (!!x) && (x.constructor === Array) ) || (Array.isArray(x)); }
|
393
392
|
|
394
|
-
isSimpleVariableType(obj){ return this.isSimpleVariableTypeName(typeof obj); }
|
395
|
-
isSimpleVariableTypeName(typeName_){ return this.inArray( typeName_, [ "boolean", "integer", "float", "double", "decimal", "string"]); }
|
396
|
-
isNumericVariableType(obj){ return this.isNumericVariableTypeName(typeof obj); }
|
397
|
-
isNumericVariableTypeName(typeName_){ return this.inArray(typeName_, [ "integer", "float", "double", "decimal"]); }
|
393
|
+
isSimpleVariableType(obj){ return this.isSimpleVariableTypeName(typeof obj); }
|
394
|
+
isSimpleVariableTypeName(typeName_){ return this.inArray( typeName_, [ "boolean", "integer", "float", "double", "decimal", "string"]); }
|
395
|
+
isNumericVariableType(obj){ return this.isNumericVariableTypeName(typeof obj); }
|
396
|
+
isNumericVariableTypeName(typeName_){ return this.inArray(typeName_, [ "integer", "float", "double", "decimal"]); }
|
398
397
|
|
399
398
|
stringToBoolean(string){
|
400
399
|
switch(string.toLowerCase().trim()){
|
@@ -402,10 +401,10 @@ const puvox_library =
|
|
402
401
|
case "false": case "no": case "0": case null: return false;
|
403
402
|
default: return Boolean(string);
|
404
403
|
}
|
405
|
-
}
|
404
|
+
}
|
406
405
|
isException(e){
|
407
406
|
return e && e.stack && e.message;
|
408
|
-
}
|
407
|
+
}
|
409
408
|
IsJsonString (str) {
|
410
409
|
try {
|
411
410
|
JSON.parse(str);
|
@@ -413,10 +412,10 @@ const puvox_library =
|
|
413
412
|
return false;
|
414
413
|
}
|
415
414
|
return true;
|
416
|
-
}
|
415
|
+
}
|
417
416
|
is_object(variable){
|
418
417
|
return typeof variable === 'object' && variable !== null;
|
419
|
-
}
|
418
|
+
}
|
420
419
|
formItemsToJson(FormElement){
|
421
420
|
let formDataEntries = new FormData(FormElement).entries();
|
422
421
|
const handleChild = function (obj,keysArr,value){
|
@@ -442,7 +441,7 @@ const puvox_library =
|
|
442
441
|
for (const [key, value] of formDataEntries )
|
443
442
|
result= handleChild(result, key.split(/\[/), value);
|
444
443
|
return result;
|
445
|
-
}
|
444
|
+
}
|
446
445
|
|
447
446
|
renameKey (obj, keyFrom, keyTo) {
|
448
447
|
for (const key of Object.keys(obj)) {
|
@@ -450,14 +449,14 @@ const puvox_library =
|
|
450
449
|
delete obj[keyFrom];
|
451
450
|
}
|
452
451
|
return obj;
|
453
|
-
}
|
452
|
+
}
|
454
453
|
renameSubKey (obj, keyFrom, keyTo, strict = false) {
|
455
454
|
for (const key of Object.keys(obj)) {
|
456
455
|
obj[key][keyTo] = strict ? obj[key][keyFrom] : (obj[key][keyFrom] || null);
|
457
456
|
delete obj[key][keyFrom];
|
458
457
|
}
|
459
458
|
return obj;
|
460
|
-
}
|
459
|
+
}
|
461
460
|
|
462
461
|
hasEmptyChild(obj){
|
463
462
|
let hasEmpty = false;
|
@@ -469,47 +468,47 @@ const puvox_library =
|
|
469
468
|
}
|
470
469
|
}
|
471
470
|
return hasEmpty;
|
472
|
-
}
|
471
|
+
}
|
473
472
|
|
474
473
|
filterObject(obj, callback) {
|
475
474
|
return Object.fromEntries(Object.entries(obj).
|
476
475
|
filter(([key, val]) => callback(val, key)));
|
477
|
-
}
|
476
|
+
}
|
478
477
|
// #####################################$$$$$################
|
479
478
|
|
480
479
|
|
481
|
-
isBetween(a,b,c) { return a< b && b< c; }
|
482
|
-
isBetweenEq(a,b,c) { return a<=b && b<=c; }
|
480
|
+
isBetween(a,b,c) { return a< b && b< c; }
|
481
|
+
isBetweenEq(a,b,c) { return a<=b && b<=c; }
|
483
482
|
startsWithWhiteSpace(content){
|
484
483
|
return (/^\s/).test(content);
|
485
|
-
}
|
484
|
+
}
|
486
485
|
trimOnlyFromEnd(content){
|
487
486
|
return content.replace(/\s*$/,"");
|
488
|
-
}
|
487
|
+
}
|
489
488
|
startsWith(content, what){
|
490
489
|
return content.startsWith(what);
|
491
|
-
}
|
490
|
+
}
|
492
491
|
startsWithArray(content,array){
|
493
492
|
array.forEach(function(val){
|
494
493
|
if (content.startsWith(val)) return true;
|
495
494
|
})
|
496
495
|
return false;
|
497
|
-
}
|
496
|
+
}
|
498
497
|
endsWith(content, what){
|
499
498
|
return content.endsWith(what);
|
500
|
-
}
|
499
|
+
}
|
501
500
|
endsWithArray(content,array){
|
502
501
|
array.forEach(function(val){
|
503
502
|
if (content.endsWith(val)) return true;
|
504
503
|
})
|
505
504
|
return false;
|
506
|
-
}
|
505
|
+
}
|
507
506
|
startLetters(str, amountOfLetters){
|
508
507
|
return str.substr(0, amountOfLetters);
|
509
|
-
}
|
508
|
+
}
|
510
509
|
endLetters(str, amountOfLetters){
|
511
510
|
return str.substr(str.length - amountOfLetters);
|
512
|
-
}
|
511
|
+
}
|
513
512
|
|
514
513
|
ConvertNumbToRoman(num){
|
515
514
|
num= num.replace('40','XXXX'); num= num.replace('39','XXXIX'); num= num.replace('38','XXXVIII'); num= num.replace('37','XXXVII');
|
@@ -522,7 +521,7 @@ const puvox_library =
|
|
522
521
|
num= num.replace('12','XII'); num= num.replace('11','XI'); num= num.replace('10','X'); num= num.replace('9','IX');
|
523
522
|
num= num.replace('8','VIII'); num= num.replace('7','VII'); num= num.replace('6','VI'); num= num.replace('5','V');
|
524
523
|
num= num.replace('4','IV'); num= num.replace('3','III'); num= num.replace('2','II'); num= num.replace('1','I'); return num;
|
525
|
-
}
|
524
|
+
}
|
526
525
|
|
527
526
|
// encrypt decrypt: http://jsfiddle.net/kein1945/M9K2c/ | https://stackoverflow.com/questions/18279141/ | https://stackoverflow.com/questions/51531021/x
|
528
527
|
|
@@ -531,24 +530,24 @@ const puvox_library =
|
|
531
530
|
when_element_is_loaded(Id_or_class,functionname){
|
532
531
|
Id_or_class=Id_or_class.trim(); var eName = Id_or_class.substr(1); if('#'==Id_or_class.charAt(0)){var x=document.getElementById(eName);} else{var x=document.getElementsByClassName(eName)[0];}
|
533
532
|
if(x) { functionname(); } else { setTimeout(when_element_is_loaded, 100, Id_or_class, functionname); }
|
534
|
-
}
|
533
|
+
}
|
535
534
|
|
536
535
|
// set document title
|
537
|
-
SetTitlee(title) { document.getElementsByTagName('title')[0].innerHTML =
|
536
|
+
SetTitlee(title) { document.getElementsByTagName('title')[0].innerHTML = title; }
|
538
537
|
|
539
538
|
setUrl(urlPath, title) {
|
540
539
|
var title= title || false;
|
541
540
|
window.history.pushState( ( title ? {"pageTitle":title} : ""),"", urlPath); //{"html":...,"pageTitle":....}
|
542
|
-
}
|
541
|
+
}
|
543
542
|
|
544
543
|
requestUri(url){
|
545
544
|
var url = url || location.href;
|
546
545
|
return url.replace(origin,'');
|
547
|
-
}
|
546
|
+
}
|
548
547
|
// check if key exists in array
|
549
548
|
ArrayKeyExistss(keyname,array) {
|
550
549
|
return typeof array[keyname] !== 'undefined';
|
551
|
-
}
|
550
|
+
}
|
552
551
|
|
553
552
|
hashtageChangeOnClick(e) {
|
554
553
|
function MyCallbackTemp (e)
|
@@ -569,17 +568,17 @@ const puvox_library =
|
|
569
568
|
|
570
569
|
if (document.addEventListener) document.addEventListener('click', MyCallbackTemp, false);
|
571
570
|
else document.attachEvent('onclick', MyCallbackTemp);
|
572
|
-
}
|
571
|
+
}
|
573
572
|
|
574
573
|
capitalizeFirstLetter(string) {
|
575
574
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
576
|
-
}
|
575
|
+
}
|
577
576
|
|
578
577
|
addQueryArg(name,value, url)
|
579
578
|
{
|
580
579
|
var url = url || location.href;
|
581
580
|
return url + (url.indexOf("?")<0 ? "?":"&") +escape(name)+"="+escape(value);
|
582
|
-
}
|
581
|
+
}
|
583
582
|
buildQueryString(params){
|
584
583
|
if (!params) return '';
|
585
584
|
return Object.entries(params)
|
@@ -587,7 +586,7 @@ const puvox_library =
|
|
587
586
|
return `${key}=${encodeURIComponent(value)}`;
|
588
587
|
})
|
589
588
|
.join('&');
|
590
|
-
}
|
589
|
+
}
|
591
590
|
|
592
591
|
// find home url (in wordpress)
|
593
592
|
wpHomeUrl (){
|
@@ -595,9 +594,8 @@ const puvox_library =
|
|
595
594
|
if (typeof matches !== 'undefined' && matches != null && matches.length > 1 ){
|
596
595
|
homeURL = matches[2];
|
597
596
|
}
|
598
|
-
}
|
597
|
+
}
|
599
598
|
|
600
|
-
|
601
599
|
LoadYoutubeApi(callback)
|
602
600
|
{
|
603
601
|
// This code loads the IFrame Player API code asynchronously.
|
@@ -608,10 +606,10 @@ const puvox_library =
|
|
608
606
|
window.onYouTubeIframeAPIReady= function(){
|
609
607
|
callback();
|
610
608
|
};
|
611
|
-
}
|
609
|
+
}
|
612
610
|
|
613
|
-
argvsString(){ return process.argv[2]; }
|
614
|
-
argvsArray(){ return process.argv.slice(2); }
|
611
|
+
argvsString(){ return process.argv[2]; }
|
612
|
+
argvsArray(){ return process.argv.slice(2); }
|
615
613
|
argvs(){
|
616
614
|
let argvs= this.argvsArray();
|
617
615
|
let KeyValues= {};
|
@@ -640,14 +638,14 @@ const puvox_library =
|
|
640
638
|
}
|
641
639
|
}
|
642
640
|
return KeyValues;
|
643
|
-
}
|
641
|
+
}
|
644
642
|
argv(which, def = undefined){
|
645
643
|
let KeyValues= this.argvs();
|
646
644
|
return (which in KeyValues ? KeyValues[which] : def);
|
647
|
-
}
|
645
|
+
}
|
648
646
|
argvIsSet(which){
|
649
647
|
return this.inArray(which, this.argvsArray()) || this.argv(which)!=undefined;
|
650
|
-
}
|
648
|
+
}
|
651
649
|
|
652
650
|
|
653
651
|
parseQuery(queryString) {
|
@@ -665,7 +663,7 @@ const puvox_library =
|
|
665
663
|
query[decodeURIComponent(pair[0])] = p2;
|
666
664
|
}
|
667
665
|
return query;
|
668
|
-
}
|
666
|
+
}
|
669
667
|
|
670
668
|
//https://stackoverflow.com/questions/123999/how-can-i-tell-if-a-dom-element-is-visible-in-the-current-viewport
|
671
669
|
// $(window).on('DOMContentLoaded load resize scroll', handler);
|
@@ -677,7 +675,7 @@ const puvox_library =
|
|
677
675
|
const newObj = {};
|
678
676
|
Object.keys(obj).map (k=>newObj[obj[k]]=k);
|
679
677
|
return newObj;
|
680
|
-
}
|
678
|
+
}
|
681
679
|
|
682
680
|
isElementInViewport (el) {
|
683
681
|
// Special bonus for those using jQuery
|
@@ -693,7 +691,7 @@ const puvox_library =
|
|
693
691
|
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /* or $(window).height() */
|
694
692
|
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /* or $(window).width() */
|
695
693
|
);
|
696
|
-
}
|
694
|
+
}
|
697
695
|
|
698
696
|
MakeIframeFullHeight(iframeElement, cycling, overwrite_margin){
|
699
697
|
cycling= cycling || false;
|
@@ -715,9 +713,9 @@ const puvox_library =
|
|
715
713
|
})();
|
716
714
|
//var funcname= arguments.callee.name;
|
717
715
|
//window.setTimeout( function(){ console.log(funcname); console.log(cycling); window[funcname](iframeElement, cycling); }, 500 );
|
718
|
-
}
|
716
|
+
}
|
719
717
|
|
720
|
-
getYtIdFromURL(URLL){let r=URLL.match(/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/); return r[1];}
|
718
|
+
getYtIdFromURL(URLL){let r=URLL.match(/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/); return r[1];}
|
721
719
|
|
722
720
|
//state url change
|
723
721
|
//function processAjaxData(response, urlPath){
|
@@ -743,7 +741,7 @@ const puvox_library =
|
|
743
741
|
};
|
744
742
|
tx[i].addEventListener("input", OnInput, false);
|
745
743
|
}
|
746
|
-
}
|
744
|
+
}
|
747
745
|
|
748
746
|
getAllMethods(obj, inherited_too)
|
749
747
|
{
|
@@ -754,7 +752,7 @@ const puvox_library =
|
|
754
752
|
}
|
755
753
|
}
|
756
754
|
return methods;
|
757
|
-
}
|
755
|
+
}
|
758
756
|
|
759
757
|
hasMethod(obj, funcName, inherited_too)
|
760
758
|
{
|
@@ -766,19 +764,19 @@ const puvox_library =
|
|
766
764
|
}
|
767
765
|
}
|
768
766
|
return false;
|
769
|
-
}
|
767
|
+
}
|
770
768
|
|
771
769
|
|
772
770
|
ConvertToHourMinSec(time){ //Output like "1:01" or "4:03:59" or "123:03:59"
|
773
771
|
var hrs = ~~(time / 3600); var mins = ~~((time % 3600) / 60); var secs = time % 60;
|
774
772
|
var hms=""; hms +=""+hrs+":"+(mins< 10 ? "0":""); hms +=""+mins+":"+(secs<10 ? "0":""); hms +=""+secs; return hms;
|
775
|
-
}
|
773
|
+
}
|
776
774
|
|
777
775
|
// =========== get device sizes ==========//
|
778
776
|
// http://ryanve.com/lab/dimensions/
|
779
777
|
getWindowSize(){
|
780
778
|
return {x:document.documentElement.clientWidth, y:document.documentElement.clientHeight} ;
|
781
|
-
}
|
779
|
+
}
|
782
780
|
|
783
781
|
removeItem(arr, value) {
|
784
782
|
var i = 0;
|
@@ -790,20 +788,20 @@ const puvox_library =
|
|
790
788
|
}
|
791
789
|
}
|
792
790
|
return arr;
|
793
|
-
}
|
791
|
+
}
|
794
792
|
removeItemOnce(arr, value) {
|
795
793
|
var index = arr.indexOf(value);
|
796
794
|
if (index > -1) {
|
797
795
|
arr.splice(index, 1);
|
798
796
|
}
|
799
797
|
return arr;
|
800
|
-
}
|
798
|
+
}
|
801
799
|
toggleItemInArray(array, value, condition)
|
802
800
|
{
|
803
801
|
if (condition) array.push(value);
|
804
802
|
else this.removeItemOnce(array,value);
|
805
803
|
return array;
|
806
|
-
}
|
804
|
+
}
|
807
805
|
|
808
806
|
// avoid ccxt's bug for undefined : https://jsfiddle.net/Lpxsthw4/
|
809
807
|
mergeDeep(target, source) {
|
@@ -822,7 +820,7 @@ const puvox_library =
|
|
822
820
|
});
|
823
821
|
}
|
824
822
|
return output;
|
825
|
-
}
|
823
|
+
}
|
826
824
|
|
827
825
|
getScrollbarWidth() {
|
828
826
|
var outer = document.createElement("div");
|
@@ -838,7 +836,7 @@ const puvox_library =
|
|
838
836
|
var widthWithScroll = inner.offsetWidth;
|
839
837
|
outer.parentNode.removeChild(outer);
|
840
838
|
return widthNoScroll - widthWithScroll;
|
841
|
-
}
|
839
|
+
}
|
842
840
|
|
843
841
|
// animation-css https://codepen.io/AKGD/pen/yvwQYZ
|
844
842
|
animationClick(element, animation, removeOrNot){
|
@@ -855,7 +853,7 @@ const puvox_library =
|
|
855
853
|
}
|
856
854
|
}
|
857
855
|
);
|
858
|
-
}
|
856
|
+
}
|
859
857
|
|
860
858
|
animationClickTarget(element, target, animation, removeOrNot){
|
861
859
|
var $=jQuery;
|
@@ -871,69 +869,70 @@ const puvox_library =
|
|
871
869
|
}
|
872
870
|
}
|
873
871
|
);
|
874
|
-
}
|
872
|
+
}
|
875
873
|
|
876
874
|
|
877
|
-
datetime
|
875
|
+
datetime = new (class{
|
876
|
+
MAIN_CLASS = self;
|
878
877
|
// 0940 type time-ints
|
879
|
-
isBetweenHMS(target, start, end, equality) { }
|
878
|
+
isBetweenHMS(target, start, end, equality) { } // datetime, int/datetime, int/datetime, bool
|
880
879
|
equalDays(d1,d2) {
|
881
880
|
return d1.getYear()==d2.getyear() && d1.getMonth()==d2.getMonth() && d1.getDate()==d2.getDate();
|
882
|
-
}
|
883
|
-
IsTodayStart(dt) { }
|
884
|
-
GetWeekOfMonth(dt) { }
|
885
|
-
GetWeekOfYear(dt) { }
|
886
|
-
GetQuarter(dt) { }
|
887
|
-
NumberToHMSstring(hhmmss) { }
|
881
|
+
} // DateTime, DateTime
|
882
|
+
IsTodayStart(dt) { } // DateTime
|
883
|
+
GetWeekOfMonth(dt) { } // DateTime
|
884
|
+
GetWeekOfYear(dt) { } // DateTime
|
885
|
+
GetQuarter(dt) { } // DateTime
|
886
|
+
NumberToHMSstring(hhmmss) { } // int
|
888
887
|
// ZZ incorrect, need LOCAL/UTC: DatetimeToHMSstring(dt) { }, // DateTime
|
889
888
|
// HMSToTimeSpan(hhmmss) { }, // int
|
890
|
-
addNumberToHMS(hhmmss, added_or_subtracted) { }
|
889
|
+
addNumberToHMS(hhmmss, added_or_subtracted) { } // int, int
|
891
890
|
DatetimeToStringUtc(dt, withMS = true, withTZ = true) {
|
892
891
|
var str = (new Date( dt || new Date() )).toISOString();
|
893
892
|
let finalStr = (withTZ ? str : str.replace("T", " ").replace("Z", ""));
|
894
893
|
return withMS ? finalStr : finalStr.split('.')[0]; //2022-07-09 15:25:00.276
|
895
|
-
}
|
894
|
+
}
|
896
895
|
DatetimeToStringLocal(dt, withMS = true, withT = false) {
|
897
896
|
const str = (dt || new Date()).toLocaleString('sv', {year:'numeric', month:'numeric', day:'numeric', hour:'numeric', minute:'numeric', second:'numeric', fractionalSecondDigits: 3}).replace(',', '.');
|
898
897
|
let finalStr = (withT ? str.replace(' ', 'T') : str);
|
899
898
|
return withMS ? finalStr : finalStr.split('.')[0]; //2022-07-09 19:25:00.276
|
900
|
-
}
|
899
|
+
}
|
901
900
|
// in some langs, the date object has distinctions, so the two below needs separated methods. However, the "date" object returned from them, are same, just the representation can be local or UTC depending user.
|
902
|
-
StringToDatetimeUtc(str, format, culture) { return new Date(str); }
|
903
|
-
StringToDatetimeLocal(str, format, culture) { return new Date(str); }
|
904
|
-
StringToTimestamUtc(str, format, culture) { return new Date(str).getTime(); }
|
901
|
+
StringToDatetimeUtc(str, format, culture) { return new Date(str); }
|
902
|
+
StringToDatetimeLocal(str, format, culture) { return new Date(str); }
|
903
|
+
StringToTimestamUtc(str, format, culture) { return new Date(str).getTime(); }
|
905
904
|
DatetimeUtc() {
|
906
905
|
var now = new Date();
|
907
906
|
var utc = new Date(now.getTime()); // + now.getTimezoneOffset() * 60000 is not needed !!!!!!
|
908
907
|
return utc;
|
909
|
-
}
|
908
|
+
} UtcDatetime() { return this.DatetimeUtc(); }
|
910
909
|
// UTC
|
911
910
|
TimestampUtc() {
|
912
911
|
return Math.floor(new Date().getTime());
|
913
|
-
}
|
912
|
+
} UtcTimestamp() { return this.TimestampUtc(); }
|
914
913
|
//i.e. input: "2021-03-08 11:59:00" | output : 1650000000000 (milliseconds)
|
915
914
|
// [DONT CHANGE THIS FUNC, I'VE REVISED]
|
916
915
|
DatetimeToTimestampUtc(dt) {
|
917
916
|
let offset = this.getOffsetFromUtc();
|
918
917
|
return ((((new Date( dt )).getTime()) / 1000) + 14400 - offset * 60* 60) * 1000;
|
919
|
-
}
|
918
|
+
} UtcTimestampFrom(dt) { return this.DatetimeToTimestampUtc(dt); }
|
920
919
|
TimestampUtcToDatetimeUtc(ts) {
|
921
920
|
var d = new Date(ts);
|
922
921
|
d.setHours(d.getHours());
|
923
922
|
return d;
|
924
|
-
}
|
923
|
+
} UtcTimestampToUtcDatetime(ts) { return this.TimestampUtcToDatetimeUtc(ts); }
|
925
924
|
// shorthands
|
926
|
-
MaxDate(d1, d2, d3=null) {}
|
927
|
-
MinDate(d1, d2, d3=null) {}
|
928
|
-
localDatetimeToUtcString(dt){ }
|
929
|
-
areSameDays(d1, d2){ }
|
925
|
+
MaxDate(d1, d2, d3=null) {}
|
926
|
+
MinDate(d1, d2, d3=null) {}
|
927
|
+
localDatetimeToUtcString(dt){ }
|
928
|
+
areSameDays(d1, d2){ }
|
930
929
|
|
931
930
|
|
932
931
|
// ##### added to JS #####
|
933
|
-
GetDayOfYear(dt) { return (dt || new Date()).getUTCDate(); }
|
932
|
+
GetDayOfYear(dt) { return (dt || new Date()).getUTCDate(); }
|
934
933
|
StringToUtcString(str) {
|
935
934
|
return str.indexOf ('Z') > -1 || str.indexOf ('GMT') > -1 ? str : str + ' GMT+0000';
|
936
|
-
}
|
935
|
+
}
|
937
936
|
//i.e. input: 1650000000000 (milliseconds) | output : "2021-03-08 11:59:00"
|
938
937
|
UtcTimestampToLocalDatetime(ts) {
|
939
938
|
var d = new Date(ts);
|
@@ -944,29 +943,29 @@ const puvox_library =
|
|
944
943
|
// var utc = d.getTime() + (d.getTimezoneOffset() * 60000); //This converts to UTC 00:00
|
945
944
|
// var nd = new Date(utc + (3600000*offset));
|
946
945
|
// return nd; return nd.toLocaleString();
|
947
|
-
}
|
946
|
+
}
|
948
947
|
//i.e. input: 1650000000000 (milliseconds) | output : "2021-07-14T21:08:00.000Z"
|
949
948
|
// [DONT CHANGE THIS FUNC, I'VE REVISED]
|
950
949
|
UtcTimestampToUtcDatetimeString_OLD_CORRECT(epochtime, withTZ){
|
951
950
|
let d = new Date(epochtime);
|
952
951
|
let str =d.toISOString();
|
953
952
|
return (withTZ ? str : str.replace("T", " ").replace("Z", ""));
|
954
|
-
}
|
953
|
+
}
|
955
954
|
UtcTimestampToUtcDatetimeString(epochtime, withTZ){
|
956
955
|
let d = this.UtcTimestampToUtcDatetime(epochtime);
|
957
956
|
return this.DatetimeToStringUtc(d, true, withTZ);
|
958
|
-
}
|
957
|
+
}
|
959
958
|
getOffsetFromUtc(){
|
960
959
|
var dt = new Date();
|
961
960
|
return -dt.getTimezoneOffset()/60;
|
962
|
-
}
|
961
|
+
}
|
963
962
|
// https://stackoverflow.com/questions/8579861/how-to-convert-milliseconds-into-a-readable-date
|
964
963
|
stringToDate(str){ // i.. "2021-04-05 15:59:55 GMT+4"
|
965
964
|
return new Date( Date.parse(str) );
|
966
|
-
}
|
965
|
+
}
|
967
966
|
msGoneAfter(date){
|
968
967
|
return (new Date()-date);
|
969
|
-
}
|
968
|
+
}
|
970
969
|
getYMDHISFfromDate(dt, utc=true){
|
971
970
|
// todo ? is +1 needed for month ??
|
972
971
|
if (utc) {
|
@@ -974,7 +973,7 @@ const puvox_library =
|
|
974
973
|
} else {
|
975
974
|
return [1900 + dt.getYear(), dt.getMonth()+1, dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds()];
|
976
975
|
}
|
977
|
-
}
|
976
|
+
}
|
978
977
|
getYMDHISFfromDateWithZeros(dt, utc=true){
|
979
978
|
let y, M, d, h, m, s, f;
|
980
979
|
if (utc) {
|
@@ -995,36 +994,36 @@ const puvox_library =
|
|
995
994
|
f = dt.getMilliseconds();
|
996
995
|
}
|
997
996
|
return {y:y.toString(), M:(M<10?'0':'')+M.toString(), d:(d<10?'0':'')+d.toString(), h:(h<10?'0':'')+h.toString(), m:(m<10?'0':'')+m.toString(), s:(s<10?'0':'')+s.toString(), f:(f<10?'00':(f<100?'0':''))+f.toString()};
|
998
|
-
}
|
997
|
+
}
|
999
998
|
prefixWithZero(num, digits){
|
1000
999
|
return (digits===1 ? num : (digits===2 ? (num < 10 ? "0"+num : num ) : (digits===3 ? (num < 10 ? "00"+num : (num < 100 ? "0"+num : num ) ) : num ) ) ).toString();
|
1001
|
-
}
|
1000
|
+
}
|
1002
1001
|
currentDatetimeIs(targetDate){ //"2021-03-30 13:33:45 GMT+0300"
|
1003
1002
|
var curr_dt = new Date( Date.now() );
|
1004
1003
|
var target_dt= new Date( Date.parse(targetDate) );
|
1005
1004
|
return curr_dt.getYear() ==target_dt.getYear() && curr_dt.getMonth() ==target_dt.getMonth() && curr_dt.getDate() ==target_dt.getDate() && curr_dt.getHours() ==target_dt.getHours() && curr_dt.getMinutes() ==target_dt.getMinutes() && curr_dt.getSeconds() ==target_dt.getSeconds();
|
1006
|
-
}
|
1005
|
+
}
|
1007
1006
|
dateCompare(date1, date2){
|
1008
|
-
var date1 =
|
1007
|
+
var date1 = this.MAIN_CLASS.isString(date1) ? Date.parse(date1) : date1;
|
1009
1008
|
date1 = new Date( date1 );
|
1010
1009
|
var date2 = date2 || new Date(Date.now());
|
1011
1010
|
return (+date1 > +date2 ? 1 : +date1 < +date2 ? -1 : 0);
|
1012
|
-
}
|
1011
|
+
}
|
1013
1012
|
dateTill(date1, date2){
|
1014
|
-
var date1 =
|
1013
|
+
var date1 = this.MAIN_CLASS.isString(date1) ? Date.parse(date1) : date1;
|
1015
1014
|
date1 = new Date( date1 );
|
1016
1015
|
var date2 = date2 || new Date(Date.now());
|
1017
1016
|
var diff = new Date(date1.getTime()-date2.getTime());
|
1018
1017
|
return diff;
|
1019
|
-
}
|
1018
|
+
}
|
1020
1019
|
secondsTill(date1, date2){
|
1021
|
-
var date1 =
|
1020
|
+
var date1 = this.MAIN_CLASS.isString(date1) ? Date.parse(date1) : date1;
|
1022
1021
|
date1 = new Date( date1 );
|
1023
1022
|
var date2 = date2 || new Date(Date.now());
|
1024
1023
|
var diffS = date1.getTime()-date2.getTime();
|
1025
1024
|
var seconds = Math.round(diffS/1000);
|
1026
1025
|
return seconds;
|
1027
|
-
}
|
1026
|
+
}
|
1028
1027
|
|
1029
1028
|
/**
|
1030
1029
|
* Adds time to a date. Modelled after MySQL DATE_ADD function.
|
@@ -1052,16 +1051,16 @@ const puvox_library =
|
|
1052
1051
|
default : ret = undefined; break;
|
1053
1052
|
}
|
1054
1053
|
return ret;
|
1055
|
-
}
|
1054
|
+
}
|
1056
1055
|
// this approach is correct, the other one: https://pastebin_com/GwsScXx1 has strange bug in node, might relate to: https://stackoverflow.com/a/19691491/2377343
|
1057
1056
|
addSeconds(date, seconds){
|
1058
1057
|
return new Date( Date.parse(date) + seconds*1000 );
|
1059
|
-
}
|
1058
|
+
}
|
1060
1059
|
addDays(date, days){
|
1061
1060
|
var result = new Date(date);
|
1062
1061
|
result.setDate(result.getDate() + days);
|
1063
1062
|
return result;
|
1064
|
-
}
|
1063
|
+
}
|
1065
1064
|
daysBetween(a, b, utc = true){
|
1066
1065
|
// https://stackoverflow.com/a/15289883/2377343
|
1067
1066
|
const _MS_PER_DAY = 1000 * 60 * 60 * 24;
|
@@ -1076,7 +1075,7 @@ const puvox_library =
|
|
1076
1075
|
}
|
1077
1076
|
return Math.floor((d2 - d1) / _MS_PER_DAY);
|
1078
1077
|
}
|
1079
|
-
}
|
1078
|
+
})();
|
1080
1079
|
// ####### END OF DATETIME FUNCTIONS ####### //
|
1081
1080
|
|
1082
1081
|
|
@@ -1099,14 +1098,14 @@ const puvox_library =
|
|
1099
1098
|
el.parentNode.removeChild(el);
|
1100
1099
|
}
|
1101
1100
|
}
|
1102
|
-
}
|
1101
|
+
}
|
1103
1102
|
|
1104
1103
|
|
1105
1104
|
|
1106
1105
|
contains(string, pattern){
|
1107
1106
|
var re = new RegExp(pattern);
|
1108
1107
|
return (re.test(string));
|
1109
|
-
}
|
1108
|
+
}
|
1110
1109
|
|
1111
1110
|
hide_show_transprent(el, hide){
|
1112
1111
|
if(hide){
|
@@ -1117,11 +1116,11 @@ const puvox_library =
|
|
1117
1116
|
el.css("opacity", 1);
|
1118
1117
|
el.css("z-index", 0);
|
1119
1118
|
}
|
1120
|
-
}
|
1119
|
+
}
|
1121
1120
|
|
1122
1121
|
get_extension_from_url( url ) {
|
1123
1122
|
return url.split(/\#|\?/)[0].split('.').pop().trim();
|
1124
|
-
}
|
1123
|
+
}
|
1125
1124
|
|
1126
1125
|
|
1127
1126
|
// https://stackoverflow.com/a/7924240/2377343 (has better performance than (ch.match(/\n/g) || []).length or ch.split('\n').length - 1 )
|
@@ -1135,7 +1134,7 @@ const puvox_library =
|
|
1135
1134
|
if (pos >= 0) { ++n; pos += step; } else break;
|
1136
1135
|
}
|
1137
1136
|
return n;
|
1138
|
-
}
|
1137
|
+
}
|
1139
1138
|
|
1140
1139
|
// startReadStream(__dirname + '/aa.csv', ()=>{});
|
1141
1140
|
async readLineByLine (filePath, callback, linesSize = 10000, delimiterN = true) {
|
@@ -1173,7 +1172,7 @@ const puvox_library =
|
|
1173
1172
|
rejector();
|
1174
1173
|
});
|
1175
1174
|
return prom;
|
1176
|
-
}
|
1175
|
+
}
|
1177
1176
|
async linesAmountInFile(filePath, delimiterN = true) {
|
1178
1177
|
const self = this;
|
1179
1178
|
// calblack format: callback(linesArray, isLastChunk)
|
@@ -1197,7 +1196,7 @@ const puvox_library =
|
|
1197
1196
|
rejector();
|
1198
1197
|
});
|
1199
1198
|
return prom;
|
1200
|
-
}
|
1199
|
+
}
|
1201
1200
|
|
1202
1201
|
|
1203
1202
|
|
@@ -1205,16 +1204,16 @@ const puvox_library =
|
|
1205
1204
|
|
1206
1205
|
oneSpace(cc){
|
1207
1206
|
return cc.replace(/\s\s+/g, ' ');
|
1208
|
-
}
|
1207
|
+
}
|
1209
1208
|
removeFirstAndLastChar(cc){
|
1210
1209
|
return this.oneSpace( cc.substring(1, cc.length-1 ) );
|
1211
|
-
}
|
1210
|
+
}
|
1212
1211
|
getWithin_X(cc, x){
|
1213
1212
|
return this.oneSpace( cc.replace(new RegExp('(.*?)'+x+'(.*)'+x+'(.*)', 'g'), '$2') );
|
1214
|
-
}
|
1213
|
+
}
|
1215
1214
|
getWithin_XY(cc, x, y){
|
1216
1215
|
return this.oneSpace( cc.replace(new RegExp('(.*?)'+x+'(.*)'+y+'(.*)', 'g'), '$2') );
|
1217
|
-
}
|
1216
|
+
}
|
1218
1217
|
// https://stackoverflow.com/q/6462578/2377343
|
1219
1218
|
removeIfOutsideQuotes(content, replaceWhat, replaceWith){
|
1220
1219
|
var regex = new RegExp('"[^"]+"|('+replaceWhat+')','g');
|
@@ -1223,31 +1222,31 @@ const puvox_library =
|
|
1223
1222
|
else return replaceWith;
|
1224
1223
|
});
|
1225
1224
|
return replaced;
|
1226
|
-
}
|
1225
|
+
}
|
1227
1226
|
// https://stackoverflow.com/questions/19414193/regex-extract-string-not-between-two-brackets
|
1228
1227
|
// https://stackoverflow.com/questions/62616023/regex-split-if-not-inside-the-two-characters
|
1229
1228
|
splitBy_X_NotInside_Y(str, x, y) //x: split by; y: not inside
|
1230
1229
|
{
|
1231
1230
|
return str.split( RegExp(x+'+(?=(?:(?:[^'+y+']*"){2})*[^'+y+']*$)', 'g' ) );
|
1232
|
-
}
|
1231
|
+
}
|
1233
1232
|
splitBy_X_NotInside_YZ(str, by, y, z) //x: split by; y&z: not inside
|
1234
1233
|
{
|
1235
1234
|
return str.split( RegExp(by+'+(?=(?:(?:[^'+y+']*"){2})*[^'+z+']*$)', 'g' ) );
|
1236
|
-
}
|
1235
|
+
}
|
1237
1236
|
splitOnlyFirstOccurence(str, what){
|
1238
1237
|
return str.split(new RegExp(what+'(.+)'));
|
1239
|
-
}
|
1238
|
+
}
|
1240
1239
|
//equal
|
1241
1240
|
splitByEqualNotInsideDoubleQuotes(str)
|
1242
1241
|
{
|
1243
1242
|
return str.split(/\=+(?=(?:(?:[^"]*"){2})*[^"]*$)/g);
|
1244
|
-
}
|
1243
|
+
}
|
1245
1244
|
//double equals
|
1246
1245
|
splitByEqualNotInsideDoubleQuotesAndDoubleEquals(str)
|
1247
1246
|
{
|
1248
1247
|
let newStr = str.replace(/==/g, "__DOUBLE_EQUAL__RAND294393494__");
|
1249
1248
|
return newStr.split(/\=+(?=(?:(?:[^"]*"){2})*[^"]*$)/g).map(x=> x.replace(/__DOUBLE_EQUAL__RAND294393494__/g,"==") );
|
1250
|
-
}
|
1249
|
+
}
|
1251
1250
|
|
1252
1251
|
splitByNotInside2(str, splitChar,notInsideCharStart,notInsideCharEnd)
|
1253
1252
|
{
|
@@ -1270,7 +1269,7 @@ const puvox_library =
|
|
1270
1269
|
}
|
1271
1270
|
|
1272
1271
|
if (currentPart) parts.push(currentPart);
|
1273
|
-
}
|
1272
|
+
}
|
1274
1273
|
|
1275
1274
|
// i.e. if you want to get from first to last correct brackets
|
1276
1275
|
// start ( "a1)" "b1)" 'c1)' ) aaaaa ) bbbbb ) cccccc)
|
@@ -1322,21 +1321,22 @@ const puvox_library =
|
|
1322
1321
|
}
|
1323
1322
|
}
|
1324
1323
|
return result;
|
1325
|
-
}
|
1324
|
+
}
|
1326
1325
|
|
1327
1326
|
// https://stackoverflow.com/questions/9621825/escape-a-variable-within-a-regular-expression
|
1328
1327
|
preg_quote(str, delimiter) {
|
1329
1328
|
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
|
1330
|
-
}
|
1329
|
+
}
|
1331
1330
|
escapeRegExp(string) {
|
1332
1331
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
1333
|
-
}
|
1332
|
+
}
|
1334
1333
|
|
1335
1334
|
splitStringIntoChars(str){
|
1336
1335
|
return str.split(/(?=[\s\S])/u);
|
1337
|
-
}
|
1336
|
+
}
|
1338
1337
|
|
1339
|
-
empty(MyVar){ return this.is_empty_or_undefined(MyVar);}
|
1338
|
+
empty(MyVar){ return this.is_empty_or_undefined(MyVar);}
|
1339
|
+
|
1340
1340
|
is_empty_or_undefined (MyVar)
|
1341
1341
|
{
|
1342
1342
|
return (
|
@@ -1358,7 +1358,7 @@ const puvox_library =
|
|
1358
1358
|
||
|
1359
1359
|
(/^\s*$/.test(MyVar))
|
1360
1360
|
);
|
1361
|
-
}
|
1361
|
+
}
|
1362
1362
|
isEmptyValue(input){
|
1363
1363
|
//input is considered empty value: falsy value (like null, undefined, '', except false and 0),
|
1364
1364
|
// string with white space characters only, empty array, empty object
|
@@ -1366,17 +1366,17 @@ const puvox_library =
|
|
1366
1366
|
((input instanceof String || typeof input === 'string') && !input.trim()) ||
|
1367
1367
|
(Array.isArray(input) && !input.length) ||
|
1368
1368
|
(input instanceof Object && !Object.keys(input).length);
|
1369
|
-
}
|
1369
|
+
}
|
1370
1370
|
removeEmptyValue (obj) {
|
1371
1371
|
if (!(obj instanceof Object))
|
1372
1372
|
return {};
|
1373
1373
|
Object.keys(obj).forEach(key => this.isEmptyValue(obj[key]) && delete obj[key]);
|
1374
1374
|
return obj;
|
1375
|
-
}
|
1375
|
+
}
|
1376
1376
|
isIterable(obj) {
|
1377
1377
|
if (obj == null) { return false; }
|
1378
1378
|
return typeof obj[Symbol.iterator] === 'function';
|
1379
|
-
}
|
1379
|
+
}
|
1380
1380
|
insertRedErrorLine(array_){
|
1381
1381
|
var array = array_;
|
1382
1382
|
array["position"] = array["position"] || "before";
|
@@ -1392,7 +1392,7 @@ const puvox_library =
|
|
1392
1392
|
$(this).hide();
|
1393
1393
|
}
|
1394
1394
|
);
|
1395
|
-
}
|
1395
|
+
}
|
1396
1396
|
|
1397
1397
|
// more from locutus: https://github.com/locutusjs/locutus/blob/master/src/php
|
1398
1398
|
stripTags (input, allowed) {
|
@@ -1402,9 +1402,9 @@ const puvox_library =
|
|
1402
1402
|
return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
|
1403
1403
|
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
|
1404
1404
|
});
|
1405
|
-
}
|
1405
|
+
}
|
1406
1406
|
|
1407
|
-
br2nl(content) { return content.replace('/\<br(\s*)?\/?\>/i', "\n"); }
|
1407
|
+
br2nl(content) { return content.replace('/\<br(\s*)?\/?\>/i', "\n"); }
|
1408
1408
|
|
1409
1409
|
jquery_popup(element, isModal, params){
|
1410
1410
|
var isModal = isModal || true;
|
@@ -1430,7 +1430,7 @@ const puvox_library =
|
|
1430
1430
|
$("#custom_overlay").remove();
|
1431
1431
|
}
|
1432
1432
|
});
|
1433
|
-
}
|
1433
|
+
}
|
1434
1434
|
jquery_popup_once(cookiename, key, text, duration, onComplete){
|
1435
1435
|
var text = text;
|
1436
1436
|
var cookieVal = this.Cookies.getOption(cookiename, "popup_shown_"+key, "true");
|
@@ -1446,7 +1446,7 @@ const puvox_library =
|
|
1446
1446
|
else{
|
1447
1447
|
onComplete();
|
1448
1448
|
}
|
1449
|
-
}
|
1449
|
+
}
|
1450
1450
|
|
1451
1451
|
jquery_popup_one_time_checkbox(cookiename, key, text, callable_func, defaultCheckboxTxt){
|
1452
1452
|
var defaultCheckboxTxt = defaultCheckboxTxt || '<div class="dialog_dont_show_again" style=" bottom:0; right:0; font-size:0.7em; background:#e7e7e7; width:100%; margin: 2px; padding: 2px; display: inline-block;"><input type="checkbox" onclick="PuvoxLibrary.dialog_dont_show_again(event, \''+key+'\', \''+cookiename+'\')" /><span class="dont_show_again_inner">Don\'t show this window again</span></div>';
|
@@ -1462,23 +1462,22 @@ const puvox_library =
|
|
1462
1462
|
{
|
1463
1463
|
callable_func();
|
1464
1464
|
}
|
1465
|
-
}
|
1465
|
+
}
|
1466
1466
|
dialog_dont_show_again(event, key, cookiename)
|
1467
1467
|
{
|
1468
1468
|
this.Cookies.setOption(cookiename, "popup_checkbox_"+key, (event.target.checked ? "false" : "true") );
|
1469
|
-
}
|
1469
|
+
}
|
1470
1470
|
|
1471
1471
|
dialogClose(){
|
1472
1472
|
window.parent.$('.ui-dialog-content:visible').dialog('close');
|
1473
|
-
}
|
1474
|
-
|
1475
|
-
|
1473
|
+
}
|
1476
1474
|
|
1477
1475
|
|
1476
|
+
|
1478
1477
|
mergeObjects(obj1, obj2){
|
1479
1478
|
for (var attrname in obj2) { obj1[attrname] = obj2[attrname]; }
|
1480
1479
|
return obj1;
|
1481
|
-
}
|
1480
|
+
}
|
1482
1481
|
|
1483
1482
|
// returns a new object with the values at each key mapped using mapFn(value)
|
1484
1483
|
objectMap(obj, fn) {
|
@@ -1487,7 +1486,7 @@ const puvox_library =
|
|
1487
1486
|
([k, v], i) => [k, fn(v, k, i)]
|
1488
1487
|
)
|
1489
1488
|
)
|
1490
|
-
}
|
1489
|
+
}
|
1491
1490
|
|
1492
1491
|
fancyTimeFormat(time)
|
1493
1492
|
{
|
@@ -1506,7 +1505,7 @@ const puvox_library =
|
|
1506
1505
|
ret += "" + mins + ":" + (secs < 10 ? "0" : "");
|
1507
1506
|
ret += "" + secs;
|
1508
1507
|
return ret;
|
1509
|
-
}
|
1508
|
+
}
|
1510
1509
|
|
1511
1510
|
getYtIdFromURL(URL_or_ID){
|
1512
1511
|
var id;
|
@@ -1519,7 +1518,7 @@ const puvox_library =
|
|
1519
1518
|
id = r[1];
|
1520
1519
|
}
|
1521
1520
|
return id;
|
1522
|
-
}
|
1521
|
+
}
|
1523
1522
|
|
1524
1523
|
//
|
1525
1524
|
jsonToArray(json_data){
|
@@ -1527,16 +1526,16 @@ const puvox_library =
|
|
1527
1526
|
//for(var i in json_data) result.push([i, json_data[i]]);
|
1528
1527
|
result = Object.keys(json_data).map((key) => [key, json_data[key]]);
|
1529
1528
|
return result;
|
1530
|
-
}
|
1529
|
+
}
|
1531
1530
|
|
1532
1531
|
fixEntitiedJson(json_data){
|
1533
1532
|
return json_data.replace(/"/g,'"');
|
1534
|
-
}
|
1533
|
+
}
|
1535
1534
|
|
1536
1535
|
|
1537
1536
|
setSelectByOptionName(selectEl, optName){
|
1538
1537
|
selectEl.find('option').filter(function () { var txt=$(this).html(); return (txt==optName); }).prop('selected', true);
|
1539
|
-
}
|
1538
|
+
}
|
1540
1539
|
ScrollTo(el, func, offset_distance) //setHashInAddress
|
1541
1540
|
{
|
1542
1541
|
var offset_distance= offset_distance || 0;
|
@@ -1544,29 +1543,29 @@ const puvox_library =
|
|
1544
1543
|
$('html, body').animate({
|
1545
1544
|
scrollTop: $(el).offset().top - offset_distance
|
1546
1545
|
}, 1000, func);
|
1547
|
-
}
|
1546
|
+
}
|
1548
1547
|
sleep(ms) {
|
1549
1548
|
return new Promise(resolve => this.setTimeout_safe(resolve, ms));
|
1550
|
-
}
|
1549
|
+
}
|
1551
1550
|
// immitating ccxt setTimeout
|
1552
1551
|
setTimeout_safe (done, ms) {
|
1553
1552
|
const self = this; const targetTime = Date.now() + ms; if (ms >= 2147483647) { throw new Error ('setTimeout() function was called with unrealistic value of ' + ms.toString ()); } let clearInnerTimeout = () => {}; let active = true; const id = setTimeout (() => { active = true; const rest = targetTime - Date.now (); if (rest > 0) { clearInnerTimeout = self.setTimeout_safe (done, rest, setTimeout, targetTime); } else { done (); } }, ms); return function clear () { if (active) { active = false; clearTimeout (id); } clearInnerTimeout (); };
|
1554
|
-
}
|
1553
|
+
}
|
1555
1554
|
|
1556
1555
|
scrollToBottom2(el) //setHashInAddress
|
1557
1556
|
{
|
1558
1557
|
if (el && el[0])
|
1559
1558
|
el.scrollTop(el[0].scrollHeight - el.height());
|
1560
|
-
}
|
1559
|
+
}
|
1561
1560
|
scrollToBottom(el_or_id) {
|
1562
1561
|
var el = this.isObject(el_or_id) ? el_or_id : document.querySelector(el_or_id);
|
1563
1562
|
el.scrollTop = el.scrollHeight - el.clientHeight;
|
1564
|
-
}
|
1563
|
+
}
|
1565
1564
|
|
1566
1565
|
scrollToBottom3(el_or_id) {
|
1567
1566
|
var el = this.isObject(el_or_id) ? el_or_id : document.querySelector(el_or_id);
|
1568
1567
|
el.scrollTop(el.scrollHeight - el.height());
|
1569
|
-
}
|
1568
|
+
}
|
1570
1569
|
|
1571
1570
|
|
1572
1571
|
// scroll to
|
@@ -1575,18 +1574,18 @@ const puvox_library =
|
|
1575
1574
|
$('html, body').animate({
|
1576
1575
|
scrollTop: $(selector).offset().top-100
|
1577
1576
|
}, 1000);
|
1578
|
-
}
|
1577
|
+
}
|
1579
1578
|
|
1580
1579
|
|
1581
1580
|
addLine(selector, text, first_or_last){
|
1582
1581
|
let elem = this.isObject(selector) ? selector : document.querySelector(selector);
|
1583
1582
|
elem.insertAdjacentHTML("beforeend", "\r\n - "+text);
|
1584
|
-
}
|
1583
|
+
}
|
1585
1584
|
removeLine(selector, first_or_last, ifMoreThanXlines) {
|
1586
1585
|
let elem = this.isObject(selector) ? selector : document.querySelector(selector);
|
1587
1586
|
//c( "a"+this.removeLineFromText(elem.innerHTML, first_or_last, ifMoreThanXlines));
|
1588
1587
|
elem.innerHTML = this.removeElementFromElement(elem.innerHTML, first_or_last, ifMoreThanXlines);
|
1589
|
-
}
|
1588
|
+
}
|
1590
1589
|
|
1591
1590
|
removeElementIfMoreThan(el, amount, first_or_last){
|
1592
1591
|
let childs = el.children;
|
@@ -1594,13 +1593,13 @@ const puvox_library =
|
|
1594
1593
|
{
|
1595
1594
|
el.children[0].remove();
|
1596
1595
|
}
|
1597
|
-
}
|
1596
|
+
}
|
1598
1597
|
|
1599
1598
|
removeElementIfMoreThanNEW(el, amount, first_or_last){
|
1600
1599
|
let newEl = el.cloneNode(true);
|
1601
1600
|
this.removeElementIfMoreThan(newEl, amount, first_or_last);
|
1602
1601
|
return newEl;
|
1603
|
-
}
|
1602
|
+
}
|
1604
1603
|
|
1605
1604
|
// if(setHashInAddress) { window.location.hash = id_or_Name; }
|
1606
1605
|
removeLine_old(selector, first_or_last, ifMoreThanXlines) {
|
@@ -1617,12 +1616,12 @@ const puvox_library =
|
|
1617
1616
|
else val.pop();
|
1618
1617
|
}
|
1619
1618
|
elem.value=val.join('\n') + '\r\n';
|
1620
|
-
}
|
1619
|
+
}
|
1621
1620
|
|
1622
1621
|
removeLineFromTextarea(selector, first_or_last, ifMoreThanXlines) {
|
1623
1622
|
let elem = document.querySelector(selector);
|
1624
1623
|
elem.value = this.removeLineFromText(elem.value, first_or_last, ifMoreThanXlines);
|
1625
|
-
}
|
1624
|
+
}
|
1626
1625
|
removeLineFromText(text, first_or_last, ifMoreThanXlines)
|
1627
1626
|
{
|
1628
1627
|
var ifMoreThanXlines= ifMoreThanXlines || 0;
|
@@ -1638,22 +1637,22 @@ const puvox_library =
|
|
1638
1637
|
else val.pop();
|
1639
1638
|
return val.join('\n') + '\r\n';
|
1640
1639
|
}
|
1641
|
-
}
|
1640
|
+
}
|
1642
1641
|
|
1643
1642
|
|
1644
1643
|
arrayColumn(array, col)
|
1645
1644
|
{
|
1646
1645
|
return array.map(function(value,index) { return value[col]; });
|
1647
|
-
}
|
1646
|
+
}
|
1648
1647
|
arrayPart(array_, amount_, from)
|
1649
1648
|
{
|
1650
1649
|
var from = from || 'start'; //start|end
|
1651
1650
|
let count = array_.length;
|
1652
1651
|
return count<=amount_ ? array_ : ( from=='start' ? array_.slice(0, amount_) : array_.slice(-amount_) );
|
1653
|
-
}
|
1652
|
+
}
|
1654
1653
|
arrayInsertAt(array, index, value){
|
1655
1654
|
return array.splice(index, 0, value);
|
1656
|
-
}
|
1655
|
+
}
|
1657
1656
|
executeAfterTry(el, func, num)
|
1658
1657
|
{
|
1659
1658
|
var num=num || 0;
|
@@ -1664,14 +1663,14 @@ const puvox_library =
|
|
1664
1663
|
if( $(el).length ) func();
|
1665
1664
|
else setTimeout( function(){ this_.executeAfterTry(el, func, num+1); }, 100 );
|
1666
1665
|
}
|
1667
|
-
}
|
1666
|
+
}
|
1668
1667
|
|
1669
1668
|
waitExecute(el, func)
|
1670
1669
|
{
|
1671
1670
|
var this_ = this;
|
1672
1671
|
if( jQuery(el).length ) func();
|
1673
1672
|
else setTimeout( function(){ this_.waitExecute(el, func); }, 700 );
|
1674
|
-
}
|
1673
|
+
}
|
1675
1674
|
|
1676
1675
|
// https://stackoverflow.com/a/41407246/2377343
|
1677
1676
|
consoleLogColor (text, backgroundColor=null, foregroundColor=null) {
|
@@ -1691,10 +1690,10 @@ const puvox_library =
|
|
1691
1690
|
foreColorString = prefix + objectTree['foreground'][foregroundColor] + suffix;
|
1692
1691
|
}
|
1693
1692
|
console.log (backColorString + foreColorString + "%s" + prefix + objectTree.types.reset + suffix, text);
|
1694
|
-
}
|
1693
|
+
}
|
1695
1694
|
|
1696
|
-
toggleWindowsMessages_WindowConfirm() { return window.confirm }
|
1697
|
-
toggleWindowsMessages_WindowAlert() { return window.alert }
|
1695
|
+
toggleWindowsMessages_WindowConfirm() { return window.confirm }
|
1696
|
+
toggleWindowsMessages_WindowAlert() { return window.alert }
|
1698
1697
|
toggleWindowsMessages(enable){
|
1699
1698
|
if (enable)
|
1700
1699
|
{
|
@@ -1706,7 +1705,7 @@ const puvox_library =
|
|
1706
1705
|
window.confirm = function() { return true; };
|
1707
1706
|
window.alert = function() {};
|
1708
1707
|
}
|
1709
|
-
}
|
1708
|
+
}
|
1710
1709
|
suspressMessagesExecution(func){
|
1711
1710
|
var alert_ = window.alert;
|
1712
1711
|
var confirm_= window.confirm;
|
@@ -1715,7 +1714,7 @@ const puvox_library =
|
|
1715
1714
|
func();
|
1716
1715
|
window.confirm = alert_;
|
1717
1716
|
window.alert = confirm_;
|
1718
|
-
}
|
1717
|
+
}
|
1719
1718
|
|
1720
1719
|
|
1721
1720
|
MakeIframeFullHeight (iframeElement, cycling, overwrite_margin){
|
@@ -1738,14 +1737,14 @@ const puvox_library =
|
|
1738
1737
|
})();
|
1739
1738
|
//var funcname= arguments.callee.name;
|
1740
1739
|
//window.setTimeout( function(){ console.log(funcname); console.log(cycling); window[funcname](iframeElement, cycling); }, 500 );
|
1741
|
-
}
|
1740
|
+
}
|
1742
1741
|
|
1743
1742
|
in_array(needle, haystack) {
|
1744
1743
|
for(var i in haystack) {
|
1745
1744
|
if(haystack[i] == needle) return true;
|
1746
1745
|
}
|
1747
1746
|
return false;
|
1748
|
-
}
|
1747
|
+
}
|
1749
1748
|
|
1750
1749
|
CreateFrameIn(targetEl, frameContent, MakeItfullWH){
|
1751
1750
|
var MakeItfullWH = MakeItfullWH || false;
|
@@ -1760,7 +1759,7 @@ const puvox_library =
|
|
1760
1759
|
this.MakeIframeFullHeight(iframe);
|
1761
1760
|
}
|
1762
1761
|
return iframe;
|
1763
|
-
}
|
1762
|
+
}
|
1764
1763
|
|
1765
1764
|
makeAllATargetBlank(el){
|
1766
1765
|
if(!el) return;
|
@@ -1770,7 +1769,7 @@ const puvox_library =
|
|
1770
1769
|
els[i].setAttribute("target", "_blank");
|
1771
1770
|
}
|
1772
1771
|
}
|
1773
|
-
}
|
1772
|
+
}
|
1774
1773
|
|
1775
1774
|
createDropdownFrom(arr, elementId, jqueriUi, appendToElement){
|
1776
1775
|
var jqueriUi = jqueriUi || false;
|
@@ -1786,7 +1785,7 @@ const puvox_library =
|
|
1786
1785
|
$(elementId).selectmenu();
|
1787
1786
|
}
|
1788
1787
|
return html;
|
1789
|
-
}
|
1788
|
+
}
|
1790
1789
|
|
1791
1790
|
//=====
|
1792
1791
|
|
@@ -1798,33 +1797,33 @@ const puvox_library =
|
|
1798
1797
|
function toSolidBytes(match, p1) {
|
1799
1798
|
return String.fromCharCode('0x' + p1);
|
1800
1799
|
}));
|
1801
|
-
}
|
1800
|
+
}
|
1802
1801
|
|
1803
1802
|
b64DecodeUnicode(str) {
|
1804
1803
|
// Going backwards: from bytestream, to percent-encoding, to original string.
|
1805
1804
|
return decodeURIComponent(atob(str).split('').map(function(c) {
|
1806
1805
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
1807
1806
|
}).join(''));
|
1808
|
-
}
|
1807
|
+
}
|
1809
1808
|
|
1810
1809
|
round(num,decimals){
|
1811
1810
|
let v=Math.pow(10,decimals); return Math.round((num + Number.EPSILON) * v) / v; //toFixed
|
1812
|
-
}
|
1811
|
+
}
|
1813
1812
|
|
1814
1813
|
|
1815
|
-
|
1816
1814
|
|
1817
1815
|
// ============================= get basename of url ============================
|
1818
|
-
basename(path) { return path.split('/').reverse()[0]; }
|
1816
|
+
basename(path) { return path.split('/').reverse()[0]; }
|
1819
1817
|
|
1820
1818
|
|
1821
1819
|
// ======== simple POPUP ======== https://github.com/ttodua/useful-javascript/ ==============
|
1822
1820
|
show_my_popup(TEXTorID, AdditionalStyles ){
|
1823
1821
|
TEXTorID=TEXTorID.trim(); var FirstChar= TEXTorID.charAt(0); var eName = TEXTorID.substr(1); if ('#'==FirstChar || '.'==FirstChar){ if('#'==FirstChar){var x=document.getElementById(eName);} else{var x=document.getElementsByClassName(eName)[0];}} else { var x=document.createElement('div');x.innerHTML=TEXTorID;} var randm_id=Math.floor((Math.random()*100000000));
|
1824
1822
|
var DivAA = document.createElement('div'); DivAA.id = "blkBackgr_"+randm_id; DivAA.className = "MyJsBackg"; DivAA.setAttribute("style", 'background:black; height:5000px; left:0px; opacity:0.9; position:fixed; top:0px; width:100%; z-index:99995;'); document.body.appendChild(DivAA); AdditionalStyles= AdditionalStyles || '';
|
1825
|
-
var DivBB = document.createElement('div'); DivBB.id = 'popupp_'+randm_id; DivBB.className = "MyJsPopup"; DivBB.setAttribute("style",'background-color:white; border:6px solid white; border-radius:10px; display:block; min-height:1%; min-width:350px; width:auto; overflow:auto; max-height:80%; max-width:800px; padding:15px; position:fixed; text-align:left; top:10%; z-index:99995; left:0px; right:0px; margin-left:auto; margin-right:auto; width:80%;'+ AdditionalStyles); DivBB.innerHTML = '<div style="background-color:#C0BCBF; border-radius:55px; padding:5px; font-family:arial; float:right; font-weight:700; margin:-15px -10px 0px 0px; z-index: 88; " class="CloseButtn" ><a href="javascript:my_popup_closee('+randm_id+');" style="display:block;margin:-5px 0 0 0;font-size:1.6em;">x</a></div>'; document.body.appendChild(DivBB);z=x.cloneNode(true);DivBB.appendChild(z); if(z.style.display=="none"){z.style.display="block";}
|
1826
|
-
|
1827
|
-
|
1823
|
+
var DivBB = document.createElement('div'); DivBB.id = 'popupp_'+randm_id; DivBB.className = "MyJsPopup"; DivBB.setAttribute("style",'background-color:white; border:6px solid white; border-radius:10px; display:block; min-height:1%; min-width:350px; width:auto; overflow:auto; max-height:80%; max-width:800px; padding:15px; position:fixed; text-align:left; top:10%; z-index:99995; left:0px; right:0px; margin-left:auto; margin-right:auto; width:80%;'+ AdditionalStyles); DivBB.innerHTML = '<div style="background-color:#C0BCBF; border-radius:55px; padding:5px; font-family:arial; float:right; font-weight:700; margin:-15px -10px 0px 0px; z-index: 88; " class="CloseButtn" ><a href="javascript:my_popup_closee('+randm_id+');" style="display:block;margin:-5px 0 0 0;font-size:1.6em;">x</a></div>'; document.body.appendChild(DivBB);z=x.cloneNode(true);DivBB.appendChild(z); if(z.style.display=="none"){z.style.display="block";}
|
1824
|
+
}
|
1825
|
+
my_popup_closee(RandomIDD) { var x=document.getElementById("blkBackgr_"+RandomIDD); x.parentNode.removeChild(x); var x=document.getElementById('popupp_'+RandomIDD); x.parentNode.removeChild(x);
|
1826
|
+
}
|
1828
1827
|
// ========================================================== //
|
1829
1828
|
|
1830
1829
|
|
@@ -1834,7 +1833,7 @@ const puvox_library =
|
|
1834
1833
|
loaderImage(circleColor){
|
1835
1834
|
var circlecolor=circleColor || '#ffffff';
|
1836
1835
|
return '<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" width="90px" height="90px" viewBox="0 0 128 128" xml:space="preserve"><g><circle cx="16" cy="64" r="16" fill="'+circlecolor+'" fill-opacity="1"/><circle cx="16" cy="64" r="16" fill="'+circlecolor+'" fill-opacity="0.67" transform="rotate(45,64,64)"/><circle cx="16" cy="64" r="16" fill="#ffffff" fill-opacity="0.42" transform="rotate(90,64,64)"/><circle cx="16" cy="64" r="16" fill="'+circlecolor+'" fill-opacity="0.2" transform="rotate(135,64,64)"/><circle cx="16" cy="64" r="16" fill="'+circlecolor+'" fill-opacity="0.12" transform="rotate(180,64,64)"/><circle cx="16" cy="64" r="16" fill="'+circlecolor+'" fill-opacity="0.12" transform="rotate(225,64,64)"/><circle cx="16" cy="64" r="16" fill="'+circlecolor+'" fill-opacity="0.12" transform="rotate(270,64,64)"/><circle cx="16" cy="64" r="16" fill="'+circlecolor+'" fill-opacity="0.12" transform="rotate(315,64,64)"/><animateTransform attributeName="transform" type="rotate" values="0 64 64;315 64 64;270 64 64;225 64 64;180 64 64;135 64 64;90 64 64;45 64 64" calcMode="discrete" dur="720ms" repeatCount="indefinite"></animateTransform></g></svg>';
|
1837
|
-
}
|
1836
|
+
}
|
1838
1837
|
Loader(ShowOrHide, style, content_To_show)
|
1839
1838
|
{
|
1840
1839
|
var elementID = 'waiter_box_p';
|
@@ -1855,7 +1854,7 @@ const puvox_library =
|
|
1855
1854
|
else{
|
1856
1855
|
var x =document.getElementById(elementID); if (x) x.parentNode.removeChild(x);
|
1857
1856
|
}
|
1858
|
-
}
|
1857
|
+
}
|
1859
1858
|
// ========================================================== //
|
1860
1859
|
|
1861
1860
|
|
@@ -1870,7 +1869,7 @@ const puvox_library =
|
|
1870
1869
|
xmlhttp.open(method,url, true);
|
1871
1870
|
if (method == "post"){xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send(parameters);}
|
1872
1871
|
else if (method == "get"){xmlhttp.send(null);}
|
1873
|
-
}
|
1872
|
+
}
|
1874
1873
|
// ========================================================== //
|
1875
1874
|
|
1876
1875
|
|
@@ -1880,7 +1879,7 @@ const puvox_library =
|
|
1880
1879
|
for (index = 0; index < elmnts.length; ++index) {
|
1881
1880
|
elmnts[index].style.display= "none"; //elmnts[index].className = elmnts[index].className + " my_css_hide_class";
|
1882
1881
|
}
|
1883
|
-
}
|
1882
|
+
}
|
1884
1883
|
//window.onload = function(){ if(typeof MyTargetHideClass ==='String') hide_popuping_divs(MyTargetHideClass); };
|
1885
1884
|
|
1886
1885
|
get(url, parameters) {
|
@@ -1915,10 +1914,10 @@ const puvox_library =
|
|
1915
1914
|
// Make the request
|
1916
1915
|
req.send(params_);
|
1917
1916
|
});
|
1918
|
-
}
|
1917
|
+
}
|
1919
1918
|
getJSON(url, parameters) {
|
1920
1919
|
return this.get(url, parameters).then(JSON.parse);
|
1921
|
-
}
|
1920
|
+
}
|
1922
1921
|
|
1923
1922
|
post(url, params, callback_1, callback_2){
|
1924
1923
|
return fetch(url, {
|
@@ -1929,16 +1928,16 @@ const puvox_library =
|
|
1929
1928
|
callback_1(text);
|
1930
1929
|
});
|
1931
1930
|
}); // .then(function(data) { callback_error(data); });
|
1932
|
-
}
|
1931
|
+
}
|
1933
1932
|
|
1934
1933
|
|
1935
1934
|
stringifyPretty(obj){
|
1936
1935
|
return JSON.stringify(obj, null, 2);
|
1937
|
-
}
|
1936
|
+
}
|
1938
1937
|
|
1939
1938
|
responseStringify(obj_or_text){
|
1940
1939
|
return ! this.is_object(obj_or_text) ? obj_or_text : ( 'responseText' in obj_or_text ? obj_or_text.responseText : JSON.stringify(obj_or_text) );
|
1941
|
-
}
|
1940
|
+
}
|
1942
1941
|
// ============================= getElementById from parent_node ========== http://stackoverflow.com/a/5683184/2377343 ==========
|
1943
1942
|
//Element.prototype.getElementById_FROM_PARENT = function(req) {
|
1944
1943
|
getElementById_FROM_PARENT(req) {
|
@@ -1951,16 +1950,16 @@ const puvox_library =
|
|
1951
1950
|
else {id=elem.getElementById_FROM_PARENT(req); if(id) return id;} // otherwise, search recursively within the child
|
1952
1951
|
}
|
1953
1952
|
return null; // if no match found
|
1954
|
-
}
|
1953
|
+
}
|
1955
1954
|
// ========================================================== //
|
1956
1955
|
|
1957
1956
|
|
1958
1957
|
inArray(needle, haystack) {
|
1959
1958
|
return haystack.indexOf(needle) > -1;
|
1960
|
-
}
|
1959
|
+
}
|
1961
1960
|
inKeys(key, obj){
|
1962
1961
|
return key in obj;
|
1963
|
-
}
|
1962
|
+
}
|
1964
1963
|
|
1965
1964
|
partialObject(object_, array_) {
|
1966
1965
|
let newObj ={};
|
@@ -1970,7 +1969,7 @@ const puvox_library =
|
|
1970
1969
|
}
|
1971
1970
|
}
|
1972
1971
|
return newObj;
|
1973
|
-
}
|
1972
|
+
}
|
1974
1973
|
|
1975
1974
|
|
1976
1975
|
array_column_with_keys(object_, keyName_) {
|
@@ -1980,7 +1979,7 @@ const puvox_library =
|
|
1980
1979
|
new_[key_] = value_[keyName_];
|
1981
1980
|
}
|
1982
1981
|
return new_;
|
1983
|
-
}
|
1982
|
+
}
|
1984
1983
|
|
1985
1984
|
|
1986
1985
|
// ============================= URL parameters ============================= //
|
@@ -2011,7 +2010,7 @@ const puvox_library =
|
|
2011
2010
|
}
|
2012
2011
|
}
|
2013
2012
|
return query_string;
|
2014
|
-
}
|
2013
|
+
}
|
2015
2014
|
|
2016
2015
|
// executed below
|
2017
2016
|
URLParser(url){
|
@@ -2137,7 +2136,7 @@ const puvox_library =
|
|
2137
2136
|
});
|
2138
2137
|
}
|
2139
2138
|
return obj;
|
2140
|
-
}
|
2139
|
+
}
|
2141
2140
|
/*
|
2142
2141
|
http://www.example.com:8082/index.php#tab2?foo=789
|
2143
2142
|
|
@@ -2171,7 +2170,7 @@ const puvox_library =
|
|
2171
2170
|
// });
|
2172
2171
|
// request.on('end', function(){ callback(qs.parse(stringData)); } );
|
2173
2172
|
}
|
2174
|
-
}
|
2173
|
+
}
|
2175
2174
|
|
2176
2175
|
|
2177
2176
|
|
@@ -2198,7 +2197,7 @@ const puvox_library =
|
|
2198
2197
|
|
2199
2198
|
el.attr("href", CurrentUrlReplaced);
|
2200
2199
|
});
|
2201
|
-
}
|
2200
|
+
}
|
2202
2201
|
|
2203
2202
|
|
2204
2203
|
//replace parameter in query string
|
@@ -2210,22 +2209,22 @@ const puvox_library =
|
|
2210
2209
|
var part= param_name+'='+variations[eachProp]; if (url.indexOf(part) >= 0){url = url.replace(part, param_name+'='+param_new_val); }
|
2211
2210
|
}
|
2212
2211
|
return url;
|
2213
|
-
}
|
2212
|
+
}
|
2214
2213
|
|
2215
2214
|
|
2216
2215
|
|
2217
2216
|
//if referrer is from same domain
|
2218
|
-
refferer_is_same_domain(){ return document.referrer.indexOf(location.host) > -1;}
|
2217
|
+
refferer_is_same_domain(){ return document.referrer.indexOf(location.host) > -1;}
|
2219
2218
|
//prevent default, better function
|
2220
|
-
DoPrevent(e) { e.preventDefault(); e.stopPropagation(); }
|
2219
|
+
DoPrevent(e) { e.preventDefault(); e.stopPropagation(); }
|
2221
2220
|
preventDefaultForAll(instantly){
|
2222
2221
|
var func = function(){ document.querySelectorAll('.preventDefault').forEach( function(item){ item.addEventListener('click', function(e){ e.preventDefault(); }); } ); };
|
2223
2222
|
if (instantly || false) func();
|
2224
2223
|
else this.trigger_on_load(func);
|
2225
|
-
}
|
2224
|
+
}
|
2226
2225
|
|
2227
2226
|
//add hovered class on element
|
2228
|
-
addHovered(elem){ if( elem.hasClass("hoveredd")) { elem.removeClass("hoveredd");} else { elem.addClass("hoveredd"); } }
|
2227
|
+
addHovered(elem){ if( elem.hasClass("hoveredd")) { elem.removeClass("hoveredd");} else { elem.addClass("hoveredd"); } }
|
2229
2228
|
// ========================================================== //
|
2230
2229
|
|
2231
2230
|
|
@@ -2241,7 +2240,7 @@ const puvox_library =
|
|
2241
2240
|
var x = jQuery(target_hidding_selector);
|
2242
2241
|
if( jQuery(selector+':checked').val() == desiredvalue) {if(SHOW_or_hide) x.show(); else x.hide();}
|
2243
2242
|
else {if(SHOW_or_hide) x.hide(); else x.show();}
|
2244
|
-
}
|
2243
|
+
}
|
2245
2244
|
|
2246
2245
|
// string.containss(smth)
|
2247
2246
|
// if (window.String && String.prototype && !String.prototype.containss) String.prototype.containss = function(arg) { return (this.indexOf(arg) > -1); }
|
@@ -2249,7 +2248,7 @@ const puvox_library =
|
|
2249
2248
|
// get random from array
|
2250
2249
|
GetRandomFromArray(my_array){
|
2251
2250
|
return my_array[this.random_number_minmax(0, my_array.length-1)];
|
2252
|
-
}
|
2251
|
+
}
|
2253
2252
|
// make array random
|
2254
2253
|
array_shuffle(array) {
|
2255
2254
|
var currentIndex = array.length, temporaryValue, randomIndex;
|
@@ -2264,7 +2263,7 @@ const puvox_library =
|
|
2264
2263
|
array[randomIndex] = temporaryValue;
|
2265
2264
|
}
|
2266
2265
|
return array;
|
2267
|
-
}
|
2266
|
+
}
|
2268
2267
|
|
2269
2268
|
|
2270
2269
|
// ============================= youtube modal popup ============================= //
|
@@ -2301,14 +2300,14 @@ const puvox_library =
|
|
2301
2300
|
});
|
2302
2301
|
}
|
2303
2302
|
if(options.oncall != ''){ window[options.oncall](); }
|
2304
|
-
}
|
2303
|
+
}
|
2305
2304
|
|
2306
2305
|
FadeOut_modalpp(){
|
2307
2306
|
$(".yt-modal").fadeOut(350, function() {
|
2308
2307
|
$(this).remove();
|
2309
2308
|
$(".modal-bg").remove();
|
2310
2309
|
});
|
2311
|
-
}
|
2310
|
+
}
|
2312
2311
|
// ============================= Youtube popup ============================= //
|
2313
2312
|
|
2314
2313
|
|
@@ -2320,7 +2319,7 @@ const puvox_library =
|
|
2320
2319
|
}
|
2321
2320
|
}
|
2322
2321
|
};
|
2323
|
-
}
|
2322
|
+
}
|
2324
2323
|
forEachDefine2(){
|
2325
2324
|
if (!Object.prototype.forEach2) {
|
2326
2325
|
Object.defineProperty(Object.prototype, 'forEach2', {
|
@@ -2337,7 +2336,7 @@ const puvox_library =
|
|
2337
2336
|
}
|
2338
2337
|
});
|
2339
2338
|
}
|
2340
|
-
}
|
2339
|
+
}
|
2341
2340
|
filterDefine(){
|
2342
2341
|
Object.filter2 = function( obj, predicate) {
|
2343
2342
|
let result = {}, key;
|
@@ -2350,7 +2349,7 @@ const puvox_library =
|
|
2350
2349
|
|
2351
2350
|
return result;
|
2352
2351
|
};
|
2353
|
-
}
|
2352
|
+
}
|
2354
2353
|
filterDefine2(){
|
2355
2354
|
if (!Object.prototype.filter2) {
|
2356
2355
|
Object.defineProperty(Object.prototype, 'filter2', {
|
@@ -2373,10 +2372,10 @@ const puvox_library =
|
|
2373
2372
|
}
|
2374
2373
|
});
|
2375
2374
|
}
|
2376
|
-
}
|
2375
|
+
}
|
2377
2376
|
|
2378
2377
|
|
2379
|
-
var_dump(array){ var o=""; for (x in array) { o += x + ": " + array[x]+"; "; } window.console && console.log(o); }
|
2378
|
+
var_dump(array){ var o=""; for (x in array) { o += x + ": " + array[x]+"; "; } window.console && console.log(o); }
|
2380
2379
|
|
2381
2380
|
// ============================= POST REQUEST SEND (LIVE FORM CREATION) ============================= //
|
2382
2381
|
//USAGE: postForm( {deletecityy:'hihi', surname: 'blabla'}, 'Are you sure?' , 'http://yoursite.com' , '_blank');
|
@@ -2396,7 +2395,7 @@ const puvox_library =
|
|
2396
2395
|
}
|
2397
2396
|
}
|
2398
2397
|
document.body.appendChild(form); form.submit();
|
2399
|
-
}
|
2398
|
+
}
|
2400
2399
|
// ==========================================================
|
2401
2400
|
|
2402
2401
|
|
@@ -2408,7 +2407,7 @@ const puvox_library =
|
|
2408
2407
|
var NewClass = document.createElement('div');NewClass.innerHTML='.myHintClass{position:absolute; background:#eeeeee; z-index: 9999;}'; document.body.appendChild(NewClass);
|
2409
2408
|
//
|
2410
2409
|
this.SetPoistion=function(e){ e.target.style.top= parseInt(e.pageY+top)+'px'; e.target.style.left= parseInt(e.pageX + left) + 'px'; };
|
2411
|
-
}
|
2410
|
+
}
|
2412
2411
|
// ==========================================================
|
2413
2412
|
|
2414
2413
|
|
@@ -2439,7 +2438,7 @@ const puvox_library =
|
|
2439
2438
|
|
2440
2439
|
}
|
2441
2440
|
else{ window.console && console.log("img not defined.. error28475 in script"); }
|
2442
|
-
}
|
2441
|
+
}
|
2443
2442
|
|
2444
2443
|
|
2445
2444
|
Balanced_Image_proportions (classname, widthh, heightt, parentClassname){ var LOAD_Result; var myImages; var FinalWidth=widthh; var FinalHeight=heightt;
|
@@ -2486,7 +2485,7 @@ const puvox_library =
|
|
2486
2485
|
|
2487
2486
|
|
2488
2487
|
}
|
2489
|
-
}
|
2488
|
+
}
|
2490
2489
|
// ========================================================= //
|
2491
2490
|
// ================= ### IMAGE PROPORTIONS ================= //
|
2492
2491
|
// ========================================================= //
|
@@ -2494,11 +2493,11 @@ const puvox_library =
|
|
2494
2493
|
show_after_pageload(el){
|
2495
2494
|
var el = el || '.show_after_pageload';
|
2496
2495
|
this.Append_To_Head("style", 'body '+el+' {opacity:1;}');
|
2497
|
-
}
|
2496
|
+
}
|
2498
2497
|
hide_after_pageload(el){
|
2499
2498
|
var el = el || '.hide_after_pageload';
|
2500
2499
|
this.Append_To_Head("style", 'body '+el+' {display:none;}');
|
2501
|
-
}
|
2500
|
+
}
|
2502
2501
|
|
2503
2502
|
// ==================== Position ==================== //
|
2504
2503
|
Highlight_Current_Menu_link(Added_class_name, Ancestor_to_search_in, link_to_find){
|
@@ -2517,9 +2516,9 @@ const puvox_library =
|
|
2517
2516
|
}
|
2518
2517
|
if (condition) { A_elements[i].className += " "+Added_class_name; }
|
2519
2518
|
}
|
2520
|
-
}
|
2519
|
+
}
|
2521
2520
|
//remove # from location
|
2522
|
-
RemoveHashString(str){ var hash=str.split("#")[1]; return str.replace("#"+hash,''); }
|
2521
|
+
RemoveHashString(str){ var hash=str.split("#")[1]; return str.replace("#"+hash,''); }
|
2523
2522
|
// ===================================================================//
|
2524
2523
|
|
2525
2524
|
arrayRemoveValue(array, value) {
|
@@ -2529,14 +2528,14 @@ const puvox_library =
|
|
2529
2528
|
newArray.splice(index, 1);
|
2530
2529
|
}
|
2531
2530
|
return newArray;
|
2532
|
-
}
|
2531
|
+
}
|
2533
2532
|
|
2534
2533
|
getCharsFromStart(str, amount){
|
2535
2534
|
return str.substring(0, amount);
|
2536
|
-
}
|
2535
|
+
}
|
2537
2536
|
getCharsFromEnd(str, amount){
|
2538
2537
|
return str.substring(str.length-amount, str.length);
|
2539
|
-
}
|
2538
|
+
}
|
2540
2539
|
|
2541
2540
|
// ============================= Position ============================= //
|
2542
2541
|
GetTopLeft(myyElement) {
|
@@ -2544,20 +2543,20 @@ const puvox_library =
|
|
2544
2543
|
var scrolled = {x : 0, y : 0}; this.GetScrolled (myyElement.parentNode, scrolled);
|
2545
2544
|
var posX = offset.x - scrolled.x; var posY = offset.y - scrolled.y;
|
2546
2545
|
return {lefttt: posX , toppp: posY };
|
2547
|
-
}
|
2546
|
+
}
|
2548
2547
|
GetOffset(object, offset) {
|
2549
2548
|
if (!object) return;
|
2550
2549
|
offset.x += object.offsetLeft; offset.y += object.offsetTop;
|
2551
2550
|
this.GetOffset (object.offsetParent, offset);
|
2552
|
-
}
|
2551
|
+
}
|
2553
2552
|
GetScrolled(object, scrolled) {
|
2554
2553
|
if (!object) return;
|
2555
2554
|
scrolled.x += object.scrollLeft; scrolled.y += object.scrollTop;
|
2556
2555
|
if (object.tagName.toLowerCase () != "html") { this.GetScrolled (object.parentNode, scrolled); }
|
2557
|
-
}
|
2558
|
-
//
|
2556
|
+
}
|
2557
|
+
// ======================== ##Position ======================== //
|
2559
2558
|
|
2560
|
-
//
|
2559
|
+
// ================ ## jQUery Fixed navigation ================ //
|
2561
2560
|
MakeFixed(selector, ExtraHeightToBody){
|
2562
2561
|
var sticky = $(selector);
|
2563
2562
|
var StickyHeight=parseInt(sticky.height());
|
@@ -2569,7 +2568,7 @@ const puvox_library =
|
|
2569
2568
|
if ($(window).scrollTop() > navPosition.top) { if(!sticky.hasClass('fixed_stickyy')){sticky.addClass('fixed_stickyy');} }
|
2570
2569
|
else { if( sticky.hasClass('fixed_stickyy')){sticky.removeClass('fixed_stickyy');} }
|
2571
2570
|
});
|
2572
|
-
}
|
2571
|
+
}
|
2573
2572
|
// ========================================================== //
|
2574
2573
|
|
2575
2574
|
triggerWhenElementInView(el, func){
|
@@ -2603,7 +2602,7 @@ const puvox_library =
|
|
2603
2602
|
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
|
2604
2603
|
|
2605
2604
|
};
|
2606
|
-
}
|
2605
|
+
}
|
2607
2606
|
|
2608
2607
|
compare(a, operator, b) {
|
2609
2608
|
if(operator === '==') return a == b;
|
@@ -2615,7 +2614,7 @@ const puvox_library =
|
|
2615
2614
|
else if (operator === '<') return a < b;
|
2616
2615
|
else if (operator === '<=') return a <= b;
|
2617
2616
|
else throw "Unknown operator";
|
2618
|
-
}
|
2617
|
+
}
|
2619
2618
|
calculate(a, operator, b) {
|
2620
2619
|
if(operator === '+') return a + b;
|
2621
2620
|
else if (operator === '-') return a - b;
|
@@ -2623,15 +2622,15 @@ const puvox_library =
|
|
2623
2622
|
else if (operator === '/') return a / b;
|
2624
2623
|
else if (operator === '%') return a % b;
|
2625
2624
|
else throw "Unknown operator";
|
2626
|
-
}
|
2625
|
+
}
|
2627
2626
|
|
2628
2627
|
// random NUMBER or STRINGS
|
2629
|
-
RandomNum(maxNum) { return Math.floor((Math.random() * maxNum) + 1); }
|
2628
|
+
RandomNum(maxNum) { return Math.floor((Math.random() * maxNum) + 1); }
|
2630
2629
|
|
2631
|
-
random_number(Length) { var length= length || 5; return Math.floor((Math.random() * Math.pow(10, length)) + 1);}
|
2632
|
-
randomNumber(Length) {return this.random_number(length);}
|
2633
|
-
random_number_minmax(min, max) { var min= min || 1; var max= max || 9999999999; return Math.floor(Math.random() * (max - min + 1)) + min;}
|
2634
|
-
randomString(Length) { var length= length || 5; return Math.random().toString(36).substr(2, length);}
|
2630
|
+
random_number(Length) { var length= length || 5; return Math.floor((Math.random() * Math.pow(10, length)) + 1);}
|
2631
|
+
randomNumber(Length) {return this.random_number(length);}
|
2632
|
+
random_number_minmax(min, max) { var min= min || 1; var max= max || 9999999999; return Math.floor(Math.random() * (max - min + 1)) + min;}
|
2633
|
+
randomString(Length) { var length= length || 5; return Math.random().toString(36).substr(2, length);}
|
2635
2634
|
//getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); },
|
2636
2635
|
|
2637
2636
|
shuffle_Word(word){
|
@@ -2644,9 +2643,9 @@ const puvox_library =
|
|
2644
2643
|
word.splice(charIndex,1);
|
2645
2644
|
}
|
2646
2645
|
return shuffledWord;
|
2647
|
-
}
|
2646
|
+
}
|
2648
2647
|
|
2649
|
-
youtubeImage(id, quality) { return 'http://img.youtube.com/vi/'+id+'/'+ (quality || "mqdefault") +'.jpg'; }
|
2648
|
+
youtubeImage(id, quality) { return 'http://img.youtube.com/vi/'+id+'/'+ (quality || "mqdefault") +'.jpg'; }
|
2650
2649
|
|
2651
2650
|
// ============================= detect mobile device ============================= //
|
2652
2651
|
IsMobileDevice(simpleORfull){
|
@@ -2659,7 +2658,7 @@ const puvox_library =
|
|
2659
2658
|
this.IsMobileDevice= (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(navigtr)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigtr.substr(0,4)));
|
2660
2659
|
}
|
2661
2660
|
return IsMobileDevice;
|
2662
|
-
}
|
2661
|
+
}
|
2663
2662
|
|
2664
2663
|
backToTopBind(el){
|
2665
2664
|
if ($(el).length) {
|
@@ -2670,7 +2669,7 @@ const puvox_library =
|
|
2670
2669
|
}, 700);
|
2671
2670
|
});
|
2672
2671
|
}
|
2673
|
-
}
|
2672
|
+
}
|
2674
2673
|
|
2675
2674
|
enable_jquery_errors()
|
2676
2675
|
{
|
@@ -2678,7 +2677,7 @@ const puvox_library =
|
|
2678
2677
|
var elements = jQuery(selector, context); if( !elements.length ) { window.console && console.log("'" + selector + "' element(s) not found"); }
|
2679
2678
|
return elements;
|
2680
2679
|
}
|
2681
|
-
}
|
2680
|
+
}
|
2682
2681
|
|
2683
2682
|
|
2684
2683
|
// region ### TELEGRAM FUNCTIONS ###
|
@@ -2723,10 +2722,10 @@ const puvox_library =
|
|
2723
2722
|
} catch (ex) {
|
2724
2723
|
return {'ok': false, 'description': ex.message + ':::' + responseText };
|
2725
2724
|
}
|
2726
|
-
}
|
2725
|
+
}
|
2727
2726
|
|
2728
|
-
telegram_interval_ms
|
2729
|
-
telegram_last_sent_time
|
2727
|
+
telegram_interval_ms= 50; // telegram seems to accept around 30 times per second, so we'd better wait around that milliseconds
|
2728
|
+
telegram_last_sent_time= 0;
|
2730
2729
|
|
2731
2730
|
async telegramMessageCached(text, chat_id, bot_key, extra_opts={}, customCacheId=null){
|
2732
2731
|
if (!extra_opts) extra_opts = {};
|
@@ -2746,17 +2745,17 @@ const puvox_library =
|
|
2746
2745
|
//if(is_callable([$this,'notifications_db_entry']))
|
2747
2746
|
// $this->notifications_db_entry($key, $array['chat_id'], $this->stringify($res), time(), $ok );
|
2748
2747
|
//return $res;
|
2749
|
-
}
|
2748
|
+
}
|
2750
2749
|
|
2751
2750
|
openUrlInBrowser(url)
|
2752
2751
|
{
|
2753
2752
|
var cmd = (process.platform == 'darwin'? `open ${url}`: process.platform == 'win32'? `start ${url}`: `xdg-open ${url}`);
|
2754
2753
|
// require('child_process').exec(cmd);
|
2755
|
-
}
|
2754
|
+
}
|
2756
2755
|
|
2757
2756
|
stringify(obj_or_str){
|
2758
2757
|
return this.isSimpleVariableType(obj_or_str) ? obj_or_str.toString() : JSON.stringify(obj_or_str);
|
2759
|
-
}
|
2758
|
+
}
|
2760
2759
|
|
2761
2760
|
stringify_plain(data){
|
2762
2761
|
var text='';
|
@@ -2777,21 +2776,21 @@ const puvox_library =
|
|
2777
2776
|
text = data;
|
2778
2777
|
}
|
2779
2778
|
return text;
|
2780
|
-
}
|
2779
|
+
}
|
2781
2780
|
CopyObject(obj) {
|
2782
2781
|
return JSON.parse(JSON.stringify(obj));
|
2783
|
-
}
|
2782
|
+
}
|
2784
2783
|
|
2785
2784
|
uniqId(obj_or_str){
|
2786
2785
|
return this.md5( this.stringify(obj_or_str) );
|
2787
|
-
}
|
2786
|
+
}
|
2788
2787
|
|
2789
2788
|
stringifyWithUndefined(obj){
|
2790
2789
|
return JSON.stringify(obj, function(key, value){ return value === undefined ? null : value; });
|
2791
|
-
}
|
2790
|
+
}
|
2792
2791
|
// https://gist.github.com/PixnBits/8811212
|
2793
2792
|
//md5(str){ let name='crypto'; return require(name).createHash('md5').update(str).digest("hex"); }
|
2794
|
-
md5(str){var md5cycle=function(x,k){var a=x[0],b=x[1],c=x[2],d=x[3];a=ff(a,b,c,d,k[0],7,-680876936);d=ff(d,a,b,c,k[1],12,-389564586);c=ff(c,d,a,b,k[2],17,606105819);b=ff(b,c,d,a,k[3],22,-1044525330);a=ff(a,b,c,d,k[4],7,-176418897);d=ff(d,a,b,c,k[5],12,1200080426);c=ff(c,d,a,b,k[6],17,-1473231341);b=ff(b,c,d,a,k[7],22,-45705983);a=ff(a,b,c,d,k[8],7,1770035416);d=ff(d,a,b,c,k[9],12,-1958414417);c=ff(c,d,a,b,k[10],17,-42063);b=ff(b,c,d,a,k[11],22,-1990404162);a=ff(a,b,c,d,k[12],7,1804603682);d=ff(d,a,b,c,k[13],12,-40341101);c=ff(c,d,a,b,k[14],17,-1502002290);b=ff(b,c,d,a,k[15],22,1236535329);a=gg(a,b,c,d,k[1],5,-165796510);d=gg(d,a,b,c,k[6],9,-1069501632);c=gg(c,d,a,b,k[11],14,643717713);b=gg(b,c,d,a,k[0],20,-373897302);a=gg(a,b,c,d,k[5],5,-701558691);d=gg(d,a,b,c,k[10],9,38016083);c=gg(c,d,a,b,k[15],14,-660478335);b=gg(b,c,d,a,k[4],20,-405537848);a=gg(a,b,c,d,k[9],5,568446438);d=gg(d,a,b,c,k[14],9,-1019803690);c=gg(c,d,a,b,k[3],14,-187363961);b=gg(b,c,d,a,k[8],20,1163531501);a=gg(a,b,c,d,k[13],5,-1444681467);d=gg(d,a,b,c,k[2],9,-51403784);c=gg(c,d,a,b,k[7],14,1735328473);b=gg(b,c,d,a,k[12],20,-1926607734);a=hh(a,b,c,d,k[5],4,-378558);d=hh(d,a,b,c,k[8],11,-2022574463);c=hh(c,d,a,b,k[11],16,1839030562);b=hh(b,c,d,a,k[14],23,-35309556);a=hh(a,b,c,d,k[1],4,-1530992060);d=hh(d,a,b,c,k[4],11,1272893353);c=hh(c,d,a,b,k[7],16,-155497632);b=hh(b,c,d,a,k[10],23,-1094730640);a=hh(a,b,c,d,k[13],4,681279174);d=hh(d,a,b,c,k[0],11,-358537222);c=hh(c,d,a,b,k[3],16,-722521979);b=hh(b,c,d,a,k[6],23,76029189);a=hh(a,b,c,d,k[9],4,-640364487);d=hh(d,a,b,c,k[12],11,-421815835);c=hh(c,d,a,b,k[15],16,530742520);b=hh(b,c,d,a,k[2],23,-995338651);a=ii(a,b,c,d,k[0],6,-198630844);d=ii(d,a,b,c,k[7],10,1126891415);c=ii(c,d,a,b,k[14],15,-1416354905);b=ii(b,c,d,a,k[5],21,-57434055);a=ii(a,b,c,d,k[12],6,1700485571);d=ii(d,a,b,c,k[3],10,-1894986606);c=ii(c,d,a,b,k[10],15,-1051523);b=ii(b,c,d,a,k[1],21,-2054922799);a=ii(a,b,c,d,k[8],6,1873313359);d=ii(d,a,b,c,k[15],10,-30611744);c=ii(c,d,a,b,k[6],15,-1560198380);b=ii(b,c,d,a,k[13],21,1309151649);a=ii(a,b,c,d,k[4],6,-145523070);d=ii(d,a,b,c,k[11],10,-1120210379);c=ii(c,d,a,b,k[2],15,718787259);b=ii(b,c,d,a,k[9],21,-343485551);x[0]=add32(a,x[0]);x[1]=add32(b,x[1]);x[2]=add32(c,x[2]);x[3]=add32(d,x[3])};var cmn=function(q,a,b,x,s,t){a=add32(add32(a,q),add32(x,t));return add32(a<<s|a>>>32-s,b)};var ff=function(a,b,c,d,x,s,t){return cmn(b&c|~b&d,a,b,x,s,t)};var gg=function(a,b,c,d,x,s,t){return cmn(b&d|c&~d,a,b,x,s,t)};var hh=function(a,b,c,d,x,s,t){return cmn(b^c^d,a,b,x,s,t)};var ii=function(a,b,c,d,x,s,t){return cmn(c^(b|~d),a,b,x,s,t)};var md51=function(s){var txt="",n=s.length,state=[1732584193,-271733879,-1732584194,271733878],i;for(i=64;i<=s.length;i+=64){md5cycle(state,md5blk(s.substring(i-64,i)))}s=s.substring(i-64);var tail=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(i=0;i<s.length;i++)tail[i>>2]|=s.charCodeAt(i)<<(i%4<<3);tail[i>>2]|=128<<(i%4<<3);if(i>55){md5cycle(state,tail);for(i=0;i<16;i++)tail[i]=0}tail[14]=n*8;md5cycle(state,tail);return state};var md5blk=function(s){var md5blks=[],i;for(i=0;i<64;i+=4){md5blks[i>>2]=s.charCodeAt(i)+(s.charCodeAt(i+1)<<8)+(s.charCodeAt(i+2)<<16)+(s.charCodeAt(i+3)<<24)}return md5blks};var hex_chr="0123456789abcdef".split("");var rhex=function(n){var s="",j=0;for(;j<4;j++)s+=hex_chr[n>>j*8+4&15]+hex_chr[n>>j*8&15];return s};var hex=function(x){for(var i=0;i<x.length;i++)x[i]=rhex(x[i]);return x.join("")};var md5_=function(s){return hex(md51(s))};var add32=function(a,b){return a+b&4294967295};if(md5_("hello")!="5d41402abc4b2a76b9719d911017c592"){var add32=function(x,y){var lsw=(x&65535)+(y&65535),msw=(x>>16)+(y>>16)+(lsw>>16);return msw<<16|lsw&65535}}return md5_(str)}
|
2793
|
+
md5(str){var md5cycle=function(x,k){var a=x[0],b=x[1],c=x[2],d=x[3];a=ff(a,b,c,d,k[0],7,-680876936);d=ff(d,a,b,c,k[1],12,-389564586);c=ff(c,d,a,b,k[2],17,606105819);b=ff(b,c,d,a,k[3],22,-1044525330);a=ff(a,b,c,d,k[4],7,-176418897);d=ff(d,a,b,c,k[5],12,1200080426);c=ff(c,d,a,b,k[6],17,-1473231341);b=ff(b,c,d,a,k[7],22,-45705983);a=ff(a,b,c,d,k[8],7,1770035416);d=ff(d,a,b,c,k[9],12,-1958414417);c=ff(c,d,a,b,k[10],17,-42063);b=ff(b,c,d,a,k[11],22,-1990404162);a=ff(a,b,c,d,k[12],7,1804603682);d=ff(d,a,b,c,k[13],12,-40341101);c=ff(c,d,a,b,k[14],17,-1502002290);b=ff(b,c,d,a,k[15],22,1236535329);a=gg(a,b,c,d,k[1],5,-165796510);d=gg(d,a,b,c,k[6],9,-1069501632);c=gg(c,d,a,b,k[11],14,643717713);b=gg(b,c,d,a,k[0],20,-373897302);a=gg(a,b,c,d,k[5],5,-701558691);d=gg(d,a,b,c,k[10],9,38016083);c=gg(c,d,a,b,k[15],14,-660478335);b=gg(b,c,d,a,k[4],20,-405537848);a=gg(a,b,c,d,k[9],5,568446438);d=gg(d,a,b,c,k[14],9,-1019803690);c=gg(c,d,a,b,k[3],14,-187363961);b=gg(b,c,d,a,k[8],20,1163531501);a=gg(a,b,c,d,k[13],5,-1444681467);d=gg(d,a,b,c,k[2],9,-51403784);c=gg(c,d,a,b,k[7],14,1735328473);b=gg(b,c,d,a,k[12],20,-1926607734);a=hh(a,b,c,d,k[5],4,-378558);d=hh(d,a,b,c,k[8],11,-2022574463);c=hh(c,d,a,b,k[11],16,1839030562);b=hh(b,c,d,a,k[14],23,-35309556);a=hh(a,b,c,d,k[1],4,-1530992060);d=hh(d,a,b,c,k[4],11,1272893353);c=hh(c,d,a,b,k[7],16,-155497632);b=hh(b,c,d,a,k[10],23,-1094730640);a=hh(a,b,c,d,k[13],4,681279174);d=hh(d,a,b,c,k[0],11,-358537222);c=hh(c,d,a,b,k[3],16,-722521979);b=hh(b,c,d,a,k[6],23,76029189);a=hh(a,b,c,d,k[9],4,-640364487);d=hh(d,a,b,c,k[12],11,-421815835);c=hh(c,d,a,b,k[15],16,530742520);b=hh(b,c,d,a,k[2],23,-995338651);a=ii(a,b,c,d,k[0],6,-198630844);d=ii(d,a,b,c,k[7],10,1126891415);c=ii(c,d,a,b,k[14],15,-1416354905);b=ii(b,c,d,a,k[5],21,-57434055);a=ii(a,b,c,d,k[12],6,1700485571);d=ii(d,a,b,c,k[3],10,-1894986606);c=ii(c,d,a,b,k[10],15,-1051523);b=ii(b,c,d,a,k[1],21,-2054922799);a=ii(a,b,c,d,k[8],6,1873313359);d=ii(d,a,b,c,k[15],10,-30611744);c=ii(c,d,a,b,k[6],15,-1560198380);b=ii(b,c,d,a,k[13],21,1309151649);a=ii(a,b,c,d,k[4],6,-145523070);d=ii(d,a,b,c,k[11],10,-1120210379);c=ii(c,d,a,b,k[2],15,718787259);b=ii(b,c,d,a,k[9],21,-343485551);x[0]=add32(a,x[0]);x[1]=add32(b,x[1]);x[2]=add32(c,x[2]);x[3]=add32(d,x[3])};var cmn=function(q,a,b,x,s,t){a=add32(add32(a,q),add32(x,t));return add32(a<<s|a>>>32-s,b)};var ff=function(a,b,c,d,x,s,t){return cmn(b&c|~b&d,a,b,x,s,t)};var gg=function(a,b,c,d,x,s,t){return cmn(b&d|c&~d,a,b,x,s,t)};var hh=function(a,b,c,d,x,s,t){return cmn(b^c^d,a,b,x,s,t)};var ii=function(a,b,c,d,x,s,t){return cmn(c^(b|~d),a,b,x,s,t)};var md51=function(s){var txt="",n=s.length,state=[1732584193,-271733879,-1732584194,271733878],i;for(i=64;i<=s.length;i+=64){md5cycle(state,md5blk(s.substring(i-64,i)))}s=s.substring(i-64);var tail=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(i=0;i<s.length;i++)tail[i>>2]|=s.charCodeAt(i)<<(i%4<<3);tail[i>>2]|=128<<(i%4<<3);if(i>55){md5cycle(state,tail);for(i=0;i<16;i++)tail[i]=0}tail[14]=n*8;md5cycle(state,tail);return state};var md5blk=function(s){var md5blks=[],i;for(i=0;i<64;i+=4){md5blks[i>>2]=s.charCodeAt(i)+(s.charCodeAt(i+1)<<8)+(s.charCodeAt(i+2)<<16)+(s.charCodeAt(i+3)<<24)}return md5blks};var hex_chr="0123456789abcdef".split("");var rhex=function(n){var s="",j=0;for(;j<4;j++)s+=hex_chr[n>>j*8+4&15]+hex_chr[n>>j*8&15];return s};var hex=function(x){for(var i=0;i<x.length;i++)x[i]=rhex(x[i]);return x.join("")};var md5_=function(s){return hex(md51(s))};var add32=function(a,b){return a+b&4294967295};if(md5_("hello")!="5d41402abc4b2a76b9719d911017c592"){var add32=function(x,y){var lsw=(x&65535)+(y&65535),msw=(x>>16)+(y>>16)+(lsw>>16);return msw<<16|lsw&65535}}return md5_(str);}
|
2795
2794
|
|
2796
2795
|
|
2797
2796
|
|
@@ -2809,14 +2808,12 @@ const puvox_library =
|
|
2809
2808
|
}
|
2810
2809
|
return o1;
|
2811
2810
|
}
|
2812
|
-
}
|
2813
|
-
|
2814
|
-
|
2811
|
+
}
|
2815
2812
|
|
2816
2813
|
|
2817
2814
|
async fetch(url, postOptions = null, opts = {}){
|
2818
2815
|
return await this.getRemoteData(url, postOptions, opts);
|
2819
|
-
}
|
2816
|
+
}
|
2820
2817
|
async getRemoteData(url, postOptions = null, opts = {}){
|
2821
2818
|
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
|
2822
2819
|
const options = {};
|
@@ -2835,7 +2832,7 @@ const puvox_library =
|
|
2835
2832
|
// }).on ('error', (ex) => { reject (ex); });
|
2836
2833
|
// } catch (ex) { reject (ex); }
|
2837
2834
|
// });
|
2838
|
-
}
|
2835
|
+
}
|
2839
2836
|
// if(setHashInAddress) { window.location.hash = id_or_Name; }
|
2840
2837
|
|
2841
2838
|
|
@@ -2853,29 +2850,30 @@ const puvox_library =
|
|
2853
2850
|
str = str.slice(0, -1);
|
2854
2851
|
}
|
2855
2852
|
return str;
|
2856
|
-
}
|
2853
|
+
}
|
2857
2854
|
trailingSlash(str){
|
2858
2855
|
return this.unTrailingSlash(str) + '/';
|
2859
|
-
}
|
2856
|
+
}
|
2860
2857
|
|
2861
2858
|
// ######## CACHE ITEMS (client-side JS) ########
|
2862
|
-
privateAppName__
|
2863
|
-
setAppName (name){ this.privateAppName__ = name; }
|
2859
|
+
privateAppName__ = null; //override with anything you want
|
2860
|
+
setAppName (name){ this.privateAppName__ = name; }
|
2864
2861
|
getAppName(){
|
2865
2862
|
if (!this.privateAppName__){
|
2866
2863
|
throw new Error ('Before you start using caching functions, please at first define your appplication\'s name(identifier) at first with .setAppName("whatever_my_app_name"), so it will get its own cache-storage');
|
2867
2864
|
}
|
2868
2865
|
return this.privateAppName__;
|
2869
|
-
}
|
2866
|
+
}
|
2870
2867
|
|
2871
2868
|
|
2872
2869
|
// ######## Cookies: https://github.com/ttodua/useful-javascript/blob/master/cookies-library.js ######## //
|
2873
|
-
Cookies
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2870
|
+
Cookies = new (class{
|
2871
|
+
MAIN_CLASS = self;
|
2872
|
+
get(a,b) { return this.cookies_instance().get(a,b); }
|
2873
|
+
set(a,b,c) { return this.cookies_instance().set(a,b); }
|
2874
|
+
remove(a, b) {return this.cookies_instance().remove(a,b); }
|
2875
|
+
append(name, value, attributes) {return this.cookies_instance().set((this.get(name) || '') + value, attributes); }
|
2876
|
+
isset(cookiename) {return this.get(cookiename)!="";} // document.cookie.indexOf('; '+cookiename+'=');
|
2879
2877
|
// WORKING WITH ARRAY/OBJECTS
|
2880
2878
|
getOption(cookieName, key, defaultValue)
|
2881
2879
|
{
|
@@ -2887,7 +2885,7 @@ const puvox_library =
|
|
2887
2885
|
return parsed[key];
|
2888
2886
|
}
|
2889
2887
|
return defaultValue;
|
2890
|
-
}
|
2888
|
+
}
|
2891
2889
|
setOption(cookieName, key, value, attributes)
|
2892
2890
|
{
|
2893
2891
|
var cookie = this.get(cookieName);
|
@@ -2897,7 +2895,7 @@ const puvox_library =
|
|
2897
2895
|
var attributes = attributes || { expires: 99999 };
|
2898
2896
|
this.set(cookieName, JSON.stringify(parsed), attributes);
|
2899
2897
|
return parsed;
|
2900
|
-
}
|
2898
|
+
}
|
2901
2899
|
removeOption(cookieName, key, attributes)
|
2902
2900
|
{
|
2903
2901
|
var cookie = this.get(cookieName);
|
@@ -2907,17 +2905,17 @@ const puvox_library =
|
|
2907
2905
|
var attributes = attributes || { expires: 99999 };
|
2908
2906
|
this.set(cookieName, JSON.stringify(parsed), attributes);
|
2909
2907
|
return parsed;
|
2910
|
-
}
|
2908
|
+
}
|
2911
2909
|
//sub-array
|
2912
2910
|
getOptionObject(cookieName, key){
|
2913
2911
|
return JSON.parse( this.getOption(cookieName, key, "{}") );
|
2914
|
-
}
|
2912
|
+
}
|
2915
2913
|
setOptionObject(cookieName, key, subKey, subValue){
|
2916
2914
|
var existing = JSON.parse( this.getOption(cookieName, key, "{}") );
|
2917
2915
|
if (subValue==null) delete existing[subKey];
|
2918
2916
|
else existing[subKey]=subValue;
|
2919
2917
|
this.setOption(cookieName, key, JSON.stringify(existing));
|
2920
|
-
}
|
2918
|
+
}
|
2921
2919
|
setOptionArray(cookieName, key, subValue, Add_or_remove)
|
2922
2920
|
{
|
2923
2921
|
var existing = JSON.parse( this.getOption(cookieName, key, "[]") );
|
@@ -2927,26 +2925,27 @@ const puvox_library =
|
|
2927
2925
|
}
|
2928
2926
|
else if(!Add_or_remove && existing.includes(subValue) )
|
2929
2927
|
{
|
2930
|
-
existing =
|
2928
|
+
existing = this.MAIN_CLASS.removeItem(existing, subValue);
|
2931
2929
|
}
|
2932
2930
|
this.setOption(cookieName, key, JSON.stringify(existing));
|
2933
|
-
}
|
2931
|
+
}
|
2934
2932
|
//
|
2935
|
-
cookies_instance(){ if (!this.cookies_inited) this.cookies_inited=this.cookies(); return this.cookies_inited; }
|
2936
|
-
cookies_inited
|
2933
|
+
cookies_instance(){ if (!this.cookies_inited) this.cookies_inited = this.cookies(); return this.cookies_inited; }
|
2934
|
+
cookies_inited= null;
|
2937
2935
|
// https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js
|
2938
|
-
cookies
|
2939
|
-
}
|
2936
|
+
cookies = function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var t={read:function(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};return function n(r,o){function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),n=r.write(n,t);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+c}}return Object.create({set:i,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var c=n[i].split("="),u=c.slice(1).join("=");'"'===u[0]&&(u=u.slice(1,-1));try{var f=t.read(c[0]);if(o[f]=r.read(u,f),e===f)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){i(t,"",e({},n,{expires:-1}))},withAttributes:function(t){return n(this.converter,e({},this.attributes,t))},withConverter:function(t){return n(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(r)}})}(t,{path:"/"})}
|
2937
|
+
})();
|
2940
2938
|
|
2941
2939
|
|
2942
|
-
cache
|
2940
|
+
cache = new (class{
|
2941
|
+
MAIN_CLASS = self;
|
2943
2942
|
helper_read(groupName, storageType, expireSeconds = 0){
|
2944
|
-
const appName =
|
2943
|
+
const appName = this.MAIN_CLASS.getAppName();
|
2945
2944
|
if (storageType === 'file'){
|
2946
|
-
const dir =
|
2945
|
+
const dir = this.MAIN_CLASS.file.tempDir() + appName + '/';
|
2947
2946
|
const filepath = dir + groupName + '.json';
|
2948
2947
|
// todo: add expiration
|
2949
|
-
return
|
2948
|
+
return this.MAIN_CLASS.file.read(filepath);
|
2950
2949
|
} else if (storageType === 'localStorage') {
|
2951
2950
|
const storage = window.localStorage;
|
2952
2951
|
let val = storage.getItem(appName + '_' + groupName);
|
@@ -2963,16 +2962,16 @@ const puvox_library =
|
|
2963
2962
|
if (typeof alert !== 'undefined') alert(`storageType ${storageType} not supported`);
|
2964
2963
|
throw new Error(`storageType ${storageType} not supported`);
|
2965
2964
|
}
|
2966
|
-
}
|
2965
|
+
}
|
2967
2966
|
helper_write(groupName, content, storageType){
|
2968
|
-
content =
|
2969
|
-
const appName =
|
2967
|
+
content = this.MAIN_CLASS.isString (content) ? content : (this.MAIN_CLASS.isArray(content) || this.MAIN_CLASS.isObject(content) ? JSON.stringify(content) : content);
|
2968
|
+
const appName = this.MAIN_CLASS.getAppName();
|
2970
2969
|
if (storageType === 'file'){
|
2971
|
-
const dir =
|
2972
|
-
|
2970
|
+
const dir = this.MAIN_CLASS.file.tempDir() + appName + '/';
|
2971
|
+
this.MAIN_CLASS.file.createDirectory(dir);
|
2973
2972
|
const filepath = dir + groupName + '.json';
|
2974
2973
|
// todo: add expiration
|
2975
|
-
|
2974
|
+
this.MAIN_CLASS.file.write(filepath, content);
|
2976
2975
|
return true;
|
2977
2976
|
} else if (storageType === 'localStorage') {
|
2978
2977
|
try{
|
@@ -2986,13 +2985,13 @@ const puvox_library =
|
|
2986
2985
|
if (typeof alert !== 'undefined') alert(`storageType ${storageType} not supported`);
|
2987
2986
|
throw new Error(`storageType ${storageType} not supported`);
|
2988
2987
|
}
|
2989
|
-
}
|
2988
|
+
}
|
2990
2989
|
helper_delete(groupName, storageType){
|
2991
|
-
const appName =
|
2990
|
+
const appName = this.MAIN_CLASS.getAppName();
|
2992
2991
|
if (storageType === 'file'){
|
2993
|
-
const filepath =
|
2992
|
+
const filepath = this.MAIN_CLASS.file.tempDir() + appName + '/' + groupName + '.json';
|
2994
2993
|
// todo: better delete
|
2995
|
-
|
2994
|
+
this.MAIN_CLASS.file.delete(filepath);
|
2996
2995
|
return true;
|
2997
2996
|
} else if (storageType === 'localStorage') {
|
2998
2997
|
try{
|
@@ -3006,30 +3005,30 @@ const puvox_library =
|
|
3006
3005
|
alert(`storageType ${storageType} not supported`);
|
3007
3006
|
throw new Error(`storageType ${storageType} not supported`);
|
3008
3007
|
}
|
3009
|
-
}
|
3008
|
+
}
|
3010
3009
|
|
3011
3010
|
get(groupName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
|
3012
3011
|
const content = this.helper_read(groupName, storageType, expireSeconds);
|
3013
3012
|
return (content !== null && content !== '') ? content : defaultVal;
|
3014
|
-
}
|
3013
|
+
}
|
3015
3014
|
set(groupName, content, storageType = 'localStorage'){
|
3016
3015
|
this.helper_write(groupName, content, storageType);
|
3017
|
-
}
|
3016
|
+
}
|
3018
3017
|
delete(groupName, storageType = 'localStorage'){
|
3019
3018
|
this.helper_delete(groupName, storageType);
|
3020
|
-
}
|
3019
|
+
}
|
3021
3020
|
getChild(groupName, optName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
|
3022
3021
|
// todo: individual sub-item expiration
|
3023
3022
|
const content = this.get(groupName, '{}', storageType, expireSeconds);
|
3024
3023
|
const json = JSON.parse(content);
|
3025
3024
|
return (optName in json) ? json[optName] : defaultVal;
|
3026
|
-
}
|
3025
|
+
}
|
3027
3026
|
setChild(groupName, optName, val, storageType = 'localStorage'){
|
3028
3027
|
const content = this.get(groupName, '{}', storageType);
|
3029
3028
|
const json = JSON.parse(content);
|
3030
3029
|
json[optName] = val;
|
3031
3030
|
this.set(groupName, JSON.stringify(json), storageType);
|
3032
|
-
}
|
3031
|
+
}
|
3033
3032
|
deleteChild(groupName, optName, storageType = 'localStorage'){
|
3034
3033
|
const content = this.get(groupName, '{}', storageType, expireSeconds);
|
3035
3034
|
// if it's empty, no need to do anything
|
@@ -3037,40 +3036,41 @@ const puvox_library =
|
|
3037
3036
|
const json = JSON.parse(content);
|
3038
3037
|
delete json[optName];
|
3039
3038
|
this.set(groupName, JSON.stringify(json), storageType);
|
3040
|
-
}
|
3039
|
+
}
|
3041
3040
|
|
3042
3041
|
|
3043
|
-
file
|
3042
|
+
file = new (class {
|
3043
|
+
MAIN_CLASS = self;
|
3044
3044
|
// ########## CACHE DIRS (server-side JS) ##########
|
3045
|
-
customCacheDir
|
3045
|
+
customCacheDir = null;
|
3046
3046
|
get_dir(){
|
3047
3047
|
if (!this.customCacheDir){
|
3048
|
-
this.customCacheDir =
|
3048
|
+
this.customCacheDir = this.MAIN_CLASS.file.tempDir();
|
3049
3049
|
}
|
3050
|
-
let finaldir =
|
3050
|
+
let finaldir = this.MAIN_CLASS.trailingSlash(this.customCacheDir + this.MAIN_CLASS.getAppName() + '_cache_');
|
3051
3051
|
return finaldir;
|
3052
|
-
}
|
3052
|
+
}
|
3053
3053
|
set_dir(dir, auto_clear_seconds=null){
|
3054
3054
|
if(dir) this.customCacheDir = dir;
|
3055
|
-
const res =
|
3055
|
+
const res = this.MAIN_CLASS.file.createDirectory(this.customCacheDir);
|
3056
3056
|
if( !is_null(auto_clear_seconds))
|
3057
3057
|
{
|
3058
3058
|
throw new Error("Not implemented yet! 345346");
|
3059
3059
|
//$this->clearCacheDir($auto_clear_seconds);
|
3060
3060
|
}
|
3061
3061
|
return res;
|
3062
|
-
}
|
3062
|
+
}
|
3063
3063
|
filePath(uniqFileName){
|
3064
|
-
const parent =
|
3064
|
+
const parent = this.MAIN_CLASS;
|
3065
3065
|
uniqFileName = parent.isString(uniqFileName) || parent.isNumeric(uniqFileName) ? uniqFileName : JSON.stringify(uniqFileName);
|
3066
3066
|
uniqFileName = parent.sanitize_key_dashed(parent.getCharsFromStart(uniqFileName, 15)) + "_"+ parent.md5(uniqFileName);
|
3067
3067
|
filePath= this.get_dir() + uniqFileName + "_tmp"; //"/".
|
3068
3068
|
return filePath;
|
3069
|
-
}
|
3069
|
+
}
|
3070
3070
|
//
|
3071
3071
|
get(uniqFileName, defaultContent ='', expire_seconds=8640000, decode = true)
|
3072
3072
|
{
|
3073
|
-
const parent =
|
3073
|
+
const parent = this.MAIN_CLASS;
|
3074
3074
|
let filePath = this.filePath(uniqFileName);
|
3075
3075
|
if ( parent.file.exists(filePath) ){
|
3076
3076
|
if ( parent.file.mtime(filePath) + expire_seconds *1000 < (new Date()).getTime() ){
|
@@ -3100,17 +3100,14 @@ const puvox_library =
|
|
3100
3100
|
else {
|
3101
3101
|
return defaultContent;
|
3102
3102
|
}
|
3103
|
-
}
|
3103
|
+
}
|
3104
3104
|
set(uniqFileName, content)
|
3105
3105
|
{
|
3106
|
-
const parent =
|
3106
|
+
const parent = this.MAIN_CLASS;
|
3107
3107
|
let filePath= this.filePath(uniqFileName);
|
3108
3108
|
let contentFinal = parent.isString(content) ? content : ((parent.isArray(content) || parent.isObject(content)) ? JSON.stringify(content) : content);
|
3109
3109
|
return parent.file.write(filePath, contentFinal);
|
3110
|
-
}
|
3111
|
-
|
3112
|
-
|
3113
|
-
|
3110
|
+
}
|
3114
3111
|
|
3115
3112
|
|
3116
3113
|
//
|
@@ -3118,14 +3115,14 @@ const puvox_library =
|
|
3118
3115
|
// try{
|
3119
3116
|
// var callback = callback || function(){};
|
3120
3117
|
// var self = this;
|
3121
|
-
//
|
3118
|
+
// this.MAIN_CLASS.modules('fs').readFile(filePath, 'utf8', function(err,data) {
|
3122
3119
|
// let json = {};
|
3123
3120
|
// if (typeof data !="undefined" && data!=''){
|
3124
3121
|
// json=JSON.parse(data);
|
3125
3122
|
// }
|
3126
3123
|
// let jsonNew = self.jsonConcat(json, jsonContent);
|
3127
3124
|
// let content = JSON.stringify(jsonNew);
|
3128
|
-
//
|
3125
|
+
// this.MAIN_CLASS.modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
|
3129
3126
|
// });
|
3130
3127
|
// });
|
3131
3128
|
// }
|
@@ -3133,41 +3130,39 @@ const puvox_library =
|
|
3133
3130
|
// console.log("writeFileAppendJson", e);
|
3134
3131
|
// }
|
3135
3132
|
// },
|
3136
|
-
containerDefaultPrefix
|
3137
|
-
tempIds
|
3133
|
+
containerDefaultPrefix = "_cached_ids_";
|
3134
|
+
tempIds = {};
|
3138
3135
|
idForContent(slugOrContent){
|
3139
|
-
return
|
3140
|
-
}
|
3136
|
+
return this.MAIN_CLASS.md5(this.MAIN_CLASS.isSimpleVariableType(slugOrContent) ? slugOrContent : JSON.stringify(slugOrContent));
|
3137
|
+
}
|
3141
3138
|
existsId(containerSlug, id){
|
3142
3139
|
return (id in this.getIds(containerSlug));
|
3143
|
-
}
|
3140
|
+
}
|
3144
3141
|
getIds(containerSlug) {
|
3145
3142
|
if (! (containerSlug in this.tempIds)) {
|
3146
|
-
const content =
|
3143
|
+
const content = this.MAIN_CLASS.file.read(this.get_dir() + this.containerDefaultPrefix + containerSlug, '{}');
|
3147
3144
|
this.tempIds[containerSlug] = JSON.parse(content);
|
3148
3145
|
}
|
3149
3146
|
return this.tempIds[containerSlug];
|
3150
|
-
}
|
3147
|
+
}
|
3151
3148
|
setIds(containerSlug, idsDict) {
|
3152
3149
|
this.tempIds[containerSlug] = idsDict;
|
3153
|
-
return
|
3154
|
-
}
|
3150
|
+
return this.MAIN_CLASS.file.write(this.get_dir() + this.containerDefaultPrefix + containerSlug, JSON.stringify(this.tempIds[containerSlug]));
|
3151
|
+
}
|
3155
3152
|
addId(containerSlug, id){
|
3156
3153
|
const ids = this.getIds(containerSlug);
|
3157
3154
|
ids[id] = 1;
|
3158
3155
|
this.setIds(containerSlug, ids);
|
3159
|
-
}
|
3156
|
+
}
|
3160
3157
|
addIdIfNotExists(containerSlug, id){
|
3161
3158
|
if (! this.existsId(containerSlug, id)){
|
3162
3159
|
this.addId(containerSlug, id);
|
3163
3160
|
return true;
|
3164
3161
|
}
|
3165
3162
|
return false;
|
3166
|
-
}
|
3167
|
-
}
|
3168
|
-
|
3169
|
-
|
3170
|
-
},
|
3163
|
+
}
|
3164
|
+
})();
|
3165
|
+
})();
|
3171
3166
|
|
3172
3167
|
// ################################################
|
3173
3168
|
// for node packs:_fs_instance :null,
|
@@ -3180,7 +3175,8 @@ const puvox_library =
|
|
3180
3175
|
// return this._required_instances[name];
|
3181
3176
|
// }
|
3182
3177
|
// },
|
3183
|
-
file
|
3178
|
+
file = new (class {
|
3179
|
+
MAIN_CLASS = self;
|
3184
3180
|
// support for several native modules
|
3185
3181
|
set_module(module) {
|
3186
3182
|
// 'fs'
|
@@ -3195,63 +3191,63 @@ const puvox_library =
|
|
3195
3191
|
else if ('hostname' in module && 'homedir' in module && 'tmpdir' in module && 'platform' in module) {
|
3196
3192
|
this.module_os = module;
|
3197
3193
|
}
|
3198
|
-
}
|
3194
|
+
}
|
3199
3195
|
fs() {
|
3200
3196
|
if(!this.module_fs) {
|
3201
3197
|
throw new Error ('at first, set puvox_library.set_module(require("fs"))');
|
3202
3198
|
}
|
3203
3199
|
return this.module_fs;
|
3204
|
-
}
|
3200
|
+
}
|
3205
3201
|
os() {
|
3206
3202
|
if(!this.module_os) {
|
3207
3203
|
throw new Error ('at first, set puvox_library.set_module(require("os"))');
|
3208
3204
|
}
|
3209
3205
|
return this.module_os;
|
3210
|
-
}
|
3206
|
+
}
|
3211
3207
|
path() {
|
3212
3208
|
if(!this.module_path) {
|
3213
3209
|
throw new Error ('at first, set puvox_library.set_module(require("path"))');
|
3214
3210
|
}
|
3215
3211
|
return this.module_path;
|
3216
|
-
}
|
3212
|
+
}
|
3217
3213
|
// ends with slash
|
3218
|
-
tempDir(){ return
|
3214
|
+
tempDir(){ return this.MAIN_CLASS.trailingSlash(this.os().tmpdir()); }
|
3219
3215
|
|
3220
3216
|
exists(filePath){
|
3221
3217
|
return this.fs().existsSync(filePath);
|
3222
|
-
}
|
3218
|
+
}
|
3223
3219
|
mtime(filePath){
|
3224
3220
|
if (this.exists(filePath)) {
|
3225
3221
|
return (this.fs().statSync(filePath)).mtimeMs;
|
3226
3222
|
} else {
|
3227
3223
|
return null;
|
3228
3224
|
}
|
3229
|
-
}
|
3225
|
+
}
|
3230
3226
|
delete(filePath){
|
3231
3227
|
return (this.unlink(filePath));
|
3232
|
-
}
|
3228
|
+
}
|
3233
3229
|
unlink(filePath){
|
3234
3230
|
return (this.fs().unlinkSync(filePath));
|
3235
|
-
}
|
3231
|
+
}
|
3236
3232
|
createDirectory(dirPath){
|
3237
3233
|
if (!this.exists(dirPath)){
|
3238
3234
|
return this.fs().mkdirSync(dirPath, { recursive: true });
|
3239
3235
|
}
|
3240
3236
|
return true;
|
3241
|
-
}
|
3237
|
+
}
|
3242
3238
|
read(filePath, defaultContent = ''){
|
3243
3239
|
if (!this.exists(filePath)){
|
3244
3240
|
return defaultContent;
|
3245
3241
|
}
|
3246
3242
|
return this.fs().readFileSync(filePath);
|
3247
|
-
}
|
3243
|
+
}
|
3248
3244
|
write(filePath, content){
|
3249
3245
|
const dir = this.path().dirname(filePath);
|
3250
3246
|
this.createDirectory(dir);
|
3251
3247
|
this.fs().writeFileSync(filePath, content, 'utf8', function(err){
|
3252
3248
|
if (err) throw err;
|
3253
3249
|
});
|
3254
|
-
}
|
3250
|
+
}
|
3255
3251
|
getFilesListFromDir (dir) {
|
3256
3252
|
const filesList = [];
|
3257
3253
|
this.fs().readdirSync(dir, (err, files) => {
|
@@ -3260,14 +3256,14 @@ const puvox_library =
|
|
3260
3256
|
});
|
3261
3257
|
});
|
3262
3258
|
return filesList;
|
3263
|
-
}
|
3264
|
-
}
|
3259
|
+
}
|
3260
|
+
})();
|
3265
3261
|
|
3266
3262
|
catchUnhandledExceptions (callback) {
|
3267
3263
|
process.on('uncaughtException', (e) => { callback(e, "exc-uncaught"); });
|
3268
3264
|
process.on('unhandledRejection', (e) => { callback(e, "uexc-nhandled"); });
|
3269
3265
|
process.on('warning', e=>{ callback(e, "exc-warning"); });
|
3270
|
-
}
|
3266
|
+
}
|
3271
3267
|
|
3272
3268
|
|
3273
3269
|
|
@@ -3284,32 +3280,32 @@ const puvox_library =
|
|
3284
3280
|
|
3285
3281
|
// region: ####### from CCXT ##########
|
3286
3282
|
// generic
|
3287
|
-
keys
|
3288
|
-
values(x) { return ((!this.isArray (x)) ? Object.values (x) : x);}
|
3289
|
-
extend(...args) { return Object.assign ({}, ...args) ;}
|
3290
|
-
clone(x){ return (this.isArray (x) ? Array.from (x) : this.extend (x)) ;}
|
3291
|
-
index(x) { return new Set (this.values (x));}
|
3292
|
-
ordered(x) { return x;}
|
3293
|
-
unique(x) { return Array.from (this.index (x));}
|
3294
|
-
arrayConcat (a, b) { return a.concat (b);}
|
3283
|
+
keys= Object.keys;
|
3284
|
+
values(x) { return ((!this.isArray (x)) ? Object.values (x) : x);}
|
3285
|
+
extend(...args) { return Object.assign ({}, ...args) ;} // NB: side-effect free
|
3286
|
+
clone(x){ return (this.isArray (x) ? Array.from (x) : this.extend (x)) ;}
|
3287
|
+
index(x) { return new Set (this.values (x));}
|
3288
|
+
ordered(x) { return x;} // a stub to keep assoc keys in order (in JS it does nothing, it's mostly for Python)
|
3289
|
+
unique(x) { return Array.from (this.index (x));}
|
3290
|
+
arrayConcat (a, b) { return a.concat (b);}
|
3295
3291
|
inArray (needle, haystack) {
|
3296
3292
|
return haystack.includes (needle);
|
3297
|
-
}
|
3293
|
+
}
|
3298
3294
|
toArray (object) {
|
3299
3295
|
return Object.values (object);
|
3300
|
-
}
|
3296
|
+
}
|
3301
3297
|
isEmpty (object) {
|
3302
3298
|
if (!object) {
|
3303
3299
|
return true;
|
3304
3300
|
}
|
3305
3301
|
return (Array.isArray (object) ? object : Object.keys (object)).length < 1;
|
3306
|
-
}
|
3302
|
+
}
|
3307
3303
|
keysort (x, out = {}) {
|
3308
3304
|
for (const k of this.keys (x).sort ()) {
|
3309
3305
|
out[k] = x[k];
|
3310
3306
|
}
|
3311
3307
|
return out;
|
3312
|
-
}
|
3308
|
+
}
|
3313
3309
|
indexBy (x, k, out = {}) {
|
3314
3310
|
// description: https://github.com/ccxt/ccxt/blob/master/js/base/functions/generic.js
|
3315
3311
|
for (const v of this.values (x)) {
|
@@ -3319,7 +3315,7 @@ const puvox_library =
|
|
3319
3315
|
}
|
3320
3316
|
|
3321
3317
|
return out;
|
3322
|
-
}
|
3318
|
+
}
|
3323
3319
|
groupBy (x, k, out = {}) {
|
3324
3320
|
// description: https://github.com/ccxt/ccxt/blob/master/js/base/functions/generic.js
|
3325
3321
|
for (const v of this.values (x)) {
|
@@ -3330,7 +3326,7 @@ const puvox_library =
|
|
3330
3326
|
}
|
3331
3327
|
}
|
3332
3328
|
return out;
|
3333
|
-
}
|
3329
|
+
}
|
3334
3330
|
filterBy (x, k, value = undefined, out = []) {
|
3335
3331
|
// description: https://github.com/ccxt/ccxt/blob/master/js/base/functions/generic.js
|
3336
3332
|
for (const v of this.values (x)) {
|
@@ -3339,7 +3335,7 @@ const puvox_library =
|
|
3339
3335
|
}
|
3340
3336
|
}
|
3341
3337
|
return out;
|
3342
|
-
}
|
3338
|
+
}
|
3343
3339
|
sortBy (array, key, descending = false, direction = descending ? -1 : 1) {
|
3344
3340
|
return array.sort ((a, b) => {
|
3345
3341
|
if (a[key] < b[key]) {
|
@@ -3350,7 +3346,7 @@ const puvox_library =
|
|
3350
3346
|
return 0;
|
3351
3347
|
}
|
3352
3348
|
});
|
3353
|
-
}
|
3349
|
+
}
|
3354
3350
|
sortBy2 (array, key1, key2, descending = false, direction = descending ? -1 : 1) {
|
3355
3351
|
return array.sort ((a, b) => {
|
3356
3352
|
if (a[key1] < b[key1]) {
|
@@ -3367,7 +3363,7 @@ const puvox_library =
|
|
3367
3363
|
}
|
3368
3364
|
}
|
3369
3365
|
});
|
3370
|
-
}
|
3366
|
+
}
|
3371
3367
|
flatten (x, out = []) {
|
3372
3368
|
for (const v of x) {
|
3373
3369
|
if (this.isArray (v)) {
|
@@ -3377,8 +3373,8 @@ const puvox_library =
|
|
3377
3373
|
}
|
3378
3374
|
}
|
3379
3375
|
return out;
|
3380
|
-
}
|
3381
|
-
pluck(x, k) { return this.values (x).filter ((v) => k in v).map ((v) => v[k]);}
|
3376
|
+
}
|
3377
|
+
pluck(x, k) { return this.values (x).filter ((v) => k in v).map ((v) => v[k]);}
|
3382
3378
|
omit (x, ...args) {
|
3383
3379
|
if (!Array.isArray (x)) {
|
3384
3380
|
const out = this.clone (x);
|
@@ -3394,11 +3390,11 @@ const puvox_library =
|
|
3394
3390
|
return out;
|
3395
3391
|
}
|
3396
3392
|
return x;
|
3397
|
-
}
|
3393
|
+
}
|
3398
3394
|
sum (...xs) {
|
3399
3395
|
const ns = xs.filter (isNumber); // leave only numbers
|
3400
3396
|
return (ns.length > 0) ? ns.reduce ((a, b) => a + b, 0) : undefined;
|
3401
|
-
}
|
3397
|
+
}
|
3402
3398
|
deepExtend(...xs) {
|
3403
3399
|
let out = undefined;
|
3404
3400
|
for (const x of xs) {
|
@@ -3414,22 +3410,21 @@ const puvox_library =
|
|
3414
3410
|
}
|
3415
3411
|
}
|
3416
3412
|
return out;
|
3417
|
-
}
|
3413
|
+
}
|
3418
3414
|
// type
|
3419
|
-
isNumber
|
3420
|
-
isInteger
|
3421
|
-
isArray
|
3422
|
-
hasProps (o){ return ((o !== undefined) && (o !== null));}
|
3423
|
-
isString (s){ return (typeof s === 'string');}
|
3424
|
-
isObject (o){ return ((o !== null) && (typeof o === 'object'));}
|
3425
|
-
isRegExp (o){ return (o instanceof RegExp);}
|
3426
|
-
isDictionary(o ){return (this.isObject (o) && (Object.getPrototypeOf (o) === Object.prototype) && !this.isArray (o) && !this.isRegExp (o));}
|
3427
|
-
isStringCoercible(x){ return ((this.hasProps (x) && x.toString) || this.isNumber (x));}
|
3428
|
-
prop (o, k) { return (this.isObject (o) && o[k] !== '' && o[k] !== null ? o[k] : undefined);}
|
3429
|
-
getValueFromKeysInArray(object, array) { return object[array.find (k => this.prop (object,k) !== undefined)];}
|
3415
|
+
isNumber= Number.isFinite;
|
3416
|
+
isInteger= Number.isInteger;
|
3417
|
+
isArray= Array.isArray;
|
3418
|
+
hasProps (o){ return ((o !== undefined) && (o !== null));}
|
3419
|
+
isString (s){ return (typeof s === 'string');}
|
3420
|
+
isObject (o){ return ((o !== null) && (typeof o === 'object'));}
|
3421
|
+
isRegExp (o){ return (o instanceof RegExp);}
|
3422
|
+
isDictionary(o ){return (this.isObject (o) && (Object.getPrototypeOf (o) === Object.prototype) && !this.isArray (o) && !this.isRegExp (o));}
|
3423
|
+
isStringCoercible(x){ return ((this.hasProps (x) && x.toString) || this.isNumber (x));}
|
3424
|
+
prop (o, k) { return (this.isObject (o) && o[k] !== '' && o[k] !== null ? o[k] : undefined);}
|
3425
|
+
getValueFromKeysInArray(object, array) { return object[array.find (k => this.prop (object,k) !== undefined)];}
|
3430
3426
|
asFloat (x) { return ((this.isNumber (x) || (this.isString (x) && x.length !== 0)) ? parseFloat (x) : NaN);}
|
3431
|
-
|
3432
|
-
asInteger(x) { return ((this.isNumber (x) || (this.isString (x) && x.length !== 0)) ? Math.trunc (Number(x)) : NaN);},
|
3427
|
+
asInteger(x) { return ((this.isNumber (x) || (this.isString (x) && x.length !== 0)) ? Math.trunc (Number(x)) : NaN);}
|
3433
3428
|
// safeFloat:(o, k, $default, n = asFloat (prop (o, k))) => (this.isNumber (n) ? n : $default),
|
3434
3429
|
// safeInteger: (o, k, $default, n = asInteger (prop (o, k))) => (this.isNumber (n) ? n : $default),
|
3435
3430
|
// safeTimestamp: (o, k, $default, n = asFloat (prop (o, k))) => (isNumber (n) ? parseInt (n * 1000) : $default),
|
@@ -3452,64 +3447,61 @@ const puvox_library =
|
|
3452
3447
|
else if (unit === 's') { scale = 1; }
|
3453
3448
|
else { throw new NotSupported ('timeframe unit ' + unit + ' is not supported'); }
|
3454
3449
|
return amount * scale;
|
3455
|
-
}
|
3450
|
+
}
|
3456
3451
|
roundTimeframe(timeframe, timestamp, direction = ROUND_DOWN) {
|
3457
3452
|
const ms = this.parseTimeframe (timeframe) * 1000
|
3458
3453
|
// Get offset based on timeframe in milliseconds
|
3459
3454
|
const offset = timestamp % ms
|
3460
3455
|
return timestamp - offset + ((direction === ROUND_UP) ? ms : 0);
|
3461
|
-
}
|
3462
|
-
json(data, params = undefined) { return JSON.stringify (data); }
|
3456
|
+
}
|
3457
|
+
json(data, params = undefined) { return JSON.stringify (data); }
|
3463
3458
|
isJsonEncodedObject (object) {
|
3464
3459
|
return (
|
3465
3460
|
(typeof object === 'string') &&
|
3466
3461
|
(object.length >= 2) &&
|
3467
3462
|
((object[0] === '{') || (object[0] === '['))
|
3468
3463
|
);
|
3469
|
-
}
|
3464
|
+
}
|
3470
3465
|
//htmlentities
|
3471
3466
|
encode_html_entities (content) {
|
3472
3467
|
return content.replace(/[\u00A0-\u9999<>\&]/g, function(i) {
|
3473
3468
|
return '&#'+i.charCodeAt(0)+';';
|
3474
3469
|
});
|
3475
|
-
}
|
3470
|
+
}
|
3476
3471
|
// number
|
3477
3472
|
precisionFromString (string) {
|
3478
3473
|
const split = string.replace (/0+$/g, '').split ('.')
|
3479
3474
|
return (split.length > 1) ? (split[1].length) : 0
|
3480
|
-
}
|
3475
|
+
}
|
3481
3476
|
numberToString (x) { // avoids scientific notation for too large and too small numbers
|
3482
3477
|
if (x === undefined) return undefined; if (typeof x !== 'number') return x.toString (); const s = x.toString (); if (Math.abs (x) < 1.0) { const n_e = s.split ('e-'); const n = n_e[0].replace ('.', ''); const e = parseInt (n_e[1]); const neg = (s[0] === '-'); if (e) { x = (neg ? '-' : '') + '0.' + (new Array (e)).join ('0') + n.substring (neg); return x; } } else { const parts = s.split ('e'); if (parts[1]) { let e = parseInt (parts[1]); const m = parts[0].split ('.'); let part = ''; if (m[1]) { e -= m[1].length; part = m[1]; } return m[0] + part + (new Array (e + 1)).join ('0'); } } return s;
|
3483
|
-
}
|
3478
|
+
}
|
3484
3479
|
// platform
|
3485
|
-
isBrowser
|
3486
|
-
isElectron
|
3487
|
-
isWebWorker
|
3488
|
-
isWindows
|
3480
|
+
isBrowser=typeof window !== 'undefined';
|
3481
|
+
isElectron= typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined';
|
3482
|
+
isWebWorker= typeof WorkerGlobalScope !== 'undefined' && (self instanceof WorkerGlobalScope);
|
3483
|
+
isWindows= typeof process !== 'undefined' && process.platform === "win32";
|
3489
3484
|
// isNode when it's not browser, neither webworker
|
3490
|
-
isNode
|
3491
|
-
defaultFetch
|
3485
|
+
isNode= typeof window === 'undefined' && !(typeof WorkerGlobalScope !== 'undefined' && (self instanceof WorkerGlobalScope));
|
3486
|
+
defaultFetch=fetch;
|
3492
3487
|
//string
|
3493
|
-
uuid (a) { return a ? (a ^ Math.random () * 16 >> a / 4).toString (16) : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace (/[018]/g, uuid);}
|
3494
|
-
capitalize (s) {return s.length ? (s.charAt (0).toUpperCase () + s.slice (1)) : s;}
|
3495
|
-
strip (s) { return s.replace(/^\s+|\s+$/g, '');}
|
3488
|
+
uuid (a) { return a ? (a ^ Math.random () * 16 >> a / 4).toString (16) : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace (/[018]/g, uuid);}
|
3489
|
+
capitalize (s) {return s.length ? (s.charAt (0).toUpperCase () + s.slice (1)) : s;}
|
3490
|
+
strip (s) { return s.replace(/^\s+|\s+$/g, '');}
|
3496
3491
|
// time
|
3497
|
-
now
|
3498
|
-
milliseconds
|
3499
|
-
seconds() { return Math.floor (Date.now () / 1000);}
|
3492
|
+
now = Date.now;
|
3493
|
+
milliseconds=Date.now; // milliseconds(){ return (new Date().getTime()); },
|
3494
|
+
seconds() { return Math.floor (Date.now () / 1000);}
|
3500
3495
|
// endregion: ####### from CCXT ##########
|
3501
|
-
|
3502
|
-
|
3503
|
-
|
3504
|
-
};
|
3496
|
+
}
|
3505
3497
|
|
3506
3498
|
|
3507
3499
|
// export to outside world
|
3508
3500
|
if (typeof module != 'undefined' && module.hasOwnProperty('exports')) {
|
3509
|
-
module.exports =
|
3501
|
+
module.exports = PuvoxLibrary;
|
3510
3502
|
}
|
3511
3503
|
if (typeof window != 'undefined') {
|
3512
|
-
window['PuvoxLibrary'] =
|
3504
|
+
window['PuvoxLibrary'] = PuvoxLibrary;
|
3513
3505
|
}
|
3514
3506
|
|
3515
3507
|
// export default puvox_library;
|