puvox-library 1.0.1 → 1.0.2
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 +87 -43
- package/package.json +1 -1
package/library_standard.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
/**
|
2
2
|
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
3
|
+
* ################################################################################
|
4
|
+
* ############################### Our JS Library ##############################
|
5
|
+
* ##### Here we collect frequently used methods across our JS applications. #####
|
6
|
+
* ##### (Some of them are generic javascript functions, some are for NodeJS) #####
|
7
|
+
* ################################################################################
|
8
8
|
*
|
9
|
-
*
|
10
|
-
*
|
9
|
+
* ########## Example usage: ##########
|
10
|
+
* const helpers = new PuvoxLibrary();
|
11
11
|
* console.log ( helpers.get_last_child_of_array(array) );
|
12
12
|
* console.log ( helpers.get_visitor_ip() );
|
13
13
|
* ... etc
|
@@ -159,6 +159,9 @@ const puvox_library =
|
|
159
159
|
return this.stringArrayToNumeric(this.stringToArray(arr));
|
160
160
|
},
|
161
161
|
|
162
|
+
objectCopy(obj){
|
163
|
+
return JSON.parse(JSON.stringify(obj));
|
164
|
+
},
|
162
165
|
// https://stackoverflow.com/a/44782052/2377343
|
163
166
|
cloneObjectDestructuve(orig){
|
164
167
|
return Object.assign(Object.create(Object.getPrototypeOf(orig)), orig);
|
@@ -393,9 +396,6 @@ const puvox_library =
|
|
393
396
|
isException(e){
|
394
397
|
return e && e.stack && e.message;
|
395
398
|
},
|
396
|
-
objectCopy(obj){
|
397
|
-
return JSON.parse(JSON.stringify(obj));
|
398
|
-
},
|
399
399
|
IsJsonString (str) {
|
400
400
|
try {
|
401
401
|
JSON.parse(str);
|
@@ -1201,7 +1201,18 @@ const puvox_library =
|
|
1201
1201
|
);
|
1202
1202
|
} ,
|
1203
1203
|
|
1204
|
-
|
1204
|
+
// more from locutus: https://github.com/locutusjs/locutus/blob/master/src/php
|
1205
|
+
strip_tags (input, allowed) {
|
1206
|
+
allowed = (((allowed || '') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');
|
1207
|
+
const tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
|
1208
|
+
const commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
|
1209
|
+
return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
|
1210
|
+
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
|
1211
|
+
});
|
1212
|
+
},
|
1213
|
+
|
1214
|
+
br2nl(content) { return content.replace('/\<br(\s*)?\/?\>/i', "\n"); },
|
1215
|
+
|
1205
1216
|
jquery_popup(element, isModal, params){
|
1206
1217
|
var isModal = isModal || true;
|
1207
1218
|
var params = params || {};
|
@@ -1595,18 +1606,18 @@ const puvox_library =
|
|
1595
1606
|
|
1596
1607
|
|
1597
1608
|
|
1598
|
-
//
|
1609
|
+
// ============================= get basename of url ============================
|
1599
1610
|
basename(path) { return path.split('/').reverse()[0]; },
|
1600
1611
|
|
1601
1612
|
|
1602
|
-
//
|
1613
|
+
// ======== simple POPUP ======== https://github.com/ttodua/useful-javascript/ ==============
|
1603
1614
|
show_my_popup(TEXTorID, AdditionalStyles ){
|
1604
1615
|
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));
|
1605
1616
|
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 || '';
|
1606
1617
|
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";} },
|
1607
1618
|
my_popup_closee(RandomIDD) { var x=document.getElementById("blkBackgr_"+RandomIDD); x.parentNode.removeChild(x); var x=document.getElementById('popupp_'+RandomIDD); x.parentNode.removeChild(x);
|
1608
1619
|
},
|
1609
|
-
//
|
1620
|
+
// ========================================================== //
|
1610
1621
|
|
1611
1622
|
|
1612
1623
|
|
@@ -1637,11 +1648,11 @@ const puvox_library =
|
|
1637
1648
|
var x =document.getElementById(elementID); if (x) x.parentNode.removeChild(x);
|
1638
1649
|
}
|
1639
1650
|
},
|
1640
|
-
//
|
1651
|
+
// ========================================================== //
|
1641
1652
|
|
1642
1653
|
|
1643
1654
|
|
1644
|
-
//
|
1655
|
+
// ============================= AJAX EXAMPLES =============== https://github.com/ttodua/useful-javascript/ ===============
|
1645
1656
|
myyAjaxRequest(parameters, url, method, func, ShowBlackground){ ShowBlackground= ShowBlackground || false;
|
1646
1657
|
method = method.toLowerCase() || "post"; if (method == "get") {url=url+'?'+parameters+'&MakeRandomValuedLinkToAvoidCache=' + Math.random();}
|
1647
1658
|
if(ShowBlackground) {Loader(true);} try{try{var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} catch( e ){var xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}}catch(e){var xmlhttp = new XMLHttpRequest();}
|
@@ -1652,7 +1663,7 @@ const puvox_library =
|
|
1652
1663
|
if (method == "post"){xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send(parameters);}
|
1653
1664
|
else if (method == "get"){xmlhttp.send(null);}
|
1654
1665
|
},
|
1655
|
-
//
|
1666
|
+
// ========================================================== //
|
1656
1667
|
|
1657
1668
|
|
1658
1669
|
//all divs, which has a classname "My_TARGET_Hiddens", will be automatically hidden on page load...
|
@@ -1720,7 +1731,7 @@ const puvox_library =
|
|
1720
1731
|
responseStringify(obj_or_text){
|
1721
1732
|
return ! this.is_object(obj_or_text) ? obj_or_text : ( 'responseText' in obj_or_text ? obj_or_text.responseText : JSON.stringify(obj_or_text) );
|
1722
1733
|
},
|
1723
|
-
//
|
1734
|
+
// ============================= getElementById from parent_node ========== http://stackoverflow.com/a/5683184/2377343 ==========
|
1724
1735
|
//Element.prototype.getElementById_FROM_PARENT = function(req) {
|
1725
1736
|
getElementById_FROM_PARENT(req) {
|
1726
1737
|
var elem = this, children = elem.childNodes, i, len, id;
|
@@ -1733,7 +1744,7 @@ const puvox_library =
|
|
1733
1744
|
}
|
1734
1745
|
return null; // if no match found
|
1735
1746
|
},
|
1736
|
-
//
|
1747
|
+
// ========================================================== //
|
1737
1748
|
|
1738
1749
|
|
1739
1750
|
inArray(haystack, needle) {
|
@@ -1770,7 +1781,7 @@ const puvox_library =
|
|
1770
1781
|
},
|
1771
1782
|
|
1772
1783
|
|
1773
|
-
//
|
1784
|
+
// ============================= URL parameters ============================= //
|
1774
1785
|
// executed below
|
1775
1786
|
GetQueryParams(url) {
|
1776
1787
|
// This function is anonymous, is executed immediately and
|
@@ -1939,7 +1950,7 @@ const puvox_library =
|
|
1939
1950
|
search ?foo=789
|
1940
1951
|
hash #tab2
|
1941
1952
|
*/
|
1942
|
-
//
|
1953
|
+
// ============================= URL parameters ============================= //
|
1943
1954
|
|
1944
1955
|
|
1945
1956
|
|
@@ -2013,7 +2024,7 @@ const puvox_library =
|
|
2013
2024
|
|
2014
2025
|
//add hovered class on element
|
2015
2026
|
addHovered(elem){ if( elem.hasClass("hoveredd")) { elem.removeClass("hoveredd");} else { elem.addClass("hoveredd"); } },
|
2016
|
-
//
|
2027
|
+
// ========================================================== //
|
2017
2028
|
|
2018
2029
|
|
2019
2030
|
// hide content if chosen radio box not chosen
|
@@ -2054,7 +2065,7 @@ const puvox_library =
|
|
2054
2065
|
},
|
2055
2066
|
|
2056
2067
|
|
2057
|
-
|
2068
|
+
// ============================= youtube modal popup ============================= //
|
2058
2069
|
showYtVideo(options) {
|
2059
2070
|
options = $.extend({ content:0, url:0, videoId: '', modalSize: 'm', shadowOpacity: 0.5, shadowColor: '#000', clickOutside: 1, closeButton: 1, autoplay: 0, start: 0, oncall: '' }, options);
|
2060
2071
|
var styleee = $('<style> .modal { box-shadow: 0px 0px 40px white; padding: 0px; left: 50%; top: 50%; position: fixed; z-index: 500; background: #fff; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; } .modal{max-width:80%;max-height:80%;} .modal.size-m { width: 600px; height: 400px; } .modal.size-l { width: 700px; height: 500px; } .modal.size-s { width: 500px; height: 300px; } .modal-bg { position: fixed; height: 100%; width: 100%; opacity: 0.5; top: 0; left: 0; z-index: 100; } .modal-close { color: #b1b0ac; font-size: 30px; line-height: .5; position: absolute; top: -18px; right: -18px; font-weight: bold; cursor: pointer; } .modal-close:hover { color: #e72626; }</style>'); styleee.appendTo('body');
|
@@ -2096,7 +2107,7 @@ const puvox_library =
|
|
2096
2107
|
$(".modal-bg").remove();
|
2097
2108
|
});
|
2098
2109
|
},
|
2099
|
-
//
|
2110
|
+
// ============================= Youtube popup ============================= //
|
2100
2111
|
|
2101
2112
|
|
2102
2113
|
forEachDefine(){
|
@@ -2165,7 +2176,7 @@ const puvox_library =
|
|
2165
2176
|
|
2166
2177
|
var_dump(array){ var o=""; for (x in array) { o += x + ": " + array[x]+"; "; } window.console && console.log(o); },
|
2167
2178
|
|
2168
|
-
//
|
2179
|
+
// ============================= POST REQUEST SEND (LIVE FORM CREATION) ============================= //
|
2169
2180
|
//USAGE: postForm( {deletecityy:'hihi', surname: 'blabla'}, 'Are you sure?' , 'http://yoursite.com' , '_blank');
|
2170
2181
|
postForm(params,ConfirmMessage, path, method, targett) {
|
2171
2182
|
if (typeof ConfirmMessage != 'undefined' && ConfirmMessage != '') { if(!confirm(ConfirmMessage)){return;}}
|
@@ -2184,10 +2195,10 @@ const puvox_library =
|
|
2184
2195
|
}
|
2185
2196
|
document.body.appendChild(form); form.submit();
|
2186
2197
|
},
|
2187
|
-
|
2198
|
+
// ==========================================================
|
2188
2199
|
|
2189
2200
|
|
2190
|
-
//
|
2201
|
+
// ============================= Show Hint On MouseOver =============================
|
2191
2202
|
SetShowHint(elemnt,text, left, top){
|
2192
2203
|
elemnt.onmouseover = function(e){ Hinttttt = document.createElement('div'); Hinttttt.className="myHintClass"; Hinttttt.innerHTML = text; document.body.appendChild(Hinttttt); this.SetPoistion(e,element); };
|
2193
2204
|
elemnt.onmousemove = function(e){ this.SetPoistion(e,element) };
|
@@ -2196,12 +2207,12 @@ const puvox_library =
|
|
2196
2207
|
//
|
2197
2208
|
this.SetPoistion=function(e){ e.target.style.top= parseInt(e.pageY+top)+'px'; e.target.style.left= parseInt(e.pageX + left) + 'px'; };
|
2198
2209
|
},
|
2199
|
-
|
2210
|
+
// ==========================================================
|
2200
2211
|
|
2201
2212
|
|
2202
|
-
//
|
2203
|
-
//
|
2204
|
-
//
|
2213
|
+
// ========================================================== //
|
2214
|
+
// ==================== IMAGE PROPORTIONS ================== //
|
2215
|
+
// ========================================================== //
|
2205
2216
|
|
2206
2217
|
|
2207
2218
|
Balance_Target_Image(img, widthh, heightt){
|
@@ -2274,11 +2285,10 @@ const puvox_library =
|
|
2274
2285
|
|
2275
2286
|
}
|
2276
2287
|
},
|
2277
|
-
|
2278
|
-
//
|
2279
|
-
//
|
2280
|
-
|
2281
|
-
|
2288
|
+
// ========================================================= //
|
2289
|
+
// ================= ### IMAGE PROPORTIONS ================= //
|
2290
|
+
// ========================================================= //
|
2291
|
+
|
2282
2292
|
show_after_pageload(el){
|
2283
2293
|
var el = el || '.show_after_pageload';
|
2284
2294
|
this.Append_To_Head("style", 'body '+el+' {opacity:1;}');
|
@@ -2288,7 +2298,7 @@ const puvox_library =
|
|
2288
2298
|
this.Append_To_Head("style", 'body '+el+' {display:none;}');
|
2289
2299
|
},
|
2290
2300
|
|
2291
|
-
//
|
2301
|
+
// ==================== Position ==================== //
|
2292
2302
|
Highlight_Current_Menu_link(Added_class_name, Ancestor_to_search_in, link_to_find){
|
2293
2303
|
var Added_class_name = Added_class_name || "current_item__from_JS";
|
2294
2304
|
var link_to_find = link_to_find || window.location.pathname;
|
@@ -2308,7 +2318,7 @@ const puvox_library =
|
|
2308
2318
|
},
|
2309
2319
|
//remove # from location
|
2310
2320
|
RemoveHashString(str){ var hash=str.split("#")[1]; return str.replace("#"+hash,''); },
|
2311
|
-
//
|
2321
|
+
// ===================================================================//
|
2312
2322
|
|
2313
2323
|
|
2314
2324
|
getCharsFromStart(str, amount){
|
@@ -2318,7 +2328,7 @@ const puvox_library =
|
|
2318
2328
|
return str.substring(str.length-amount, str.length);
|
2319
2329
|
},
|
2320
2330
|
|
2321
|
-
//
|
2331
|
+
// ============================= Position ============================= //
|
2322
2332
|
GetTopLeft(myyElement) {
|
2323
2333
|
var offset = {x : 0, y : 0}; this.GetOffset (myyElement, offset);
|
2324
2334
|
var scrolled = {x : 0, y : 0}; this.GetScrolled (myyElement.parentNode, scrolled);
|
@@ -2335,9 +2345,9 @@ const puvox_library =
|
|
2335
2345
|
scrolled.x += object.scrollLeft; scrolled.y += object.scrollTop;
|
2336
2346
|
if (object.tagName.toLowerCase () != "html") { this.GetScrolled (object.parentNode, scrolled); }
|
2337
2347
|
},
|
2338
|
-
//
|
2348
|
+
// ============================= ##Position ============================= //
|
2339
2349
|
|
2340
|
-
//
|
2350
|
+
// ============================= ## jQUery Fixed navigation ============================= //
|
2341
2351
|
MakeFixed(selector, ExtraHeightToBody){
|
2342
2352
|
var sticky = $(selector);
|
2343
2353
|
var StickyHeight=parseInt(sticky.height());
|
@@ -2350,7 +2360,7 @@ const puvox_library =
|
|
2350
2360
|
else { if( sticky.hasClass('fixed_stickyy')){sticky.removeClass('fixed_stickyy');} }
|
2351
2361
|
});
|
2352
2362
|
},
|
2353
|
-
//
|
2363
|
+
// ========================================================== //
|
2354
2364
|
|
2355
2365
|
triggerWhenElementInView(el, func){
|
2356
2366
|
var element_ = el;
|
@@ -2409,7 +2419,7 @@ const puvox_library =
|
|
2409
2419
|
|
2410
2420
|
|
2411
2421
|
|
2412
|
-
//
|
2422
|
+
// ============================= detect mobile device ============================= //
|
2413
2423
|
IsMobileDevice(simpleORfull){
|
2414
2424
|
var simpleORfull = simpleORfull || "simple";
|
2415
2425
|
var navigtr=navigator.userAgent||navigator.vendor||window.opera;
|
@@ -2442,6 +2452,39 @@ const puvox_library =
|
|
2442
2452
|
},
|
2443
2453
|
|
2444
2454
|
|
2455
|
+
// region ### TELEGRAM FUNCTIONS ###
|
2456
|
+
// public function telegram($text) { return $helpers->telegram_message( ['chat_id'=>'-1001234567890', 'text'=>$text, 'parse_mode'=>'html', 'disable_web_page_preview'=>true ], $bot_key ); } | resp: pastebin_com/u0J1Cph3
|
2457
|
+
async telegram_message(opts = {text: 'Hi', chat_id:'-1001234567890'}, bot_id, is_repeated_call=false){
|
2458
|
+
opts['disable_web_page_preview'] = 'disable_web_page_preview' in opts ? opts['disable_web_page_preview'] : true;
|
2459
|
+
// opts['chat_id'] = opts['chat_id'].toString().substring(0,4) == '-100' ? opts['chat_id'].toString() : '-100' + opts['chat_id'].toString(); opts['chat_id'] = parseInt(opts['chat_id']);
|
2460
|
+
opts['text'] = this.stripTags(this.br2nl(opts['text']),'<b><strong><i><em><u><ins><s><strike><del><a><code><pre>'); // allowed: https://core.telegram.org/bots/api#html-style
|
2461
|
+
opts['text'] = opts['text'].substring(0, 4095); //max telegram message length 4096
|
2462
|
+
const responseText = await (await fetch('https://api.telegram.org/bot'+ bot_id +'/sendMessage', { method: 'POST', headers: { 'Content-Type': 'application/json' + (0 ? 'application/x-www-form-urlencoded':'') }, body: JSON.stringify(opts)})).text(); //'sendMessage?'.http_build_query($array, '');
|
2463
|
+
try {
|
2464
|
+
const responseJson = JSON.parse(responseText);
|
2465
|
+
if (responseJson.ok){
|
2466
|
+
return response;
|
2467
|
+
} else {
|
2468
|
+
//i.e. {"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: Unsupported start tag \"br/\" at byte offset 43"}
|
2469
|
+
// for some reason, if still unsupported format submitted, resubmit the plain format
|
2470
|
+
const txt = "Bad Request: can't parse entities";
|
2471
|
+
if( response.description.indexOf (txt)> -1 ){
|
2472
|
+
const newOpts = this.objectCopy(opts);
|
2473
|
+
newOpts['text'] = "[SecondSend] \r\n". this.stripTags(newOpts['text']) ;
|
2474
|
+
if ( ! repeated_call ){
|
2475
|
+
return this.telegram_message(newOpts, bot_id, true);
|
2476
|
+
} else {
|
2477
|
+
return response;
|
2478
|
+
}
|
2479
|
+
} else {
|
2480
|
+
return response;
|
2481
|
+
}
|
2482
|
+
}
|
2483
|
+
} catch (ex) {
|
2484
|
+
return {'ok': false, 'description': responseText };
|
2485
|
+
}
|
2486
|
+
},
|
2487
|
+
|
2445
2488
|
openUrlInBrowser(url)
|
2446
2489
|
{
|
2447
2490
|
var cmd = (process.platform == 'darwin'? `open ${url}`: process.platform == 'win32'? `start ${url}`: `xdg-open ${url}`);
|
@@ -2591,6 +2634,7 @@ const puvox_library =
|
|
2591
2634
|
}
|
2592
2635
|
},
|
2593
2636
|
async getRemoteData(url){
|
2637
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
|
2594
2638
|
return await (await fetch(url)).text();
|
2595
2639
|
// return new Promise ((resolve, reject) => {
|
2596
2640
|
// try {
|