1 2_execute_1 = false; 3_execute_2 = false; 4 5var is_Mobile = false; 6var is_Tablet = false; 7var is_Desktop = false; 8 9var preload_LCP_image_has_run = false; 10 11print_debug(window.pageYOffset); 12 13//Check if Webp is supported 14 15var isWebPSupported = false; 16 17if(isWebPSupported == false){ 18 mybrowserversion = getBrowserVersion(); 19 mybrowser = mybrowserversion.match(/[a-z]+/i); 20 myversion = mybrowserversion.match(/[\d]+/); 21 if(mybrowser == "Chrome"){ 22 if(myversion[0] <=31){ 23 isWebPSupported = false; 24 } 25 else{ 26 isWebPSupported = true; 27 } 28 } 29 else if (mybrowser == "Safari"){ 30 if(myversion[0] <=15){ 31 isWebPSupported = false; 32 } 33 else{ 34 isWebPSupported = true; 35 } 36 } 37 else if(mybrowser == "Firefox" ){ 38 if(myversion[0] <=64){ 39 isWebPSupported = false; 40 } 41 else{ 42 isWebPSupported = true; 43 } 44 } 45 else if(mybrowser == "Edge" ){ 46 if(myversion[0] <=17){ 47 isWebPSupported = false; 48 } 49 else{ 50 isWebPSupported = true; 51 } 52 } 53 else{ 54 isWebPSupported = support_format_webp(); 55 } 56} 57 58function support_format_webp() 59{ 60 var elem = document.createElement('canvas'); 61 62 if (!!(elem.getContext && elem.getContext('2d'))) 63 { 64 // was able or not to get WebP representation 65 return true; 66 return elem.toDataURL('image/webp').indexOf('data:image/webp') == 0; 67 68 } 69 else 70 { 71 // very old browser like IE 8, canvas not supported 72 return false; 73 } 74} 75 76function getBrowserVersion(){ 77 var ua= navigator.userAgent; 78 var tem; 79 var M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; 80 if(/trident/i.test(M[1])){ 81 tem= /\brv[ :]+(\d+)/g.exec(ua) || []; 82 return 'IE '+(tem[1] || ''); 83 } 84 if(M[1]=== 'Chrome'){ 85 tem= ua.match(/\b(OPR|Edge)\/(\d+)/); 86 if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera'); 87 } 88 M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; 89 if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]); 90 return M.join(' '); 91} 92 93 94 95// launch preload image LCP 96var my_i=0; 97if(typeof interval != "number" ){ 98 const interval = setInterval(function() { 99 // method to be executed; 100 console.log(my_i); 101 //console.log(my_i >= 50); 102 my_i=my_i+1; 103 if( typeof preload_LCP_image == "function" && document.getElementById("image_LCP") != null){ 104 preload_LCP_image(); 105 } 106 if (my_i >= 20 || preload_LCP_image_has_run == true){ 107 clearInterval(interval); 108 } 109 110 }, 100); 111} 112 113if(typeof interval_jquery != "number" ){ 114 const interval_jquery = setInterval(function() { 115 if(typeof jQuery == "function" && preload_LCP_image_has_run == true){ 116 clearInterval(interval_jquery); 117 //PHONE 118 if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){ 119 print_debug("is_phone_START"); 120 is_Mobile = true; 121 is_Tablet = true; 122 123 if ( _execute_1 == false ){ 124 _execute_1 = js_primary();
125 _execute_2 = js_secondary(); 126 } 127 128 129 } 130 //DESKTOP 131 else { 132 print_debug("is_desktop_START"); 133 is_Desktop = true; 134 135 if ( _execute_1 == false ){ 136 _execute_1 = js_primary(); 137 _execute_2 = js_secondary(); 138 } 139 140 141 } 142 } 143 144 }, 100); 145} 146 147 148 149 150 151 152 153 154 if(typeof jQuery == "function"){ 155window.onscroll = function() { 156//jQuery("body").scroll(function(){ 157//window.ontouchstart = function() { 158 print_debug("onscroll_START"); 159 print_debug(window.pageYOffset); 160 if ( _execute_1 == false ){ 161 _execute_1 = js_primary(); 162 } 163 164 js_continuos(); 165 166 if ( _execute_2 == false ) { 167 if ( _execute_1 == false ){ 168 _execute_1 = js_primary(); 169 } 170 _execute_2 = js_secondary(); 171 172 } 173 } 174//}); 175 } 176 177if(typeof jQuery == "function"){ 178jQuery(".button_prev ,.button_next").on('click', function() { 179 180 print_debug(".button_prev ,.button_next_START"); 181 if ( _execute_1 == false ){ 182 _execute_1 = js_primary();
183 } 184 185 js_continuos(); 186 187 if ( _execute_2 == false ) { 188 if ( _execute_1 == false ){ 189 _execute_1 = js_primary(); 190 } 191 _execute_2 = js_secondary(); 192 193 } 194 195}); 196} 197 198/////////////////////////////////////////////////////////////////////////////////////// 199 200function preload_LCP_image (){ 201 if(preload_LCP_image_has_run == false){ 202 print_debug("preload_LCP_image_START"); 203 preload_LCP_image_has_run = true; 204 img_post = document.getElementById("image_LCP"); 205 if(img_post.getAttribute("srcset") == null && img_post.getAttribute("ta-srcset") != null){ 206 207 img_post.setAttribute("srcset", replaceToWebP( img_post.getAttribute("ta-srcset"))); 208 img_post.setAttribute("sizes", "(max-width:500px) 301px, 700px"); 209 //img_post.setAttribute("sizes", "(max-width:500px) 700px, 700px"); 210 } 211 } 212} 213 214function add_onscroll_event(){ 215 print_debug("add_onscroll_event_START"); 216 217 if(typeof jQuery == "function"){ 218//window.onscroll = function() { 219jQuery("body").scroll(function(){ 220//window.ontouchstart = function() { 221 print_debug("onscroll_START"); 222 print_debug(window.pageYOffset); 223 if ( _execute_1 == false ){ 224 _execute_1 = js_primary();
225 } 226 227 js_continuos(); 228 229 if ( _execute_2 == false ) { 230 if ( _execute_1 == false ){ 231 _execute_1 = js_primary(); 232 } 233 _execute_2 = js_secondary(); 234 235 } 236 237}); 238 } 239 240} 241 242function js_primary(){ 243 print_debug("js_primary_START"); 244 245 _execute_1 = true; 246 247 if(typeof jQuery == "function"){ 248 load_ta_featured(function(){ 249 250 load_ta_images(); 251 252 }); 253 254 255 load_ta_async_content(); 256 257 return _execute_1; 258 } 259} 260 261function js_secondary(){ 262 print_debug("js_secondary_START"); 263 264 _execute_2 = true; 265 266 switch_ta_scripts(); 267 load_high_res_images(); 268 load_ta_iframes(); 269 270 return _execute_2; 271} 272 273function js_continuos(){ 274 275 load_ta_images(); 276 load_high_res_images(); 277 load_ta_iframes(); 278 279} 280 281 282/////////////////////////////////////////////////////////////////////////////////////// 283 284function replaceToWebP(srctoReplace) { 285 print_debug("replaceToWebP_START"); 286 287 if (isWebPSupported && srctoReplace != null) { 288 289 var _parts = srctoReplace.split(","); 290 var _webpUrls = _parts.map(function(part) { 291 292 var _url = part.trim().split(" "); 293 var _pathname = _url[0]; 294 var _extension = _pathname.split(/[#?]/)[0].split('.').pop().trim(); 295 296 if (_extension.endsWith(".webp")) { 297 298 return part.trim(); 299 300 } else { 301 302 var supportedExtensions = ["jpg", "jpeg"]; 303 304 if (supportedExtensions.indexOf(_extension) !== -1) { 305 306 var _webpUrl = _pathname + '.webp'; 307 308 return part.replace(_pathname, _webpUrl); 309 310 } else { 311 312 return part.trim(); 313 314 } 315 316 } 317 318 }); 319 320 var _result = _webpUrls.join(", "); 321 322 return _result; 323 324 } 325 326 return srctoReplace; 327 328} 329 330 331function load_ta_async_content(){ 332 print_debug("load_ta_async_content_START"); 333 334 335 jQuery(function(){ 336 337 jQuery('[data-ta-iframe]').each(function() { 338 339 var _this = jQuery(this); 340 341 342 343 if(_this[0].hasAttribute("data-ta-iframe_loaded") ){ 344 345 } 346 else{ 347 348 _path = _this.attr("data-ta-iframe"); 349 350 if ( _path != undefined ) { 351 352 _this[0].setAttribute("data-ta-iframe_loaded","true"); 353 354 jQuery.ajax({cache:true,url: _path, success: function(result){ 355 356 // There is only one part, we put the content directly inside ta_async tag 357 _this.html(result); 358 359 }}); 360 361 362 } 363 } 364 365 }); 366 367 jQuery('ta_async_content').each(function() { 368 369 var _this = jQuery(this); 370 371 372 373 374 375 376 if ( is_Mobile && _this.hasClass("disable-mobile") ) { 377 378 return false; 379 380 } 381 382 if ( is_Tablet && _this.hasClass("disable-tablet") ) { 383 384 return false; 385 386 } 387 388 if ( is_Desktop && _this.hasClass("disable-desktop") ) { 389 390 return false; 391 392 } 393 394 if(_this[0].hasAttribute("ta_async_content_loaded") ){ 395 396 } 397 else{ 398 _path = _this.attr("path"); 399 400 401 if ( _path != undefined ) { 402 _this[0].setAttribute("ta_async_content_loaded","true"); 403 jQuery.ajax({cache:true,url: _path, success: function(result){ 404 405 // Split the result in parts 406 var _resultArr = result.split("||TA_CACHE_SPLIT||"); 407 408 // If the are more than one part we need to loop through the tags 409 // <ta_async_partial> and replace it with the part 410 if ( _resultArr.length > 1 ) { 411 412 var _partials = _this.find("ta_async_partial"); 413 414 _partials.each(function( _index, _val ){ 415 416 $(this).html( _resultArr[_index] ); 417 418 }); 419 420 } else { 421 422 // There is only one part, we put the content directly inside ta_async tag 423 _this.html(result); 424 425 } 426 427 }}); 428 429 } 430 } 431 432 }); 433 434 });
435 436} 437 438function load_ta_featured( _callback = "" ) { 439 print_debug("load_ta_featured_START"); 440 jQuery(function(){ 441 442 jQuery('img:not([sizes_adapted])').each(function(){ 443 444 if (typeof this.getAttribute("ta-srcset") != undefined){ 445 446 imageLoaded( this ); 447 448 /* 449 myAttribute=this.getAttribute("ta-srcset"); 450 451 if(typeof myAttribute == "string"){ 452 453 this.setAttribute("srcset", replaceToWebP(myAttribute)); 454 455 } 456 */ 457 458 } 459 460 if ( typeof _callback == "function" ){ 461 462 _callback.apply(this); 463 464 } 465 466 }); 467 468 }); 469 470} 471 472function load_ta_images(){ 473 print_debug("load_ta_images_START"); 474 all_images=jQuery('img[ta-src],img[ta-srcset]'); 475 476 for(i=0;i<all_images.length;i++){ 477 478 if ( elementInViewport( all_images[i] ) ) { 479 480 myAttribute=all_images[i].getAttribute("ta-src"); 481 myAttribute = replaceToWebP(myAttribute); 482 483 if(typeof myAttribute == "string"){ 484 485 all_images[i].setAttribute("src",myAttribute); 486 all_images[i].removeAttribute("ta-src"); 487 488 } 489 490 myAttribute=all_images[i].getAttribute("ta-srcset"); 491 492 if(typeof myAttribute == "string"){ 493 494 all_images[i].setAttribute("srcset",replaceToWebP(myAttribute)); 495 all_images[i].removeAttribute("ta-srcset"); 496 497 } 498 499 } 500 501 } 502 503} 504 505function load_ta_iframes(){ 506 print_debug("load_ta_iframes_START"); 507 jQuery(document).ready(function() { 508 509 jQuery('iframe').each(function() { 510 511 if (typeof this.getAttribute("src") !== "string"){ 512 513 if ( elementInViewport( this ) ) { 514 515 myAttribute=this.getAttribute("ta-src"); 516 517 if(typeof myAttribute == "string"){ 518 519 this.setAttribute("src",myAttribute); 520 521 } 522 523 myAttribute=this.getAttribute("ta-srcset"); 524 525 if(typeof myAttribute == "string"){ 526 527 this.setAttribute("srcset",myAttribute); 528 529 } 530 531 } 532 533 } 534 535 }); 536 537 }) ; 538 539 540} 541 542function load_high_res_images(){ 543 print_debug("load_high_res_images_START"); 544 545 let all_images=jQuery('img:not([sizes_adapted])'); 546 547 if(all_images[0] !== "undefiend"){ 548 549 for(let i=0;i<all_images.length;i++){ 550 551 if ( elementInViewport( all_images[i] ) && typeof all_images !== "undefiend") { 552 553 imageLoaded( all_images[i] ); 554 555 } 556 557 } 558 559 } 560 561} 562 563function switch_ta_scripts(){ 564 print_debug("switch_ta_scripts_START"); 565 jQuery("link").each(function(){ 566 567 var attr = jQuery(this).attr('ta-script-href'); 568 569 if (typeof attr !== 'undefined' && attr !== false) { 570 571 jQuery(this).attr("href", attr); 572 573 } 574 575 }); 576 577 jQuery("script").each(function(){ 578 579 var attr = jQuery(this).attr('ta-script-src'); 580 var type = jQuery(this).attr('ta-script-type'); 581 582 if (typeof attr !== 'undefined' && attr !== false) { 583 584 jQuery(this).attr("src", attr); 585 586 } 587 588 if (typeof type !== 'undefined' && type !== false) { 589 590 var _script = jQuery("<script>").text( jQuery(this).text() ).appendTo("body"); 591 592 } 593 594 }); 595 596 jQuery("iframe").each(function(){ 597 598 var attr = jQuery(this).attr('ta-script-src'); 599 600 if (typeof attr !== 'undefined' && attr !== false) { 601 602 jQuery(this).attr("src", attr); 603 604 } 605 606 }); 607 608 609} 610 611function imageLoaded( img_post ) { 612 print_debug("imageLoaded_START"); 613 // Run onload code. 614 var sizes_adapted_value = "ERROR sizes"; 615 //console.log("Attribute"); 616 //console.log(img_post.getAttribute("sizes_adapted")); 617 if(img_post.getAttribute("sizes_adapted") == null){ 618 619 if(typeof debug_image_resolution=='undefined' || debug_image_resolution!=true){ 620 621 let sizes = []; 622 623 if(img_post.getAttribute("srcset") == null && img_post.getAttribute("ta-srcset") != null){ 624 625 img_post.setAttribute("srcset", replaceToWebP( img_post.getAttribute("ta-srcset"))); 626 627 } 628 //img_post.setAttribute("srcset",replaceToWebP( img_post.getAttribute("srcset"))); 629 630 if(img_post.getAttribute("srcset") != null && img_post.getAttribute("srcset").match(/[\d.]+(?=w)/g) != null){ 631 632 633 634 img_post.getAttribute("srcset").match(/[\d.]+(?=w)/g).forEach(str => { 635 636 sizes.push(Number(str)); 637 638 }); 639 640 for(let i=0;i<sizes.length;i++){ 641 642 if(isNaN(sizes[i])){ 643 644 sizes[i] = 0; 645 646 } 647 648 } 649 650 sizes.sort(function(a, b) { 651 652 return a - b; 653 654 }); 655 656 let acceptable_scale_factor=1; 657 let width = jQuery(img_post).width() * acceptable_scale_factor; 658 659 if (jQuery(img_post).parents('.TA_gallery_element').length > 0 && jQuery(img_post).parents('.carousel').length > 0){ 660 661 width = -1; 662 663 } 664 665 if(width == 0){ 666 667 sizes_adapted_value = "ERROR sizes: Width=0"; 668 669 } else { 670 671 672 if(width == -1 && !jQuery(img_post).closest().is(':first-child')){ 673 674 sizes_of_first_child = jQuery(img_post).parents('.carousel').first().attr('sizes'); 675 img_post.setAttribute("sizes", sizes_of_first_child); 676 sizes_adapted_value = "true"; 677 678 } else { 679 680 current_val=-1; 681 682 for(i=0;i<sizes.length;i++){ 683 684 if(sizes[i] > width){ 685 686 current_val=i; 687 break; 688 689 } else { 690 691 if(i == sizes.length-1){ 692 693 current_val = i; 694 console.log("max image size reached"); 695 696 } else { 697 //donothing 698 } 699 700 } 701 702 } 703 //console.log("sizes[current_val]"); 704 //console.log(sizes[current_val]); 705 706 if(current_val != -1){ 707 //console.log(isWebPSupported); 708 //img_post.setAttribute("sizes", sizes[current_val] + "px"); // window.devicePixelRatio is 3 on phone 709 if(window.devicePixelRatio > 1){ 710 sizes_corrector = window.devicePixelRatio / 2; 711 } 712 else{ 713 sizes_corrector = 1; 714 } 715 716 size_to_right=parseInt(width / sizes_corrector); 717 if (size_to_right < 300){ 718 if(is_Mobile){ 719 size_to_right=300 / (window.devicePixelRatio / 2); 720 } 721 else{ 722 size_to_right=300; 723 } 724 } 725 726 Real_ratio = img_post.height / img_post.width ; 727 Image_ratio = parseInt(img_post.style.maxHeight) / parseInt(img_post.style.maxWidth); 728 if((Real_ratio - Image_ratio) >= 0.3){ 729 size_to_right = parseInt(size_to_right * Real_ratio / Image_ratio); 730 } 731 732 733 //console.log(size_to_right); 734 img_post.setAttribute("sizes", parseInt(size_to_right) + "px"); 735 736 sizes_adapted_value = "true"; 737 738 } else { 739 740 sizes_adapted_value = "ERROR sizes: current_val = -1"; 741 742 } 743 744 } 745 746 } 747 748 } else { 749 750 sizes_adapted_value = "ERROR sizes: srcsetNotDefined"; 751 752 } 753 } else { 754 755 sizes_adapted_value = "ERROR sizes: undefinedB"; 756 757 } 758 759 img_post.setAttribute("sizes_adapted", sizes_adapted_value); 760 761 } 762 /* 763 else if (img_post == jQuery(".article_0 .feature_image img")[0]){ //LCP Load preloaded image 764 if(img_post.getAttribute("srcset") == null && img_post.getAttribute("ta-srcset") != null){ 765 766 img_post.setAttribute("srcset", replaceToWebP( img_post.getAttribute("ta-srcset"))); 767 img_post.setAttribute("sizes", "(max-width:500px) 60vw, 40vw"); 768 } 769 770 771 } 772 */ 773} 774 775 776 777function elementInViewport(myElement) { 778 print_debug("elementInViewport_START"); 779 return true; 780 var bounding = myElement.getBoundingClientRect(); 781 var myElementHeight = myElement.offsetHeight; 782 var myElementWidth = myElement.offsetWidth; 783 784 if (bounding.top >= -myElementHeight 785 && bounding.left >= -myElementWidth 786 && bounding.right <= (window.innerWidth || document.documentElement.clientWidth) + myElementWidth 787 && bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) + myElementHeight) { 788 789 return true; 790 791 } else { 792 793 return false; 794 795 } 796 797} 798 799 800 801 802function print_debug(mystring){ 803 if(false){ 804 console.log(mystring); 805} 806}
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.