1/* 2===== 3functions/detections: 4 5file_upload_delete() 6file_upload_reset() 7file_upload_set() 8form_submit() -- includes recaptcha validation 9generate_password() 10hide_featured_img() 11htmlentities 12isJson() 13js_back() 14local_storage_debug() 15move_form_labels() 16optimage() 17password_chars_showhide() 18pcp() -- password confirm password form submit 19prevent_double_click() 20slider() 21spinner_load() 22spinner_show() 23scrollto() 24tabs() 25validate_ajax() 26wrappers_inner() 27wrappers_outer() 28===== 29*/ 30 31// GLOBALS =============================================================== 32if (typeof $jsphp_vars['current_rel_uri'] != 'undefined') { 33 $current_rel_uri = $jsphp_vars['current_rel_uri']; 34} 35// /GLOBALS =============================================================== 36 37// TRIGGER VARS ========================================================== 38// $enable_recaptcha = false; 39$enable_recaptcha = true; 40 41// $recaptcha_bot_level = 0.2; 42$recaptcha_bot_level = 0.3; 43// $recaptcha_bot_level = 0.4; 44// /TRIGGER VARS ========================================================== 45 46// MISC =================================================================== 47/** 48 * htmlentities 49 * modded from https://ourcodeworld.com/articles/read/188/encode-and-decode-html-entities-using-pure-javascript 50 * by DP 51 */ 52window.htmlentities = { 53 /** 54 * Converts a string to its html characters completely. 55 * 56 * @param {String} str String with unescaped HTML characters 57 **/ 58 encode : function(str) { 59 var buf = []; 60 61 for (var i=str.length-1;i>=0;i--) { 62 buf.unshift(['&#', str[i].charCodeAt(), ';'].join('')); 63 } 64 65 return buf.join(''); 66 }, 67 /** 68 * Converts an html characterSet into its original character. 69 * 70 * @param {String} str htmlSet entities 71 **/ 72 decode : function(str) { 73 return str.replace(/&#(\d+);/g, function(match, dec) { 74 return String.fromCharCode(dec); 75 }); 76 } 77};// /window.htmlentities = { 78 79/** 80 * isJson() 81 * test if a string can be parsed as json 82 * from: https://www.codegrepper.com/code-examples/javascript/javascript+check+if+string+is+json+parsable 83 */ 84isJson = (str) => { 85 try { 86 return JSON.parse(str); 87 } catch (e) { 88 return false; 89 } 90} 91 92/** 93 * js_back() 94 * a simple back button 95 * 96 */ 97jQuery(document).ready(function($) { 98 $(document).on('click','.js-back',function($e){ 99 $e.preventDefault(); 100 js_back(); 101 }); 102}); 103function js_back() { 104 history.back(); 105} 106 107/** 108 * local_storage_debug() 109 * print to console all localStorage key/values 110 * 111 */ 112function local_storage_debug() { 113 for (var $k in localStorage) { 114 if (typeof localStorage[$k] === 'function') {continue;} 115 console.log($k, ' = ', localStorage[$k]); 116 }// /for (var $k in localStorage) { 117}// /function local_storage_debug() { 118 119/** 120 * scrollto() 121 * scroll to anchor 122 * on page load, select change and link click 123 */ 124jQuery(document).ready(function($) { 125 $('a').on('click',function ($e) { 126 //use like: <a href="/myfolder/#fred">Fred</a> <a name="fred" id="fred"></a> 127 if ($(this).prop('hash') !== '') { 128 // console.log('$(this)',$(this)); 129 if (typeof $(this).attr('fancybox-inline') != 'undefined') {return false;} 130 scrollto($(this).prop('hash')); 131 } 132 }); 133 $('select').change(function($e){ 134 if($(this).val().charAt(0) == '#') { 135 $e.preventDefault(); 136 scrollto($(this).val()); 137 } 138 }); 139 $(window).ready(function(){ 140 if (location.hash) {scrollto(location.hash);} 141 }); 142});// /jQuery(document).ready(function($) { 143function scrollto(hash) { 144 jQuery(document).ready(function($) { 145 console.log('hash:',hash); 146 if (typeof(hash) == 'undefined' || hash == '') {return false;} 147 var $target = $(hash); 148 if (typeof $target.offset() == 'undefined') {return false;} 149 $('html, body').stop().animate({ 150 'scrollTop': parseInt($target.offset().top)-150 151 }, 900, 'swing'); 152 });// /jQuery(document).ready(function($) { 153}// /function scrollto (hash) { 154 155/** 156 * slider() 157 * slide rotator 158 * modded from hp-darrel.js upcoming events rotator 159 * 160 * @param string $slider REQUIRED 161 * @param int data-timer -- in milliseconds 162 * @param int data-timer_resume -- milliseconds 163 * 164 * @since 2021-02 - TW 165 * 166 * use like, (in WP use group and/or columns for div's): 167 * <div class="slider"> 168 * <div class="slide">$content</div> 169 * <div class="slide">$content</div> 170 * </div> 171 * 172 * css like: 173.slider { 174border: solid 10px red; 175} 176.slide { 177 opacity: 0; 178 transition: 0.5s opacity; 179border: solid 10px green; 180} 181.slide:not(:first-of-type) { 182 position: absolute; 183 top: 0; 184 left: 0; 185} 186.slide .wp-block-column { 187border: solid 10px yellow; 188} 189.slide.slide-current { 190 opacity: 1;
191} 192.slider-nav-container { 193 display: flex; 194 justify-content: flex-start; 195border: solid 10px blue; 196} 197.slide-nav { 198 width: 20px; 199 height: 20px; 200 margin-right: 10px; 201 background-color: rgba(0,0,0,1); 202 border-radius: 20px; 203 cursor: pointer; 204 transition: 0.5s all; 205} 206.slide-nav.slide-nav-current { 207 background-color: rgba(255,255,255,1); 208} 209 */ 210jQuery(document).ready(function($) { 211 $('.slider').each(function($k,$v){ 212 slider($(this)); 213 }); 214});// /jQuery(document).ready(function($) { 215function slider($obj) { 216 jQuery(document).ready(function($) { 217 //console.log('$obj:',$obj); 218 //console.log('$obj.find(\'.slide\'):',$obj.find('.slide')); 219 220 var $timer = 4000; 221 if (typeof $obj.attr('data-timer') != 'undefined') {$timer = parseInt($obj.attr('data-timer'));} 222 //console.log('$timer:',$timer); 223 224 var $timer_resume = 10000; 225 if (typeof $obj.attr('data-timer_resume') != 'undefined') {$timer_resume = parseInt($obj.attr('data-timer_resume'));} 226 //console.log('$timer_resume:',$timer_resume); 227 228 var $slides_count = $obj.find('.slide').length; 229 var $slide_current = $slides_count; 230 if ($slides_count > 0) { 231 if ($slides_count > 1) { 232 // add the nav 233 $obj.append('<div class="slider-nav-container"></div>'); 234 for(var $n = 1; $n <= $slides_count; $n++) { 235 $obj.find('.slider-nav-container').append('<div class="slide-nav" data-num="'+$n+'"></div>'); 236 } 237 238 // start the timer 239 var $slidetimer = setInterval(function(){slide_display()},$timer); 240 }// /if ($slides_count > 1) { 241 242 // now show the first slide 243 slide_display(); 244 }// /if ($slides_count > 0) { 245 246 $obj.find('.slide-nav').on('click',function(){ 247 // stop the timer 248 clearInterval($slidetimer); 249 $slidetimer = null; 250 251 // restart the timer after x seconds 252 setTimeout(function(){ 253 $slidetimer = setInterval(function(){slide_display()},$timer); 254 },$timer_resume); 255 256 // set the clicked slide to current 257 $slide_current = ($(this).attr('data-num')-1); 258 slide_display(); 259 260 });// /$('.slide-nav').on('click',function(){ 261 262 function slide_display() { 263 //console.log('$obj:',$obj); 264 $obj.find('.slide').removeClass('slide-current'); 265 $slide_current = ($slide_current%$slides_count)+1;//console.log('$slide_current:',$slide_current); 266 $obj.find('.slide:nth-of-type('+$slide_current+')').addClass('slide-current'); 267 268 $obj.find('.slide-nav').removeClass('slide-nav-current'); 269 $obj.find('.slide-nav:nth-of-type('+$slide_current+')').addClass('slide-nav-current'); 270 }// /function slide_display() { 271 });// /jQuery(document).ready(function($) { 272}// /function slider() { 273 274/** 275 * spinner_load() 276 * DOM insert modal background with a css animated div, hidden by default 277 * see also ../css/style-custom.css spinner 278 */ 279spinner_load(); 280function spinner_load() { 281 jQuery(document).ready(function($) { 282 var popup = '<div class="hp-spinnerpopup" style="display:none;position:fixed;top:0px;left:0px;z-index:20000;width:100%;height:100%;background-color: rgba(0,0,0,0.5);"><div id="loader"></div></i></div>'; 283 284 $('body').append(popup); 285 286 var $viewport_height = parseInt($(window).height());//console.log($viewport_height); 287 $('.hp-spinnerpopup').css('padding-top',(($viewport_height/2)-60)+'px'); 288 289 $('body').on('click','.show_spinner',function($e){spinner_show();}); 290 291 window.default_alert = window.alert;// hold original alert obj 292 window.alert = function() { 293 $('.hp-spinnerpopup').hide(); 294 default_alert(arguments[0]); 295 return; 296 } 297 });// /jQuery(document).ready(function($) { 298}// /function spinner_load() { 299 300/** 301 * spinner_show() 302 * show/hide from spinner_load() above 303 * 304 * can also instead simply use the show() hide() in a page 305 * to progammatically determine when to show/hide, 306 * such as on an ajax send/return 307 * 308 * @param int $length -- length in milliseconds before hiding the spinner popup 309 */ 310function spinner_show($length) { 311 jQuery(document).ready(function($) { 312 //console.log('$length:',$length); 313 if ( 314 typeof $length == 'undefined' 315 || $length == '' 316 || $length == 0 317 || !$length 318 ) { 319 $length = 10000; 320 } 321 $('.hp-spinnerpopup').show(); 322 window.setTimeout(function(){ 323 $('.hp-spinnerpopup').hide(); 324 },$length); 325 });// /jQuery(document).ready(function($) { 326}// /function spinner_show() { 327 328/** 329 * tabs() 330 * HTML like: 331<div class="tabs"> 332 333<div class="tabs-nav"> 334<div class="active" data-tab="tab-name1">Name 1</div> 335<div data-tab="tab-name2">Name 2</div> 336</div><!-- class="tabs-nav"--> 337 338<div class="tab active" id="tab-name1"> 339<content here> 340</div><!-- class="tab"--> 341 342<div class="tab" id="tab-name2"> 343<content here> 344</div><!-- class="tab"--> 345 346</div><!-- class="tabs"--> 347 348 * CSS like: 349.tabs { 350} 351.tabs-nav { 352 position: relative; 353 z-index: 10000; 354 border-bottom: solid 1px #000; 355} 356.tabs-nav div {
357 display: inline-block; 358 padding: 3px 3px 3px 3px; 359 color: #ccc; 360 border-style: solid; 361 border-width: 1px 0px 0px 1px; 362 border-color: #000000; 363 cursor: pointer; 364} 365.tabs-nav div:last-child { 366 border-right-width: 1px; 367} 368.tabs-nav div.active{ 369 color: #000; 370} 371.tab { 372 display: none; 373} 374.tab.active { 375 display: block; 376} 377 */ 378function tabs() { 379 jQuery(document).ready(function($) { 380 $('.tabs-nav div').click(function($e){ 381 $e.preventDefault(); 382 383 var $tabs = $(this).closest('.tabs'); 384 var $tabs_nav = $(this).closest('.tabs-nav'); 385 var $target = $(this).attr('data-tab'); 386 387 $tabs_nav.find('div').removeClass('active'); 388 $(this).addClass('active'); 389 390 $tabs.find('.tab').hide(); 391 $('#'+$target).show(); 392 });// /$('.tabs-nav div').click(function($e){ 393 });// /jQuery(document).ready(function($) { 394}// /function tabs() { 395tabs(); 396// /MISC =================================================================== 397 398// FORMS =================================================================== 399/* 400NOTE: 2020-06-12 401some of the below have been rebuilt and may not function correctly, test before deployment!!!!! 402*/ 403 404// move labels ============================================= 405/** 406 * move_form_labels() 407 * move form labels inside of form elements: text, textarea 408 * see also see also style-custom.css label {} for the inital hide of labels 409 * 410 * must be in separate function if form is inserted in the dom via ajax or other mechanism, 411 * ex: see /admintools-3/api.js at3_form_print() 412 */ 413move_form_labels(); 414function move_form_labels() { 415 jQuery(document).ready(function($) { 416 // if element is pre-populated, add .label-pos-focused to the container 417 418 // move selected form element labels ========== 419 // see ../php/shortcodes-form.php [password],[text],[textarea] 420 var $container = $('.input-password-container,.input-text-container,.input-textarea-container'); 421 $container.addClass('label-pos'); 422 423 var $elements = 'input[type=password],input[type=text],textarea'; 424 // console.log('$elements:',$elements); 425 426 // $container.find('input[type=text]').blur();// removes autofocus if set 427 if ($container.find('input[type=text]').prop('autofocus')) { 428 $container.find('input[type=text]').blur(); 429 } 430 431 $container.each(function($k,$v){ 432 // console.log('$v:',$v); 433 // console.log('$(this)',$(this)); 434 var $_this = $(this); 435 var $val = $_this.find($elements).val(); 436 // console.log('$val:',$val.length); 437 if (typeof $val !== 'undefined' && $val.length > 0) {$_this.addClass('label-pos-focused');} 438 // console.log('$_this.attr(\'class\')',$_this.attr('class')); 439 440 // show the labels, see also style-custom.css label {} 441 $_this.find('label').show(); 442 443 $_this.find($elements).on('focus',function(){ 444 $_this.addClass('label-pos-focused'); 445 }); 446 $_this.find('label').on('click',function(){ 447 $_this.addClass('label-pos-focused'); 448 $_this.find($elements).focus(); 449 }); 450 $_this.find($elements).on('blur',function(){ 451 if ($(this).val() == '') { 452 $_this.removeClass('label-pos-focused'); 453 } 454 }); 455 });// /$container.each(function($k,$v){ 456 // /move selected form element labels ========== 457 458 // refocus on the last autofocus ========== 459 /* 460 NOTE: DO NOT HAVE CONSOLE OPEN OR THIS WILL NOT FOCUS!!!!! 461 Also, a timeout will NOT steal focus from the console, so don't try it 462 */ 463 $.each($('input[type=text]'),function($k,$v){ 464 if ($(this).prop('autofocus')) { 465 $(this).focus(); 466 } 467 });// /$.each($('input[type=text]'),function($k,$v){ 468 // /refocus on the last autofocus ========== 469 470 // suspenders/belt -- make sure labels are shown in case dom inserted 471 setTimeout(function(){ 472 $('label').show(); 473 },1600); 474 475 });// /jQuery(document).ready(function($) { 476}// /function move_form_labels() { 477// /move labels ============================================= 478 479// validate on submit ============================================ 480/** 481 * form_submit() 482 * validate forms on submit IF the form has data-validate="true" 483 * 484 * if data-validate == to an existing function, that function will be called, ex: 485 * [form2 name="password_confirm_password" validate="pcp"] will call this function: pcp() 486 * modded from: https://www.labnol.org/code/20181-call-javascript-function-by-name 487 * 488 * for recaptcha v3: 489 * if a form has attr('data-recaptcha') == true 490 * and attr('data-rsk') != 'undefined', i.e. has the public key 491 * on recaptcha fail, redirects to wp page /bot/ 492 * 493 * see ../php/shortcodes-form-2.php [form2] 494 */ 495jQuery(document).ready(function($) { 496 $('form').on('submit',function($e){ 497 498 // call a specific submit function: 499 if ( 500 typeof $(this).attr('data-validate') !== 'undefined' 501 && typeof window[$(this).attr('data-validate')] === 'function'// $(this).attr('data-validate') == 'pcp' 502 ) { 503 window[$(this).attr('data-validate')]($e,$(this));//pcp($e,$(this)); 504 } 505 506 // use the generic submit function 507 else { 508 form_submit($e,$(this)); 509 } 510 });// /$('form').on('submit',function($e){ 511 async function form_submit($e,$obj) { 512 if ( 513 typeof $obj.attr('data-validate') === 'undefined' 514 || $obj.attr('data-validate') !== 'true' 515 ) {return;} 516 517 /* 518 stop the submit 519 to resubmit after tests, 520 unbind the submit button from the submit action like: 521 $obj.unbind('submit').submit(); 522 */ 523 $e.preventDefault(); 524 525 var $validated = true; 526 527 // see ../../assets/js/validate.js for validate functions
528 $obj.find(':input').each(function($k,$v){ 529 //console.log('$(this):',$(this)); 530 var $validate_type = ''; 531 if (typeof $(this).attr('data-validate') != 'undefined') {$validate_type = $(this).attr('data-validate');} 532 //console.log('$validate_type:',$validate_type); 533 var $msg = ''; 534 if (typeof $(this).attr('data-validate-msg') != 'undefined') {$msg = $(this).attr('data-validate-msg');} 535 //console.log($msg); 536 537 if ($validate_type == 'blank' && !check_blank($(this),$msg)) {$validated = false;return false;} 538 if ($validate_type == 'blank-no-email' && !check_blank_no_email($(this),$msg)) {$validated = false;return false;} 539 if ($validate_type == 'checkbox' && !check_checkbox($(this),$msg)) {$validated = false;return false;} 540 if ($validate_type == 'email' && !check_email($(this),$msg)) {$validated = false;return false;} 541 if ($validate_type == 'radio' && !check_radio_grp($(this),$msg)) {$validated = false;return false;} 542 if ($validate_type == 'select' && !check_select($(this),$msg)) {$validated = false;return false;} 543 544 // see ../php/shortcodes-form-2.php > [password_confirm_password2] 545 if ($validate_type == 'pcp-add' && $(this).hasClass('password')) { 546 // NOTE: $(this).hasClass('password') skips .password_confirm in the loop 547 var $pw = $(this); 548 var $pwc = $obj.find('.password_confirm');//alert($pwc); 549 if(!check_blank($pw,'Please fill out the "'+$pw.attr('title')+'" field')) {$validated = false;return false;} 550 if(!check_blank($pwc,'Please fill out the "'+$pwc.attr('title')+'" field')) {$validated = false;return false;} 551 if(!check_match_a_b($pw,$pwc,$msg)) {$validated = false;return false;} 552 if(!check_min_max($pw,$pw.attr('data-minlength'),$pw.attr('data-maxlength'))) {$validated = false;return false;} 553 }// /if ($validate_type == 'pcp-add' && $(this).hasClass('password')) { 554 555 });// /$(this).find(':input').each(function($k,$v){ 556 //if (!check_blank($('#form_id #field_id'))) {return false;}// an example of checking a specific field instead of using the above loop 557 558 // recaptcha test MUST be LAST!!!!! 559 // NOTE: $enable_recaptcha var at the top simply stops the redirect to the bot page, it does NOT stop the recaptcha test 560 if ( 561 typeof $obj.attr('data-recaptcha') != 'undefined' 562 && $obj.attr('data-recaptcha') == true 563 && typeof $obj.attr('data-rsk') != 'undefined' 564 && $validated 565 ) { 566 // console.log('$obj.attr(\'id\')',$obj.attr('id')); 567 // console.log('$obj.attr(\'data-recaptcha\'):',$obj.attr('data-recaptcha')); 568 // console.log('$obj.attr(\'data-rsk\'):',$obj.attr('data-rsk')); 569 var $site_key = $obj.attr('data-rsk'); 570 var $rsk = $site_key; 571 572 // $recaptcha_v set at the top of this file 573 // for $jsphp_vars see ../../functions.php 574 // var $rvu = $jsphp_vars['parent_theme_file_uri']+'/assets/php/recaptcha/recaptcha_v3_validate.php';//'/wp-content/themes/'.HP_THEME_FOLDER.'/assets/php/recaptcha/recaptcha_v3_validate.php'; 575 var $rvu = $jsphp_vars['stylesheet_directory_uri']+'/assets/php/recaptcha/recaptcha_v3_validate.php';//'/wp-content/themes/'.HP_THEME_FOLDER.'/assets/php/recaptcha/recaptcha_v3_validate.php'; 576 await grecaptcha.ready(async function() { 577 await grecaptcha.execute($rsk, {action:'shortcode_form'}).then(async function(token) { 578 var $url = $rvu; 579 var $postdata = {'token':token}; 580 var $data = await $.post($url,$postdata,function($data,$status){},"json");// NOTE: MUST set return as json here!!!!! 581 // console.log('$data:',$data); 582 if (isJson($data)) { 583 $data = JSON.parse($data); 584 // console.log('$data:',$data); 585 586 // always show this in console, helps with troubleshooting 587 console.log('v3 $data[\'score\']:',$data['score']); 588 589 // $enable_recaptcha set at the top of this file 590 if ($enable_recaptcha) { 591 if (typeof $data['success'] == 'undefined') { 592 window.location.replace('/bot/?msg=success-undefined'); 593 return false; 594 } 595 if (!$data['success']) { 596 window.location.replace('/bot/?msg=success-false'); 597 return false; 598 } 599 if (typeof $data['score'] == 'undefined') { 600 window.location.replace('/bot/?msg=score-undefined'); 601 return false; 602 } 603 if($data['score'] < $recaptcha_bot_level) { 604 window.location.replace('/bot/?msg=score-small&size='+$data['score']); 605 return false; 606 } 607 608 // pass -- submit the form 609 $obj.unbind('submit').submit(); 610 }// /if ($enable_recaptcha) { 611 }// /if (isJson($data)) { 612 613 });// /grecaptcha.execute( 614 });// /grecaptcha.ready(function() { 615 }// /if (typeof $obj.attr('data-recaptcha') != 'undefined' 616 617 else if ($validated) {$obj.unbind('submit').submit();} 618 }// /function form_submit() { 619 620 /** 621 * pcp() 622 * password confirm password form submit 623 * see ../php/shortcodes-form-2.php > [password_confirm_password2] 624 * 625 * html MUST be like: 626 * <input type="password" class="password" 627 * <input type="password" class="password"_confirm" 628 */ 629 function pcp($e,$obj) { 630 //alert($e);$e.preventDefault();return false; 631 var $pw = $obj.find('input.password'); 632 var $pwc = $obj.find('input.password_confirm'); 633 634 var $msg = ''; 635 if (typeof $pw.attr('data-validate-msg') != 'undefined') {$msg = $pw.attr('data-validate-msg');} 636 //console.log($msg); 637 if(!check_blank($pw,'Please fill out the "'+$pw.attr('title')+'" field')) {$e.preventDefault();return false;} 638 if(!check_blank($pwc,'Please fill out the "'+$pwc.attr('title')+'" field')) {$e.preventDefault();return false;} 639 if(!check_match_a_b($pw,$pwc,$msg)) {$e.preventDefault();return false;} 640 if(!check_min_max($pw,$pw.attr('data-minlength'),$pw.attr('data-maxlength'))) {$e.preventDefault();return false;} 641 }// /function form_submit_pcp() { 642});// /jQuery(document).ready(function($) { 643// /validate on submit ============================================ 644 645// ajax validate ============================================ 646/** 647 * validate_ajax() 648 * see ../php/shortcodes-form-2.php [text2] 649 * 650 * NOTE: blur initially gets hit for all text fields to handle the moving of the label 651 * into the field, see move_form_labels() above 652 */ 653jQuery(document).ready(function($) { 654 $('input').on('blur',function(){ 655 if (typeof $(this).attr('data-validate-ajax') !== 'undefined') { 656 validate_ajax($(this)); 657 } 658 }); 659});// /jQuery(document).ready(function($) { 660function validate_ajax($obj) { 661 jQuery(document).ready(function($) { 662 //var $obj = $(obj);console.log('$obj:',$obj); 663 664 // if empty, stop -- will be hit on page load all the time by move_form_labels() 665 if (typeof $obj.val() == 'undefined' || $obj.val() == '') {return false;} 666 667 // if no string to test with, stop 668 if (typeof $obj.attr('data-validate-ajax') == 'undefined' || $obj.attr('data-validate-ajax') == '') {return false;} 669 670 var $args = {}; 671 phpjs.parse_str($obj.attr('data-validate-ajax'),$args); 672 if (typeof $args['process'] == 'undefined' || $args['process'] == '') {$args['process'] = 'unique_db';} 673 $args['v'] = $obj.val(); 674 $args['ajax_return'] = true; 675 676 var $url = './';// see db.php 677 if (typeof $args['url'] != 'undefined' && $args['url'] != '') {$url = $args['url'];} 678 679 //console.log('$url:',$url); 680 //console.log('$args:',$args); 681 $.post($url,$args).done(function($data) { 682 //console.log('validate_ajax $data:',$data); 683 //console.log('$obj.attr(\'data-validate-ajax-exist\'):',$obj.attr('data-validate-ajax-exist')); 684 /* 685 if a value is returned, it means that the value exists already in the db 686 $exist = check db to see if returned value is to be tested as existing or not existing 687 */ 688 var $exist = JSON.parse($obj.attr('data-validate-ajax-exist').toLowerCase());// cast "true"|"false" to bool true|false 689 if (!$exist && $data.hasOwnProperty('check_v')) { 690 alert('The value you entered "'+$obj.val()+'" is not available. Please try again.'); 691 $obj.val(''); 692 $obj.focus(); 693 } 694 if ($exist && !$data.hasOwnProperty('check_v')) { 695 alert('The value you entered "'+$obj.val()+'" is not on file. Please try again.'); 696 $obj.val(''); 697 $obj.focus(); 698 } 699 },'json'); 700 });// /jQuery(document).ready(function($) { 701}// /function validate_ajax(obj) { 702// /ajax validate ============================================ 703 704// file upload ============================================== 705/** 706 * file uploader 707 * upload both to specific server location or email attachement 708 * drag and drop interface 709 * 710 * see ../php/shortcodes-form-2.php [file2] 711 */ 712jQuery(document).ready(function($) { 713 if (typeof $('.file-uploader-container') != 'undefined') {
714 $('.file-uploader-container').each(function($k,$v){ 715 $obj = $(this); 716 var $id = $obj.attr('data-id');//console.log('$id:',$id); 717 var $data_id = $obj.attr('data-id');//console.log('$data_id:',$data_id); 718 var $imgsrc = $obj.find('img').attr('src');//console.log('$imgsrc:',$imgsrc); 719 var $init_string = $('#'+$data_id+'-file-upload-display-name').html();//console.log('$init_string:',$init_string); 720 721 // show initial image 722 if (!empty($imgsrc)) { 723 $id.show(); 724 }// /if (!empty($imgsrc)) { 725 726 // drop on file input 727 $('#'+$data_id).on('dragover',false).on('drop',function($e){ 728 var $files = $e.originalEvent.dataTransfer.files;//console.log($files); 729 file_upload_set($files,$data_id); 730 }); 731 732 $('#'+$data_id+'-div .file-upload-reset').on('click',function($e){ 733 file_upload_reset($e,$data_id,$init_string,$imgsrc); 734 }); 735 736 $obj.find('.bn_delete').on('click',function($e){ 737 file_upload_delete($e,$data_id,$itempath,$copypath) 738 }); 739 });// /$('.file-uploader-container').each(function($k,$v){ 740 }// /if (typeof $('.file-uploader-container') != 'undefined') { 741});// /jQuery(document).ready(function($) { 742 743/** 744 * file_upload_set() 745 * 746 */ 747function file_upload_set($files,$data_id) { 748 //console.log('$files:',$files); 749 //console.log('$data_id:',$data_id); 750 jQuery(document).ready(function($) { 751 var $name = $files[0]['name'];//console.log($name); 752 $('#'+$data_id+'-file-upload-display-name').show().html($name); 753 //for(var $n = 0; $n < $files.length; $n++) {console.log($n+':'+$files[$n].name);} 754 755 // image upload ===== 756 if ( 757 typeof $files[0]['type'] != 'undefined' 758 && $files[0]['type'].search(/image/i) > -1 759 ) { 760 var reader = new FileReader(); 761 reader.onload = function ($e) { 762 $('#'+$data_id+'-file-upload-img-container').show(); 763 $('#'+$data_id+'-file-upload-img-container img').attr('src',$e.target.result); 764 } 765 //reader.readAsDataURL(e.target.files[0]); 766 reader.readAsDataURL($files[0]); 767 } 768 // /image upload ===== 769 770 $('#'+$data_id+'-div .file-upload-reset').show(); 771 });// /jQuery(document).ready(function($) { 772}// /function file_upload_set() { 773 774/** 775 * file_upload_reset() 776 * 777 */ 778function file_upload_reset($e,$data_id,$init_string,$imgsrc) { 779 jQuery(document).ready(function($) { 780 $e.preventDefault(); 781 $('#'+$data_id+'-file-upload-display-name').html($init_string); 782 $('#'+$data_id).val('');// this is the ONLY value that can be set with js for an input[type="file"] 783 $('#'+$data_id+'-file-upload-img-container img').attr('src',$imgsrc); 784 $('#'+$data_id+'-div .file-upload-reset').hide(); 785 });// /jQuery(document).ready(function($) { 786}// /function file_upload_reset() { 787 788/** 789 * file_upload_delete() 790 * 791 */ 792function file_upload_delete($e,$data_id,$itempath,$copypath) { 793 jQuery(document).ready(function($) { 794 //var $_this = $(this); 795 var $_this = $e.target; 796 $e.preventDefault(); 797 if (confirm('Are you SURE you want to delete this???')) { 798 $imgsrc = ''; 799 $url = './';// see shared.php 800 $postdata = { 801 'process':'delete_collateral', 802 'item':$itempath, 803 'copypath':$copypath, 804 'ajax':true, 805 }; 806 //console.log('$postdata:',$postdata); 807 808 $.post($url,$postdata).done(function($data) { 809 console.log($data); 810 if ( 811 $data.hasOwnProperty('deleted') 812 && $data['deleted'] == true 813 ) { 814 $('#'+$data_id+'-div .file-upload-reset').click(); 815 $_this.hide(); 816 } 817 else { 818 alert('There was a problem with your request.'); 819 } 820 },'json').fail(function(xhr,status,error){ 821 console.log('xhr:',xhr); 822 console.log('status:',status); 823 console.log('error:',error); 824 }); 825 }// /if (confirm 826 });// /jQuery(document).ready(function($) { 827}// /function file_upload_delete() { 828// /file upload ============================================== 829 830// generate password ======================================== 831/** 832 * generate_password() 833 * 834 */ 835jQuery(document).ready(function($) { 836 $('.gen-pswd').on('click',function($e){ 837 $e.preventDefault(); 838 generate_password($e,$(this)); 839 }); 840});// /jQuery(document).ready(function($) { 841function generate_password($e,$obj) { 842 jQuery(document).ready(function($) { 843 var $id = $obj.attr('data-id').replace('.','\\\.');// in case of id like: tablename.colname 844 var $url = './'; 845 var $args = { 846 'process':'ajax_pswd_gen',// in shared.php 847 'length':9, 848 'strength':10, 849 } 850 $.post($url,$args).done(function($data) { 851 //console.log('$data:',$data); 852 //console.log('$id:',$id); 853 if ($data.hasOwnProperty('pswd')) { 854 var $css_hide = { 855 'color':'rgba(0,0,0,0)', 856 'transition':'color 200ms', 857 }; 858 var $css_show = { 859 'color':'rgba(0,0,0,1)', 860 }; 861 862 var $newpswdmsg = '<div><i>Randomly generated password:</i></div><p><strong style="display:none;">'+$data['pswd']+'</strong></p>'; 863 $('#'+$id+'-gen-result').html($newpswdmsg); 864 $('#'+$id+'').val($data['pswd']).css($css_hide); 865 $('#'+$id+'_confirm').val($data['pswd']).css($css_hide); 866 $('#'+$id+'').focus(); 867 $('#'+$id+'_confirm').focus(); 868 $('#'+$id+'-gen-result strong').fadeIn('fast',function(){ 869 $('#'+$id+'').css($css_show); 870 $('#'+$id+'_confirm').css($css_show); 871 }); 872 } 873 },'json');// /$.post( 874 });// /jQuery(document).ready(function($) { 875}// /function generate_password() { 876 877// optimize images ======================================== 878/** 879 * optimage() 880 * 881 */ 882document.addEventListener('DOMContentLoaded', (event) => { 883 //console.log('DOM fully loaded and parsed'); 884 window.onresize = optimage; 885 optimage(); 886}); 887 888// optimize images ======================================== 889/** 890 * optimage() 891 * 892 */ 893document.addEventListener('DOMContentLoaded', (event) => { 894 //console.log('DOM fully loaded and parsed'); 895 window.onresize = optimage; 896 optimage(); 897}); 898 899function optimage() { 900 var optimages = document.querySelectorAll('.optimage img')
901 optimages.forEach(function(optimg) { 902 if (optimg.hasAttribute('srcset')) { 903 var srcset; 904 if (optimg.hasAttribute('srcset2')) { 905 srcset = optimg.getAttribute('srcset2'); 906 } else { 907 srcset = optimg.getAttribute('srcset'); 908 optimg.setAttribute('srcset2', srcset); 909 optimg.srcset = ""; 910 } 911 var sources = srcset.split(', ').map(e => e.split(' ')); 912 sources.forEach(function (source, index) { 913 sources[index][1] = Number(sources[index][1].substring(0, sources[index][1].length - 1)) 914 }) 915 sources.sort(function (a, b) { 916 return b[1] - a[1] 917 }); 918 var containerw = optimg.closest('.optimage').offsetWidth; 919 var containerh = optimg.closest('.optimage').offsetHeight; 920 var optimgwidth = optimg.getAttribute('width'); 921 var optimgheight = optimg.getAttribute('height'); 922 var optimgratio = optimgheight / optimgwidth; 923 var zoomlevel = 0 924 925 while (sources[zoomlevel][1] > containerw && optimgratio * sources[zoomlevel][1] > containerh) { 926 //console.log(zoomlevel, containerw, sources[zoomlevel][1]); 927 if (zoomlevel === sources.length - 1) break; 928 if (containerw < sources[zoomlevel + 1][1] && containerh < sources[zoomlevel + 1][1] * optimgratio) { 929 zoomlevel = zoomlevel + 1; 930 } else { 931 break 932 } 933 } 934 //console.log(containerw + ": " + sources[zoomlevel]); 935 zoomlevel = Math.max(0, Math.min(zoomlevel, sources.length - 1)) 936 if (optimg.src !== sources[zoomlevel][0]) optimg.src = sources[zoomlevel][0]; 937 } 938 }) 939} 940 941 942 943// /generate password ======================================== 944 945/** 946 * password_chars_showhide() 947 * show/hide the characters in a password input 948 */ 949jQuery(document).ready(function($) { 950 $(document).on('click','.show-pswd',function($e){ 951 $e.preventDefault(); 952 password_chars_showhide($(this)); 953 }); 954});// /jQuery(document).ready(function($) { 955function password_chars_showhide($obj) { 956 $obj.toggleClass('active'); 957 var $pswd_field = $obj.closest('.pswd-container').find('.password'); 958 if ($pswd_field.attr('type') === 'password') { 959 $pswd_field.attr('type','text'); 960 } 961 else { 962 $pswd_field.attr('type','password'); 963 } 964 $pswd_field.focus(); 965} 966 967// prevent form submission double-clicking =============================== 968/** 969 * prevent_double_click() 970 * stop accidental or purposeful multiple clicks on submit buttons and other form submission types 971 * 972 * NOTE: DO NOT DISABLE THE SUBMIT BUTTON, 973 * will break submissions that require the name of the submit button!!!!! 974 * Instead, set a data-disabled attr. 975 */ 976jQuery(document).ready(function($) { 977 $("form").each(function($k,$v) { 978 $_this = $(this); 979 prevent_double_click($k,$v,$_this); 980 });// /$("form").each(function($k,$v) { 981});// /jQuery(document).ready(function($) { 982function prevent_double_click($k,$v,$_this) { 983 jQuery(document).ready(function($) { 984 985 // enter key 986 $_this.keypress(function($e){ 987 if($e.which == 13) { 988 // sets the data-disabled attr on the form itself. 989 if ($_this.attr('data-disabled')) { 990 $e.preventDefault(); 991 return false; 992 } 993 $_this.attr('data-disabled','disabled'); 994 setTimeout(function(){$_this.removeAttr('data-disabled');},1000); 995 console.log('form submitted'); 996 }// /if($e.which == 13) { 997 });// /$_this.keypress(function($e){ 998 999 // submit buttons 1000 $_this.submit(function($e){ 1001 // assume regular input submit button 1002 var $submit = $_this.find('input[type="submit"]'); 1003 1004 // if running from an html 5 button instead: 1005 if ($submit.length === 0) {$submit = $_this.find('button[type="submit"]');} 1006 1007 if ($submit.attr('data-disabled')) { 1008 $e.preventDefault(); 1009 return false; 1010 } 1011 $submit.attr('data-disabled','disabled'); 1012 setTimeout(function(){$submit.removeAttr('data-disabled');},1000); 1013 1014 console.log('form submitted'); 1015 });// /$_this.submit(function($e){ 1016 });// /jQuery(document).ready(function($) { 1017}// /function prevent_double_click() { 1018// /prevent form submission double-clicking =============================== 1019 1020// /FORMS =================================================================== 1021 1022 1023// WORDPRESS additions/overwrites ========================================== 1024// NOTE: these additions are a moving target, so try not to rely on them 1025 1026/** 1027 * hide_featured_img() 1028 * if an image/cover is in the page with a class of "featured" remove any featured image that may be set 1029 * either manually or via shortcode [featured_image] 1030 * mainly useful for [featured_image use_default_img="true"], see shortcodes php for settings 1031 */ 1032hide_featured_img(); 1033function hide_featured_img() { 1034 jQuery(document).ready(function($) { 1035 if ( 1036 $('.wp-block-cover.featured').length 1037 || $('.wp-block-image.featured').length 1038 ) { 1039 $('.wp-block-post-featured-image').hide(); 1040 } 1041 });// /jQuery(document).ready(function($) { 1042}// /function hide_featured_img() { 1043 1044/** 1045 * remove empty p tags 1046 */ 1047jQuery(document).ready(function($) { 1048 $('p:empty').remove(); 1049});// /jQuery(document).ready(function($) { 1050 1051/** 1052* wrappers_inner() 1053* add inner div wrappers to select elements 1054*/ 1055jQuery(document).ready(function($) { 1056 wrappers_inner(); 1057});// /jQuery(document).ready(function($) { 1058function wrappers_inner() { 1059 jQuery(document).ready(function($) { 1060 // $('.wp-block-column').wrapInner('<div class="wp-block-column-inner"></div>'); 1061 });// /jQuery(document).ready(function($) { 1062}// /function wrappers_inner() { 1063 1064/** 1065* wrappers_outer() 1066* add outer div wrappers to select elements 1067* 1068*/ 1069jQuery(document).ready(function($) { 1070 wrappers_outer(); 1071});// /jQuery(document).ready(function($) { 1072function wrappers_outer() { 1073 jQuery(document).ready(function($) { 1074 });// /jQuery(document).ready(function($) { 1075}// /function wrappers_outer() { 1076// /WORDPRESS additions/overwrites ==========================================
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.