1var ILTranslation = function (params) { 2 this.params = params; 3}; 4(function ($, ILTranslation) { 5 (ILTranslation.prototype = { 6 apiServer: "", 7 endPoint: "/bos/translation/ILTranslationRest.php", 8 apiEndPoint: "", 9 failsafe: 10000, 10 debugTranslate: false, 11 excludeName: { 12 IMG: 1, 13 SCRIPT: 1, 14 STYLE: 1, 15 HEAD: 1, 16 IFRAME: 1, 17 OBJECT: 1, 18 path: 1, 19 g: 1, 20 svg: 1, 21 ubdiv: 1, 22 }, 23 preElements: { 24 A: 1, 25 SPAN: 1, 26 B: 1, 27 I: 1, 28 STRONG: 1, 29 }, 30 jqValidate: { 31 "This field is required.": 1, 32 }, 33 //specialChars: {"#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "_", "`", "{", "|", "}", "~"}, 34 specialChars: { 35 "#": 1, 36 $: 1, 37 "%": 1, 38 "&": 1, 39 "'": 1, 40 "(": 1, 41 ")": 1, 42 "*": 1, 43 "+": 1, 44 ",": 1, 45 "-": 1, 46 ".": 1, 47 "/": 1, 48 ":": 1, 49 ";": 1, 50 "<": 1, 51 "=": 1, 52 ">": 1, 53 "?": 1, 54 "@": 1, 55 "[": 1, 56 "\\": 1, 57 "]": 1, 58 "^": 1, 59 _: 1, 60 "`": 1, 61 "{": 1, 62 "|": 1, 63 "}": 1, 64 "~": 1, 65 }, 66 slidersData: [ 67 { 68 sliderClass: "rev_slider", 69 }, 70 ], 71 noTranslateClass: "ILTNotranslate", 72 noTranslateClassD: "ILTNotranslateD", 73 excludeClasses: { 74 globalMapCheckAvail: 1, 75 "amcharts-balloon-div": 1, 76 "amcharts-chart-div": 1, 77 "autocomplete-suggestions": 1, 78 "autocomplete-suggestion": 1, 79 "countText": 1 80 }, 81 autoTranslate: "", 82 backElms: {}, 83 validIFrames: [], 84 loadedIframes: [], 85 validImages: [], 86 replaceImages: [], 87 validOthers: [], 88 validBtns: [], 89 validBeacon: [], 90 otherElms: [], 91 validSliders: [], 92 bearerToken: "", 93 translateCookie: "", 94 widgetCookie: "", 95 translateTo: false, 96 translateFrom: "en", 97 selectorBaseTxt: "", 98 selectorBaseTxtWidget: "Translate", 99 selectorShort: { 100 en: "English", 101 es: "Español", 102 }, 103 selectorShortWidget: { 104 en: "[EN]", 105 es: "[ES]", 106 "zh-CN": "[ZH-CN]", 107 "zh-TW": "[ZH-TW]", 108 tl: "[TL]", 109 }, 110 toTranslate: [], //store the original text ordered by DOM order - id is added as data --> stackid = toTranslate.length value 111 nodesToTranslate: [], //store nodes text by node assigned id (data-stackid) 112 translateLimit: 30000, // API Limit for each call = 30720, 113 translateNodes: [], 114 translatedElms: {}, 115 translatedIframes: [], 116 translatedImages: {}, 117 translatedOthers: {}, 118 translatedOthersBtns: {}, 119 loadFrom: "", 120 currentWidget: "", 121 callbackScript: false, 122 labelIndex: 0, 123 stackId: 0, 124 lastIndex: 0, 125 lngCookie: "", 126 observer: [], 127 observedElms: [], 128 observerIdx: 0, 129 nodesToObserve: [], 130 observerTurnedOn: false, 131 observerConfig: { 132 // Options for the observer (which mutations to observe) 133 attributes: false, 134 characterData: true, 135 childList: true, 136 subtree: true 137 }, 138 translateRunning: false, 139 iframeLoaders: [], 140 init: function () { 141 console.log( 142 "%c ILTranslation init ", 143 "background: #0A0A0A; color: #45AAEB; padding-left:5px; padding: 1px; border-left: 3px solid #45AAEB;", 144 ); 145 //---> max translate ---> 30720 146 var pf = this; 147 if ( 148 typeof pf.params.loadFrom != "undefined" && 149 pf.params.loadFrom != "" 150 ) { 151 pf.loadFrom = pf.params.loadFrom; 152 } 153 if ( 154 typeof pf.params.parentToken != "undefined" && 155 pf.params.parentToken != "" 156 ) { 157 pf.parentToken = pf.params.parentToken; 158 } 159 if (pf.loadFrom != "" && pf.parentToken != "") { 160 pf.bearerToken = pf.parentToken; 161 } 162 //apiEndPoint 163 if (window.location.href.indexOf("sb8") > -1) { 164 pf.apiServer = "https://sb8.imaginationlibrary.com/"; 165 } 166 else if (window.location.href.indexOf("locsb") > -1) {
167 pf.apiServer = "https://locsb.imaginationlibrary.com/"; 168 } 169 else if (window.location.href.indexOf("stg") > -1) { 170 pf.apiServer = "https://stg.imaginationlibrary.com/"; 171 } else { 172 pf.apiServer = "https://imaginationlibrary.com/"; 173 } 174 175 pf.apiEndPoint = 176 pf.apiServer + "bos/translation/serverTranslate.php"; 177 $(document).ready(function () { 178 //debug mode 179 //inline code: $('body').append("<input type='hidden' id='debugMode' value='true'>"); 180 var debugMode = 181 $("#debugMode") !== undefined && 182 $("#debugMode").val() == "true" 183 ? true 184 : false; 185 pf.debugTranslate = false; // debugMode true or false; 186 if (pf.debugTranslate == true) { 187 console.log( 188 "%c ILTranslation DEBUG MODE ON", 189 "color:#D27575; background-color:#4B0F0F; padding:8px; font-weight:bold; border-left:10px solid #f00; margin-bottom:8px;" 190 ); 191 } 192 if (pf.observer != false) { 193 pf.observer.disconnect(); 194 } 195 if (pf.loadFrom == "bosWidgets") { 196 try { 197 pf.iltBosWidgets(); 198 return; 199 } catch (e) { 200 console.log( 201 "%c -- ILTranslation BOS Widgets ERR 0x001", 202 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 203 e 204 ); 205 } 206 } 207 var windowSive = $(window).width(); 208 if ( 209 /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( 210 navigator.userAgent 211 ) || 212 windowSive < 985 213 ) { 214 $("#selectLngMob") 215 .off() 216 .on("change", function () { 217 if ( 218 $(this).val() != "" && 219 $(this).val() != pf.translateFrom 220 ) { 221 pf.translateTo = $(this).val(); 222 $("#mob_iltSelectedLng").val(pf.translateTo); 223 var shortLngVal = 224 $("#selectLngMob option:selected").val() != 225 "" 226 ? $( 227 "#selectLngMob option:selected" 228 ).val() 229 : pf.translateFrom; 230 $(this).prop("selectedIndex", 0); 231 $("#selectLngMob option:selected").text( 232 pf.selectorBaseTxt + 233 " " + 234 pf.selectorShort[shortLngVal] 235 ); 236 $("#selectLngMob option:selected").text( 237 pf.selectorBaseTxt + 238 " " + 239 pf.selectorShort[shortLngVal] 240 ); 241 pf.getTranslateCookie( 242 "setCookie", 243 pf.translateTo, 244 false 245 ); 246 pf.showLoader(); 247 pf.getTranslation(document.body); 248 pf.translateImages(); 249 setTimeout(function () { 250 pf.getIframes(); 251 pf.translateOthers(); 252 }, 6000); 253 pf.getHelpScout(); 254 pf.translateRunning = true; 255 } else { 256 pf.getTranslateCookie("unsetCookie", "", false); 257 pf.translateRunning = false;
258 pf.backToOriginal(); 259 var shortLngVal = 260 $("#selectLngMob option:selected").val() != 261 "" 262 ? $( 263 "#selectLngMob option:selected" 264 ).val() 265 : pf.translateFrom; 266 $(this).prop("selectedIndex", 0); 267 $("#selectLngMob option:selected").text( 268 pf.selectorBaseTxt + 269 " " + 270 pf.selectorShort[shortLngVal] 271 ); 272 pf.removeLoader(); 273 } 274 }); 275 } 276 $("#selectLng") 277 .off() 278 .on("change", function () { 279 if ( 280 $(this).val() != "" && 281 $(this).val() != pf.translateFrom 282 ) { 283 pf.translateTo = $(this).val(); 284 $("#iltSelectedLng").val(pf.translateTo); 285 var shortLngVal = 286 $("#selectLng option:selected").val() != "" 287 ? $("#selectLng option:selected").val() 288 : pf.translateFrom; 289 $(this).prop("selectedIndex", 0); 290 $("#selectLng option:selected").text( 291 pf.selectorBaseTxt + 292 " " + 293 pf.selectorShort[shortLngVal] 294 ); 295 $( 296 '#selectLng option[value="' + 297 pf.translateTo + 298 '"]' 299 ).prop("disabled", true); 300 301 pf.getTranslateCookie( 302 "setCookie", 303 pf.translateTo, 304 false 305 ); 306 pf.showLoader(); 307 pf.getTranslation(document.body); 308 pf.translateImages(); 309 setTimeout(function () { 310 pf.getIframes(); 311 }, 5000); 312 pf.translateOthers(); 313 pf.getHelpScout(); 314 pf.translateRunning = true; 315 } else { 316 pf.getTranslateCookie("unsetCookie", "", false); 317 $( 318 '#selectLng option[value="' + 319 pf.translateTo + 320 '"]' 321 ).prop("disabled", false); 322 pf.translateRunning = false; 323 pf.backToOriginal(); 324 var shortLngVal = 325 $("#selectLng option:selected").val() != "" 326 ? $("#selectLng option:selected").val() 327 : pf.translateFrom; 328 $(this).prop("selectedIndex", 0); 329 $("#selectLng option:selected").text( 330 pf.selectorBaseTxt + 331 " " + 332 pf.selectorShort[shortLngVal] 333 ); 334 pf.removeLoader(); 335 } 336 $(this).blur(); 337 }); 338 var checkTranslateCookie = pf.getTranslateCookie("", "", true); 339 pf.translateCookie = checkTranslateCookie; 340 if ( 341 checkTranslateCookie != "" && 342 checkTranslateCookie != pf.translateFrom 343 ) { 344 $("#selectLng option:selected").prop("selected", false); 345 $("#selectLng option[value='" + checkTranslateCookie + "']") 346 .prop("selected", true) 347 .trigger("change"); 348 if ( 349 /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( 350 navigator.userAgent 351 ) 352 ) { 353 $("#selectLngMob option:selected").prop( 354 "selected", 355 false 356 ); 357 $( 358 "#selectLngMob option[value='" + 359 checkTranslateCookie + 360 "']" 361 ) 362 .prop("selected", true) 363 .trigger("change"); 364 } 365 } 366 let chkExtlng = $("#externalLng").val() != '' && $("#externalLng").val() != pf.translateFrom ? $("#externalLng").val() : ''; 367 if ( 368 chkExtlng != '' 369 ) { 370 $("#selectLng option:selected").prop("selected", false); 371 $("#selectLng option[value='" + chkExtlng + "']") 372 .prop("selected", true) 373 .trigger("change"); 374 if ( 375 /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( 376 navigator.userAgent 377 ) 378 ) { 379 $("#selectLngMob option:selected").prop( 380 "selected", 381 false 382 ); 383 $( 384 "#selectLngMob option[value='" + 385 chkExtlng + 386 "']" 387 ) 388 .prop("selected", true) 389 .trigger("change"); 390 } 391 } 392 if (pf.debugTranslate == true) { 393 pf.removeLoader(); 394 } 395 }); 396 }, 397 iltBosWidgets: function () { 398 var pf = this; 399 console.log( 400 "%c ILTranslation BOS Widgets ", 401 "background: #0A0A0A; color: #45AAEB; padding-left:5px; padding: 1px; border-left: 3px solid #45AAEB;", 402 ); 403 try { 404 var checkTranslateCookie = pf.getTranslateCookie("", "", true); 405 var iframe = document.getElementById(pf.currentWidget); 406 if (pf.callbackScript == false) { 407 var iframe = document.getElementById(pf.currentWidget); 408 var iframeSelector = 409 iframe.contentWindow.document.getElementById( 410 "languageSelector" 411 ); 412 envElm = 413 iframe.contentWindow.document.querySelector("body"); 414 } else { 415 iframe = document; 416 var iframeSelector = 417 iframe.getElementById("languageSelector"); 418 envElm = iframe.querySelector("body"); 419 } 420 if (pf.autoTranslate != "") { 421 pf.translateTo = pf.autoTranslate; 422 if (pf.translateFrom != pf.translateTo) { 423 pf.iltBosWidgetActions(envElm, iframe); 424 } 425 return; 426 } 427 console.log( 428 "%c ILTranslation BOS Widgets ", 429 "background: #0A0AAA; color: #45AC0B; padding-left:5px; padding: 1px; border-left: 3px solid #45C1EB;",
430 "checkTranslateCookie: " + checkTranslateCookie, 431 "pf.translateFrom: " + pf.translateFrom, 432 "pf.translateTo: " + pf.translateTo, 433 "language selector val" + $("#languageSelector").val() 434 ); 435 if(checkTranslateCookie !== '' && checkTranslateCookie !== pf.translateFrom) { 436 //disable all options translateFrom 437 $("#languageSelector option").each(function () { 438 if ( 439 $(this).val() !== "" && 440 $(this).val() !== pf.translateFrom 441 ) { 442 $(this).prop("disabled", true); 443 } else { 444 $(this).prop("disabled", false); 445 } 446 }); 447 } 448 449 iframeSelector.addEventListener("change", function () { 450 var lngSelected = this.value; 451 pf.translateTo = lngSelected; 452 453 if (pf.translateFrom != pf.translateTo) { 454 pf.showLoader(); 455 var shortLngVal = 456 $("#languageSelector option:selected").val() != "" 457 ? $("#languageSelector option:selected").val() 458 : pf.translateFrom; 459 $(this).prop("selectedIndex", 0); 460 461 $("#languageSelector option:selected").text( 462 pf.selectorBaseTxtWidget + 463 " " + 464 pf.selectorShortWidget[shortLngVal] 465 ); 466 $( 467 '#languageSelector option[value="' + 468 pf.translateTo + 469 '"]' 470 ).prop("disabled", true); 471 //add disabled to other options than selected except english 472 $("#languageSelector option").each(function () { 473 if ( 474 $(this).val() != "" && 475 $(this).val() != pf.translateTo && 476 $(this).val() != pf.translateFrom 477 ) { 478 $(this).prop("disabled", true); 479 } 480 }); 481 482 pf.getTranslateCookie( 483 "setCookie", 484 pf.translateTo, 485 false 486 ); 487 488 pf.iltBosWidgetActions(envElm, iframe); 489 } else { 490 pf.getTranslateCookie("unsetCookie", "", false); 491 pf.removeLoader(); 492 pf.backToOriginal(); 493 var shortLngVal = 494 $("#languageSelector option:selected").val() != "" 495 ? $("#languageSelector option:selected").val() 496 : pf.translateFrom; 497 $(this).prop("selectedIndex", 0); 498 $("#languageSelector option:selected").text( 499 pf.selectorBaseTxtWidget + 500 " " + 501 pf.selectorShortWidget[shortLngVal] 502 ); 503 console.log( 504 "%c +++++ FALSE", 505 "color:#cc1100; font-size:14px; font-weight:bold; padding:2px; border:3px solid #069; background:#d1d2d3;", 506 $(this).find("option") 507 ); 508 $(this).find("option").prop("disabled", false); 509 } 510 }); 511 if ( 512 checkTranslateCookie != pf.translateFrom && 513 checkTranslateCookie != "" && 514 typeof checkTranslateCookie != "undefined" 515 ) { 516 iframeSelector.value = checkTranslateCookie; 517 pf.translateTo = checkTranslateCookie; 518 if (pf.translateFrom != pf.translateTo) { 519 pf.iltBosWidgetActions(envElm, iframe); 520 } 521 } 522 } catch (e) { 523 console.log( 524 "%c -- ILT iltBosWidgets ERR 0x001", 525 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 526 e 527 ); 528 } 529 }, 530 iltBosWidgetActions: function (envElm, iframe) { 531 var pf = this; 532 try { 533 $.each(pf.loadedIframes, function (i, v) { 534 if (v == iframe.getAttribute("id")) { 535 pf.validIFrames = []; 536 } 537 }); 538 var loader = envElm.querySelector(".iltFrameLoader"); 539 if (loader !== null) { 540 if (loader.style.display == "none") { 541 loader.style.display = "block"; 542 } 543 pf.iframeLoaders.push(loader); 544 } 545 envElm.setAttribute("iltLoaded", "true"); 546 setTimeout(function () { 547 pf.translatedIframes.push(envElm); 548 pf.getTextInNode(envElm, pf.toTranslate); 549 pf.translateImages(); 550 pf.translateOthers(); 551 pf.validIFrames.push({ 552 node: envElm, 553 }); 554 pf.translateNodes.push(iframe); 555 pf.translateIframes(envElm); 556 try { 557 pf.loadedIframes.push(iframe.getAttribute("id")); 558 } catch (e) { 559 console.log( 560 "%c -- ILT iltBosWidgetActions ERR 0x002", 561 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 562 e 563 ); 564 } 565 }, 4500); 566 } catch (e) { 567 console.log( 568 "%c -- ILT iltBosWidgetActions ERR 0x001", 569 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 570 e 571 ); 572 } 573 }, 574 getTranslation: function (envElm) { 575 console.log( 576 "%c ILT getTranslation 1", 577 "color:#00c2f5; background-color:#012345; padding:8px; font-weight:bold; border-left:2px solid #00c2f5; margin-bottom:8px;" 578 ); 579 var pf = this; 580 pf.getToken(); 581 pf.showLoader(); 582 try { 583 var trNodes = []; 584 pf.getTextInNode(envElm, pf.toTranslate); 585 pf.translateOthers(); 586 trNodes.push(envElm.querySelectorAll("._translate_")); 587 pf.setObserver(envElm); 588 pf.nodesToObserve.push(envElm); 589 } catch (e) { 590 console.log( 591 "%c -- ILT getTranslation ERR 0x001", 592 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 593 e 594 ); 595 } 596 console.log( 597 "%c ILT translatePage 3", 598 "color:#00c2f5; background-color:#012345; padding:8px; font-weight:bold; border-left:2px solid #00c2f5; margin-bottom:8px;", 599 trNodes.length, 600 trNodes 601 ); 602 pf.translatePage(trNodes); 603 }, 604 translateIframes: function () { 605 var pf = this; 606 setTimeout(function () { 607 try { 608 var trNodes = []; 609 if (pf.validIFrames.length > 0) { 610 $.each(pf.validIFrames, function (index, element) { 611 trNodes.push( 612 element.node.querySelectorAll("._translate_") 613 ); 614 pf.nodesToObserve.push(element.node); 615 pf.setObserver(element.node); 616 }); 617 pf.translatePage(trNodes); 618 } 619 } catch (e) { 620 console.log( 621 "%c -- ILT translateIframes ERR 0x001", 622 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 623 e 624 ); 625 } 626 }, 4000); 627 }, 628 getHelpScout: function () { 629 var pf = this; 630 try { 631 var translateVal = 632 $("#iltSelectedLng").val() || 633 $("#mob_iltSelectedLng").val(); 634 if (translateVal !== pf.translateFrom) { 635 var hsCatched = false;
636 window.Beacon("on", "ready", function () { 637 setTimeout(function () { 638 pf.validBeacon = []; 639 window.Beacon("open"); 640 var beaconContent = 641 document.getElementById("beacon-container"); 642 var beaconIframes = 643 beaconContent.querySelectorAll("iframe"); 644 $.each(beaconIframes, function (i, content) { 645 var node = 646 content.contentWindow.document.querySelector( 647 "body" 648 ); 649 pf.getTextInNode(node, pf.toTranslate); 650 pf.validBeacon.push({ 651 node: node, 652 }); 653 pf.translateNodes.push(node); 654 }); 655 pf.translateBeacons(); //translateBeacons: 656 window.Beacon("toggle"); 657 hsCatched = true; 658 }, 2000); 659 }); 660 if (hsCatched === false) { 661 if (typeof window.Beacon("info") !== undefined) { 662 window.Beacon("open"); 663 var beaconContent = 664 document.getElementById("beacon-container"); 665 if (beaconContent !== null) { 666 var beaconContent = 667 document.getElementById("beacon-container"); 668 var beaconIframes = 669 beaconContent.querySelectorAll("iframe"); 670 $.each(beaconIframes, function (i, content) { 671 var node = 672 content.contentWindow.document.querySelector( 673 "body" 674 ); 675 pf.getTextInNode(node, pf.toTranslate); 676 pf.validBeacon.push({ 677 node: node, 678 }); 679 pf.translateNodes.push(node); 680 }); 681 } 682 pf.translateBeacons(); 683 window.Beacon("toggle"); 684 } 685 } 686 } 687 } catch (e) { 688 console.log( 689 "%c -- ILT getHelpScout ERR 0x001", 690 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 691 e 692 ); 693 } 694 }, 695 translateBeacons: function () { 696 var pf = this; 697 try { 698 var trNodes = []; 699 if (pf.validBeacon.length > 0) { 700 $.each(pf.validBeacon, function (index, element) { 701 trNodes.push( 702 element.node.querySelectorAll("._translate_") 703 ); 704 pf.nodesToObserve.push(element.node); 705 pf.setObserver(element.node); 706 }); 707 console.log( 708 "%c ILT translatePage 1", 709 "color:#00c2f5; background-color:#012345; padding:8px; font-weight:bold; border-left:2px solid #00c2f5; margin-bottom:8px;", 710 trNodes.length, 711 trNodes 712 ); 713 pf.translatePage(trNodes); //translatePage: 714 } 715 } catch (e) { 716 console.log( 717 "%c -- ILT translateBeacons ERR 0x001", 718 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 719 e 720 ); 721 } 722 }, 723 translateImages: function () { 724 var pf = this; 725 try { 726 var imgNodes = []; 727 if (pf.validImages.length > 0) { 728 $.each(pf.validImages, function (index, element) { 729 if (element.node.title != "") { 730 imgNodes.push(element.node); 731 } 732 }); 733 } 734 var textToTranslate = []; 735 textToTranslate[0] = []; 736 if (imgNodes.length > 0) {
737 $.each(imgNodes, function (i, node) { 738 if (node.title != "") { 739 textToTranslate[0][i] = node.title; 740 } 741 }); 742 pf.apiConnect(textToTranslate, "IMG"); 743 } 744 } catch (e) { 745 console.log( 746 "%c -- ILT translateImages ERR 0x001", 747 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 748 e 749 ); 750 } 751 }, 752 translateOthers: function () { 753 var pf = this; 754 try { 755 var otherNodes = []; 756 var otherElmNodes = []; 757 if (pf.validOthers.length > 0) { 758 $.each(pf.validOthers, function (index, element) { 759 if (!pf.otherElms.includes(element.thisNode)) { 760 switch (element.nodeType) { 761 case "placeholder": 762 element.thisNode.value = 763 element.thisNode.placeholder; 764 otherNodes.push(element.thisNode); 765 break; 766 default: 767 } 768 pf.otherElms.push(element.thisNode); 769 } 770 }); 771 } 772 if (pf.validBtns.length > 0) { 773 $.each(pf.validBtns, function (index, element) { 774 if (!pf.otherElms.includes(element.thisNode)) { 775 if ( 776 element.thisNode.value != "" && 777 element.thisNode.name == "" 778 ) { 779 otherElmNodes.push(element.thisNode); 780 } 781 pf.otherElms.push(element.thisNode); 782 } 783 }); 784 } 785 var textToTranslate = []; 786 textToTranslate[0] = []; 787 if (otherNodes.length > 0) { 788 $.each(otherNodes, function (i, node) { 789 if (node.value != "") { 790 textToTranslate[0][i] = node.value; 791 } else if (node.nodeType == "placeholder") { 792 textToTranslate[0][i] = node.placeholder; 793 } 794 }); 795 pf.apiConnect(textToTranslate, "OTHER"); 796 } 797 var textToTranslateOthers = []; 798 textToTranslateOthers[0] = []; 799 if (otherElmNodes.length > 0) { 800 $.each(otherElmNodes, function (i, node) { 801 if (node.value != "") { 802 textToTranslateOthers[0][i] = node.value; 803 } else if ( 804 node.nodeType == "button" || 805 node.nodeType == "submit" 806 ) { 807 textToTranslateOthers[0][i] = node.value; 808 } 809 }); 810 pf.apiConnect(textToTranslateOthers, "OTHERBTNS"); 811 } 812 } catch (e) { 813 console.log( 814 "%c -- ILT translateOthers ERR 0x001", 815 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 816 e 817 ); 818 } 819 }, 820 translatePage: function (trNodes) { 821 var pf = this; 822 try { 823 if (trNodes.length > 0) { 824 $.each(trNodes, function (index, node) { 825 pf.nodesToTranslate = []; 826 $.each(node, function (idx, elm) { 827 if (elm.innerHTML != "") { 828 pf.nodesToTranslate.push(elm.innerHTML); 829 } 830 }); 831 var scopeLimit = 0; 832 var scopeCycle = 0; 833 var scopeIdx = 0; 834 var textToTranslate = []; 835 textToTranslate[scopeCycle] = [];
836 $.each(pf.nodesToTranslate, function (index, element) { 837 var text = element; 838 scopeLimit += text.length; 839 if ( 840 text.trim() != "" && 841 scopeLimit < pf.translateLimit 842 ) { 843 textToTranslate[scopeCycle][scopeIdx] = text; 844 scopeIdx++; 845 } else { 846 textToTranslate[scopeCycle][scopeIdx] = text; 847 scopeLimit = 0; 848 scopeIdx = 0; 849 scopeCycle++; 850 if (textToTranslate[scopeCycle] == undefined) 851 textToTranslate[scopeCycle] = []; 852 } 853 }); 854 pf.apiConnect(textToTranslate, node); 855 pf.nodesToTranslate = []; 856 }); 857 } 858 pf.translateOthers(); 859 trNodes = []; 860 } catch (e) { 861 console.log( 862 "%c -- ILT translatePage ERR 0x001", 863 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 864 e 865 ); 866 } 867 }, 868 apiConnect: function (textToTranslate, node) { 869 var pf = this; 870 871 if (textToTranslate[0].length > 0 && pf.debugTranslate == false) { 872 var thisLength = textToTranslate.length; 873 var thisScope = 0; 874 $.each(textToTranslate, function (scopeIdx, scopeText) { 875 try { 876 if (scopeText.length > 0) { 877 $.ajax({ 878 url: pf.apiEndPoint, 879 type: "POST", 880 async: false, 881 cache: false, 882 timeout: 500, 883 beforeSend: function (xhr) { 884 }, 885 always: function () { 886 }, 887 data: { 888 sourceLanguageCode: pf.translateFrom, 889 targetLng: pf.translateTo, 890 contents: scopeText 891 }, 892 893 dataType: "json", 894 success: function (d) { 895 try { 896 if (node == "IMG") { 897 $.each( 898 pf.validImages, 899 function (i, v) { 900 if ( 901 d.translations[i] 902 .translatedText != 903 "" 904 ) { 905 var translatedText = 906 d.translations[i] 907 .translatedText; 908 v.node.title = 909 translatedText; 910 var originalText = 911 scopeText[i]; 912 913 pf.translatedImages[i] = 914 { 915 node: v, 916 nodeStackId: i, 917 original: 918 originalText, 919 translated: 920 translatedText, 921 }; 922 } 923 } 924 ); 925 } else if (node == "OTHER") { 926 $.each( 927 pf.validOthers, 928 function (i, v) { 929 if ( 930 v.nodeType.toLowerCase() == 931 "placeholder" 932 ) { 933 var originalText = 934 v.thisNode 935 .placeholder; 936 v.thisNode.value = ""; 937 var tText = 938 pf.iltCapitalize( 939 d.translations[ 940 i 941 ].translatedText 942 ); 943 944 v.thisNode.placeholder = 945 tText; 946 pf.translatedOthers[i] = 947 { 948 nodeType: 949 v.nodeType, 950 originalNode: 951 v.thisNode, 952 originalText: 953 scopeText[ 954 i 955 ], 956 }; 957 } 958 } 959 ); 960 pf.validOthers = []; 961 } else if (node == "OTHERBTNS") { 962 $.each( 963 pf.validBtns, 964 function (i, v) { 965 if ( 966 v.thisNode.value != "" 967 ) { 968 var translatedText = 969 d.translations[i] 970 .translatedText; 971 v.thisNode.value = 972 translatedText; 973 var originalText = 974 scopeText[i]; 975 pf.translatedOthersBtns[ 976 i 977 ] = { 978 nodeType: 979 v.nodeType, 980 originalNode: 981 v.thisNode, 982 originalText: 983 originalText, 984 }; 985 } 986 } 987 ); 988 pf.validBtns = []; 989 } else { 990 $.each( 991 d.translations, 992 function (i, v) { 993 //store node data 994 if ( 995 typeof node[ 996 pf.lastIndex 997 ].dataset != "undefined" 998 ) { 999 var nodeStackId = 1000 node[pf.lastIndex] 1001 .dataset 1002 .stackid; 1003 var nodeOriginalText = 1004 $( 1005 node[ 1006 pf.lastIndex 1007 ] 1008 ).text(); 1009 pf.translatedElms[ 1010 nodeStackId 1011 ] = { 1012 node: node[ 1013 pf.lastIndex 1014 ], 1015 nodeStackId: 1016 nodeStackId, 1017 original: 1018 nodeOriginalText, 1019 translated: 1020 v.translatedText, 1021 }; 1022 pf.backElms[ 1023 nodeStackId 1024 ] = { 1025 node: node[ 1026 pf.lastIndex 1027 ], 1028 nodeStackId: 1029 nodeStackId, 1030 original: 1031 nodeOriginalText, 1032 translated: 1033 v.translatedText, 1034 }; 1035 var translatedText = 1036 v.translatedText; 1037 1038 pf.lastIndex++; 1039 } 1040 } 1041 ); 1042 thisScope++; 1043 1044 if (thisScope == thisLength) { 1045 pf.lastIndex = 0; 1046 } 1047 } 1048 } catch (e) { 1049 console.log( 1050 "%c -- ILT apiConnect ERR 0x001", 1051 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1052 e 1053 ); 1054 } 1055 }, 1056 error: function (e) { 1057 console.log( 1058 "%c -- ILT apiConnect ERR 0x002", 1059 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1060 e 1061 ); 1062 }, 1063 }); 1064 } 1065 } catch (e) { 1066 console.log( 1067 "%c -- ILT runTranslation API ERR 0x003", 1068 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1069 e 1070 ); 1071 } 1072 pf.doTranslation(); 1073 }); 1074 } 1075 }, 1076 doTranslation: function () { 1077 var pf = this; 1078 1079 if (Object.keys(pf.translatedElms).length > 0) { 1080 try { 1081 $.each(pf.translatedElms, function (idx, elm) { 1082 if ( 1083 elm.translated != "" && 1084 typeof elm.translated != "undefined" 1085 ) { 1086 var translatedText = elm.translated; 1087 if (elm.node.parentElement !== null) { 1088 var elmNodeName = 1089 elm.node.parentElement.nodeName; 1090 if (elmNodeName in pf.preElements) { 1091 translatedText = " " + translatedText; 1092 } 1093 } 1094 var sanitizedTxt = pf.decodeHtml(translatedText); 1095 $(elm.node).text(sanitizedTxt); 1096 } 1097 }); 1098 1099 pf.translatedElms = {}; 1100 } catch (e) { 1101 console.log( 1102 "%c -- ILT doTranslation ERR 0x001", 1103 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1104 e 1105 ); 1106 } 1107 } 1108 if (pf.iframeLoaders.length > 0) { 1109 setTimeout(function () { 1110 $.each(pf.iframeLoaders, function (i, v) { 1111 v.style.display = "none"; 1112 }); 1113 pf.removeLoader(); 1114 }, 8000); 1115 } else { 1116 pf.removeLoader(); 1117 } 1118 }, 1119 backToOriginal: function () { 1120 var pf = this; 1121 try { 1122 pf.observer.disconnect(); 1123 if (Object.keys(pf.backElms).length > 0) { 1124 try { 1125 $.each(pf.backElms, funct
1125ion (idx, elm) { 1126 var originalText = document.createTextNode( 1127 elm.original 1128 ); 1129 if ( 1130 typeof elm.node.parentElement !== "undefined" && 1131 elm.node.parentElement !== null 1132 ) { 1133 elm.node.parentElement.insertBefore( 1134 originalText, 1135 elm.node 1136 ); 1137 elm.node.remove(); 1138 } 1139 }); 1140 } catch (e) { 1141 console.log( 1142 "%c -- ILT backToOriginal translatedElms ERR 1x001", 1143 "background: #333; color: #cc11ff; padding-left:3px; padding: 8px; font-weight: bold; border-left: 2px solid #FF3269; margin-bottom: 8px;", 1144 e 1145 ); 1146 } 1147 } 1148 if (Object.keys(pf.validImages).length > 0) { 1149 $.each(pf.translatedImages, function (i, v) { 1150 v.node.node.title = v.original; 1151 v.node.node.removeAttribute("data-stackid"); 1152 }); 1153 } 1154 if (Object.keys(pf.replaceImages).length > 0) { 1155 $.each(pf.replaceImages, function (i, v) { 1156 if (v.type == "lightbox") { 1157 v.node.querySelector(v.querySelector).href = 1158 v.lboxPath; 1159 } else { 1160 v.node.querySelector("img").src = v.imgPath; 1161 v.node.querySelector("img").srcset = 1162 v.srcSetPath !== null ? v.srcSetPath : ""; 1163 } 1164 }); 1165 } 1166 if (Object.keys(pf.translatedOthers).length > 0) { 1167 $.each(pf.translatedOthers, function (i, elm) { 1168 elm.originalNode.removeAttribute("data-stackid"); 1169 switch (elm.nodeType) { 1170 case "placeholder": 1171 elm.originalNode.placeholder = elm.originalText; 1172 break; 1173 case "button": 1174 case "submit": 1175 elm.originalNode.value = elm.originalText; 1176 break; 1177 } 1178 }); 1179 } 1180 if (Object.keys(pf.translatedOthersBtns).length > 0) { 1181 $.each(pf.translatedOthersBtns, function (i, elm) { 1182 elm.originalNode.removeAttribute("data-stackid"); 1183 switch (elm.nodeType) { 1184 case "placeholder": 1185 elm.originalNode.placeholder = elm.originalText; 1186 break; 1187 case "button": 1188 case "submit": 1189 elm.originalNode.value = elm.originalText; 1190 break; 1191 } 1192 }); 1193 } 1194 if (Object.keys(pf.validIFrames).length > 0) { 1195 $.each(pf.validIFrames, function (i, v) { 1196 v.node.removeAttribute("iltloaded"); 1197 }); 1198 } 1199 pf.iframeLoaders = []; 1200 pf.translateTo = ""; 1201 pf.toTranslate = []; 1202 pf.observerTurnedOn = false; 1203 pf.observedElms = []; 1204 pf.nodesToObserve = []; 1205 pf.translateCookie = ""; 1206 pf.stackId = 0; 1207 pf.validIFrames = []; 1208 pf.validBeacon = []; 1209 pf.validImages = []; 1210 pf.replaceImages = []; 1211 pf.validOthers = []; 1212 pf.validBtns = []; 1213 pf.otherElms = []; 1214 pf.translateNodes = []; 1215 pf.translatedOthers = []; 1216 pf.translatedOthersBtns = []; 1217 pf.translatedImages = []; 1218 pf.backElms = {}; 1219 } catch (e) { 1220 console.log( 1221 "%c -- ILT backToOriginal ERR 0x001", 1222 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1223 e 1224 ); 1225 } 1226 }, 1227 setObserver: function (observerElm) { 1228 var pf = this; 1229 pf.observedElms.push(observerElm); 1230 // Callback function to execute when mutations are observed 1231 var callback = function (mutationsList) { 1232 var trNodes = []; 1233 for (var mutation of mutationsList) { 1234 if (mutation.type == "childList") { 1235 if (Object.keys(mutation.addedNodes).length > 0) { 1236 try {
1237 mutation.addedNodes.forEach(function (element) { 1238 var chkNoTranslate = 1239 pf.noTranslateCheck(element); 1240 if (element.nodeName == "P") { 1241 if (element.classList.contains("countText")) { 1242 element.querySelectorAll("option").forEach(function (option) { 1243 option.classList.add(pf.noTranslateClass); 1244 }); 1245 chkNoTranslate = false; 1246 } 1247 } 1248 if (chkNoTranslate == false) return false; 1249 if ( 1250 !(element.nodeName in pf.excludeName) && 1251 element.nodeName != "FONT" 1252 ) { 1253 if (element.nodeType == 3) { 1254 pf.getTextInNode( 1255 element, 1256 pf.toTranslate 1257 ); 1258 } else { 1259 if ( 1260 typeof element.className != 1261 "undefined" && 1262 typeof element.className != 1263 "object" && 1264 element.nodeType == 1 && 1265 element.className.indexOf( 1266 "_translate_" 1267 ) == -1 1268 ) { 1269 pf.getTextInNode( 1270 element, 1271 pf.toTranslate 1272 ); 1273 } 1274 } 1275 } else if ( 1276 element.nodeName == "FONT" && 1277 element.className.indexOf( 1278 "_translate_" 1279 ) >= 0 1280 ) { 1281 trNodes.push(mutation.addedNodes[0]); 1282 } else { 1283 } 1284 }); 1285 } catch (e) { 1286 console.log( 1287 "%c -- ILT setObserver Mutations ERR 0x001", 1288 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1289 e 1290 ); 1291 } 1292 } 1293 } 1294 } 1295 if (trNodes.length > 0) { 1296 var nodes = []; 1297 var getNodes = Array.from(trNodes); 1298 nodes[0] = getNodes; 1299 pf.translatePage(nodes); 1300 } 1301 }; 1302 try { 1303 // Create an observer instance linked to the callback function 1304 if (pf.observerTurnedOn == false) 1305 pf.observer = new MutationObserver(callback); 1306 // Start observing the target node for configured mutations 1307 pf.observer.observe(observerElm, pf.observerConfig); 1308 pf.observerTurnedOn = true; 1309 } catch (e) { 1310 console.log( 1311 "%c -- ILT setObserver ERR 0x001", 1312 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1313 e 1314 ); 1315 } 1316 }, 1317 getTextInNode: function (node, stack) { 1318 var pf = this; 1319 try { 1320 if ( 1321 typeof node.classList != "undefined" && 1322 node.classList.length > 0 && 1323 node.classList.contains(pf.noTranslateClassD) 1324 ) { 1325 node.classList.forEach(function (className) { 1326 var selectField = node.classList.contains("ILTSelect"); 1327 if (selectField == true) { 1328 node.querySelectorAll("option").forEach(function ( 1329 option 1330 ) { 1331 option.classList.add(pf.noTranslateClass); 1332 }); 1333 } 1334 var radioBtn = node.classList.contains("ILTRbtn"); 1335 if (radioBtn == true) { 1336 var radioBtnList = node.querySelectorAll("li"); 1337 radioBtnList.forEach(function (li) { 1338 if (li.nextSibling !== null) 1339 li.classList.add(pf.noTranslateClass); 1340 }); 1341 } 1342 }); 1343 } 1344 var chkNoTranslate = pf.noTranslateCheck(node); 1345 if (chkNoTranslate == false) return false;
1346 if (node.nodeName == "UBDIV") { 1347 return false; 1348 } 1349 if (node.nodeName == "INPUT" || node.nodeName == "TEXTAREA") { 1350 if (node.getAttribute("data-stackid") !== null) { 1351 return false; 1352 } 1353 var allowedTypes = { 1354 text: 1, 1355 submit: 1, 1356 button: 1, 1357 textarea: 1, 1358 password: 1, 1359 }; 1360 if (node.type in allowedTypes) { 1361 if ( 1362 node.type == "textarea" || 1363 node.type == "text" || 1364 node.type == "password" 1365 ) { 1366 if (node.placeholder != "" && node.value == "") { 1367 node.setAttribute("data-stackId", pf.stackId); 1368 pf.stackId++; 1369 pf.validOthers.push({ 1370 nodeType: "placeholder", 1371 stackId: pf.stackId, 1372 thisNode: node, 1373 }); 1374 pf.translateNodes.push(node); 1375 } 1376 } else if ( 1377 node.type == "submit" || 1378 node.type == "button" 1379 ) { 1380 if (node.value != "" && node.name == "") { 1381 node.setAttribute("data-stackId", pf.stackId); 1382 pf.stackId++; 1383 pf.validBtns.push({ 1384 nodeType: node.type, 1385 stackId: pf.stackId, 1386 thisNode: node, 1387 }); 1388 pf.translateNodes.push(node); 1389 } 1390 } 1391 } 1392 } 1393 1394 if (!(node.nodeName in pf.excludeName)) { 1395 pf.translateNodes.push(node); 1396 //iterate nodes 1397 if ( 1398 typeof node.className != "undefined" && 1399 typeof node.className != "object" && 1400 ((node.nodeName == "DIV" && 1401 node.className.indexOf("ilTranslate") >= 0) || 1402 (node.nodeName == "A" && 1403 node.className.indexOf( 1404 "entry-featured-image-url" 1405 ) >= 0)) 1406 ) { 1407 //try imgPath 1408 try { 1409 fromLang = pf.translateFrom; 1410 toLang = pf.translateTo; 1411 var imgPath = node 1412 .querySelector("img") 1413 .getAttribute("src"); 1414 var regExp = new RegExp( 1415 "(-" + fromLang + ")(.|-d+xd+)", 1416 "g" 1417 ); //(-en)(\.|-\d+x\d+) 1418 var replaceSrc = imgPath.replace( 1419 regExp, 1420 "-" + toLang + "$2" 1421 ); 1422 var srcSetPath = node 1423 .querySelector("img") 1424 .getAttribute("srcset"); 1425 var replaceSrcSet = 1426 srcSetPath !== null 1427 ? srcSetPath.replaceAll( 1428 regExp, 1429 "-" + toLang + "$2" 1430 ) 1431 : ""; 1432 node.querySelector("img").src = replaceSrc; 1433 node.querySelector("img").srcset = replaceSrcSet; 1434 1435 pf.replaceImages.push({ 1436 node: node, 1437 type: "img", 1438 replaceSrc: replaceSrc, 1439 replaceSrcSet: replaceSrcSet, 1440 srcSetPath: srcSetPath, 1441 imgPath: imgPath, 1442 }); 1443 //lightbox 1444 if ( 1445 node.querySelector("a.et_pb_lightbox_image") !== 1446 null 1447 ) { 1448 var lboxPath = node 1449 .querySelector("a.et_pb_lightbox_image") 1450 .getAttribute("href"); 1451 //check if is image 1452 var isImage = lboxPath.match( 1453 /\.(jpeg|jpg|gif|png)$/ 1454 ); 1455 if (isImage) { 1456 var replaceLbox = lboxPath.replace( 1457 regExp, 1458 "-" + toLang + "$2" 1459 ); 1460 node.querySelector( 1461 "a.et_pb_lightbox_image" 1462 ).href = replaceLbox; 1463 pf.replaceImages.push({ 1464 node: node, 1465 type: "lightbox", 1466 lboxPath: lboxPath, 1467 querySelector: "a.et_pb_lightbox_image", 1468 }); 1469 } 1470 } 1471 } catch (e) { 1472 console.log( 1473 "%c ILT try imgPath ERR 0x002", 1474 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1475 e 1476 ); 1477 } 1478 } 1479 1480 //jquery validate errors 1481 if ( 1482 node.nodeType == 3 && 1483 Object.keys(node.childNodes).length == 0 && 1484 node.nodeValue in pf.jqValidate && 1485 node.parentElement !== null 1486 ) { 1487 td = document.createElement("font"); 1488 td.className = "_translate_"; 1489 var textValue = node.nodeValue.replace( 1490 /(\r\n|\r|\n)/g, 1491 "" 1492 ); 1493 td.append(textValue); 1494 td.setAttribute("data-stackId", pf.stackId); 1495 node.parentElement.insertBefore(td, node); 1496 node.remove(); 1497 pf.stackId++; 1498 } 1499
1500 node.childNodes.forEach(function (element) { 1501 if ( 1502 typeof node.nodeName != "undefined" && 1503 node.nodeName == "A" 1504 ) { 1505 if (node.title != "") { 1506 node.setAttribute("data-stackId", pf.stackId); 1507 pf.validImages.push({node: node}); 1508 pf.translateNodes.push(node); 1509 pf.stackId++; 1510 } 1511 } 1512 if (element.nodeType === 3) { 1513 var stripped = String(element.nodeValue) 1514 .replace(/(\r\n|\r|\n)/g, "") 1515 .trim(); 1516 if (stripped != "") { 1517 stack[pf.stackId] = stripped; 1518 pf.setNodeTranslation(element, pf.stackId); 1519 pf.stackId++; 1520 } 1521 } else { 1522 if ( 1523 typeof element.className != "undefined" && 1524 typeof element.className != "object" && 1525 element.nodeType == 1 && 1526 element.className.indexOf("_translate_") == -1 1527 ) { 1528 pf.getTextInNode(element, stack); 1529 } 1530 //exit(); 1531 } 1532 }); 1533 } else { 1534 if ( 1535 typeof node.nodeName != "undefined" && 1536 node.nodeName == "IMG" 1537 ) { 1538 if (node.title != "") { 1539 node.setAttribute("data-stackId", pf.stackId); 1540 pf.validImages.push({node: node}); 1541 pf.translateNodes.push(node); 1542 pf.stackId++; 1543 } 1544 } 1545 } 1546 } catch (e) { 1547 console.log( 1548 "%c -- ILT getTextInNode ERR 0x001", 1549 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1550 e 1551 ); 1552 } 1553 }, 1554 getIframes: function () { 1555 var pf = this; 1556 var iframes = document.querySelectorAll("iframe"); 1557 if (iframes.length > 0) { 1558 try { 1559 iframes.forEach(function (iframe, idx) { 1560 if ( 1561 typeof iframe.dataset.translate != "undefined" && 1562 iframe.dataset.translate == "true" 1563 ) { 1564 return; 1565 } 1566 var iframeSrc = iframe.src; 1567 var elmId = iframe.id; 1568 var currentHost = window.location.host; 1569 var checkHost = 1570 iframeSrc != "" && 1571 iframeSrc.indexOf(currentHost) >= 0 && 1572 iframeSrc.indexOf(currentHost) < 40 1573 ? true 1574 : false; 1575 if (checkHost) { 1576 var loadIframe = false; 1577 if ( 1578 pf.translateCookie != "" && 1579 pf.translateCookie != pf.translateFrom 1580 ) { 1581 pf.showLoader(); 1582 document.getElementById(elmId).onload = 1583 function () { 1584 try { 1585 loadIframe = true; 1586 envElm = 1587 this.contentWindow.document.querySelector( 1588 "body" 1589 ); 1590 setTimeout(function () { 1591 if ( 1592 envElm.getAttribute( 1593 "iltLoaded" 1594 ) === null 1595 ) { 1596 pf.validIFrames = []; 1597 var loader = 1598 envElm.querySelector( 1599 ".iltFrameLoader" 1600 ); 1601 if (loader !== null) { 1602 if ( 1603 loader.style 1604 .display == 1605 "none" 1606 ) { 1607 loader.style.display = 1608 "block"; 1609 } 1610 pf.iframeLoaders.push( 1611 loader 1612 ); 1613 } 1614 envElm.setAttribute( 1615 "iltLoaded", 1616 "true" 1617 ); 1618 pf.getTextInNode( 1619 envElm, 1620 pf.toTranslate 1621 ); 1622 pf.validIFrames.push({ 1623 node: envElm, 1624 }); 1625 pf.translateNodes.push( 1626 iframe 1627 ); 1628 pf.loadedIframes.push( 1629 elmId 1630 ); 1631 pf.translateIframes(); 1632 } 1633 }, 4000); 1634 } catch (e) { 1635 console.log( 1636 "%c -- ILT getIFrames ERR 0x001", 1637 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1638 e 1639 ); 1640 } 1641 }; 1642 } 1643 1644 if (loadIframe == false) { 1645 pf.showLoader(); 1646 var envElm = 1647 iframe.contentWindow.document.querySelector( 1648 "body" 1649 ); 1650 var loader = 1651 envElm.querySelector(".iltFrameLoader"); 1652 if (loader !== null) { 1653 if (loader.style.display == "none") { 1654 loader.style.display = "block"; 1655 } 1656 pf.iframeLoaders.push(loader); 1657 } 1658 setTimeout(function () { 1659 if ( 1660 envElm.getAttribute("iltLoaded") === 1661 null 1662 ) { 1663 envElm.setAttribute( 1664 "iltLoaded", 1665 "true" 1666 ); 1667 pf.getTextInNode( 1668 envElm, 1669 pf.toTranslate 1670 ); 1671 pf.validIFrames.push({node: envElm}); 1672 pf.translateNodes.push(iframe); 1673 pf.loadedIframes.push(elmId); 1674 pf.translateIframes(); 1675 } 1676 }, 4000); 1677 } 1678 } 1679 }); 1680 } catch (e) { 1681 console.log( 1682 "%c -- ILT getIframes ERR 0x002 ", 1683 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1684 e 1685 ); 1686 } 1687 } 1688 }, 1689 noTranslateCheck: function (target) { 1690 var pf = this; 1691 try { 1692 var returnChk = true; 1693 //ClassList 1694 if ( 1695 typeof target.classList != "undefined" && 1696 target.classList.length > 0 1697 ) { 1698 target.classList.forEach(function (className) { 1699 if ( 1700 className == pf.noTranslateClass || 1701 className in pf.excludeClasses 1702 ) { 1703 returnChk = false;
1704 } 1705 }); 1706 } 1707 return returnChk; 1708 } catch (e) { 1709 console.log( 1710 "%c -- ILT noTranslateCheck ERR 0x001", 1711 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1712 e 1713 ); 1714 } 1715 }, 1716 setNodeTranslation: function (tNode, stackId) { 1717 var pf = this; 1718 var added; 1719 if (tNode.nodeType === 3) { 1720 if ( 1721 tNode.nodeValue != "" && 1722 !(tNode.nodeValue in pf.specialChars) 1723 ) { 1724 td = document.createElement("font"); 1725 td.className = "_translate_"; 1726 var textValue = tNode.nodeValue.replace( 1727 /(\r\n|\r|\n)/g, 1728 "" 1729 ); 1730 td.append(textValue); 1731 td.setAttribute("data-stackId", stackId); 1732 tNode.parentElement.insertBefore(td, tNode); 1733 tNode.remove(); 1734 added = true; 1735 } 1736 } else { 1737 added = false; 1738 } 1739 return added; 1740 }, 1741 getToken: function () { 1742 var pf = this; 1743 var idxXqr = $.ajax({ 1744 type: "POST", 1745 url: pf.endPoint, 1746 async: false, 1747 data: { 1748 do: "getToken", 1749 }, 1750 dataType: "json", 1751 beforeSend: function () { 1752 }, 1753 }); 1754 idxXqr.done(function (data) { 1755 if (data.payload.tokenValue != "") { 1756 pf.bearerToken = data.payload.tokenValue; 1757 } 1758 }); 1759 idxXqr.fail(function (data) { 1760 console.log("fails", data); 1761 }); 1762 idxXqr.always(function (data) { 1763 //console.log('always',data); 1764 }); 1765 }, 1766 getTranslateCookie: function (setUnset, toLng, checkCookie) { 1767 var pf = this; 1768 var response = false; 1769 var doAction = 1770 checkCookie == true 1771 ? "checkTranslateCookie" 1772 : "getTranslateCookie"; 1773 try { 1774 var idxXqr = $.ajax({ 1775 type: "POST", 1776 url: pf.endPoint, 1777 async: false, 1778 data: { 1779 do: doAction, 1780 setUnset: setUnset, 1781 checkCookie: checkCookie, 1782 toLng: toLng, 1783 lngCookie: pf.lngCookie, 1784 }, 1785 dataType: "json", 1786 beforeSend: function () { 1787 }, 1788 }); 1789 idxXqr.done(function (data) { 1790 if (pf.lngCookie != "") { 1791 switch (pf.lngCookie) { 1792 case "registerWindow": 1793 response = 1794 data.payload 1795 .ILTranslateCookieREGISTERWINDOW; 1796 break; 1797 case "parentWindow": 1798 response = 1799 data.payload.ILTranslateCookiePARENTWINDOW; 1800 break; 1801 } 1802 pf.widgetCookie = response; 1803 return; 1804 } 1805 response = data.payload.ILTranslateCookie; 1806 }); 1807 idxXqr.fail(function (data) { 1808 console.log("fails", data); 1809 }); 1810 idxXqr.always(function (data) { 1811 //console.log('always',data); 1812 }); 1813 } catch (e) { 1814 console.log( 1815 "%c -- ILT getTranslateCookie ERR 0x001", 1816 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1817 e 1818 ); 1819 } 1820 return response; 1821 }, 1822 getCookie: function (cname) { 1823 var name = cname + "="; 1824 var decodedCookie = decodeURIComponent(document.cookie); 1825 var ca = decodedCookie.split(";"); 1826 1827 for (var i = 0; i < ca.length; i++) { 1828 var c = ca[i]; 1829 while (c.charAt(0) == " ") { 1830 c = c.substring(1); 1831 } 1832 if (c.indexOf(name) == 0) { 1833 return c.substring(name.length, c.length); 1834 } 1835 } 1836 return ""; 1837 }, 1838 iltCapitalize: function (targetWord) { 1839 return targetWord 1840 .toLowerCase() 1841 .replace(/\w/, (firstLetter) => firstLetter.toUpperCase()); 1842 }, 1843 decodeHtml: function (translatedText) { 1844 var pf = this; 1845 try { 1846 var txt = document.createElement("textarea"); 1847 txt.innerHTML = translatedText; 1848 return txt.value; 1849 } catch (e) { 1850 console.log( 1851 "%c -- ILT --------------decodeHtml ERR 0x001", 1852 "background: #0A0A0A; color: #FF2345; padding-left:5px; padding: 1px; border-left: 3px solid #FF2345;", 1853 e 1854 ); 1855 } 1856 }, 1857 showLoader: function () { 1858 var pf = this; 1859 $("#ilTranslationBox").append( 1860 '<div class="lds-spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>' 1861 ); 1862 $("#selectLng").prop("disabled", true); 1863 }, 1864 removeLoader: function () { 1865 $(".lds-spinner").remove(); 1866 $("#selectLng").prop("disabled", false); 1867 }, 1868 }), 1869 $.extend({}); 1870 return ILTranslation; 1871})(jQuery, ILTranslation); 1872 1873var externalLoad = typeof loadFrom != "undefined" ? loadFrom : ""; 1874var ILTranslation = new ILTranslation({ 1875 loadFrom: externalLoad, 1876}); 1877ILTranslation.init();
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.