/* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/modules/translator/js/translator.min.js # Provides JS Core functions|API for J1 Module Translator # # Product/Info: # http://jekyll.one # # Copyright (C) 2022 Juergen Adams # # J1 Template is licensed under MIT License. # See: https://github.com/jekyll-one/J1 Template/blob/master/LICENSE # ----------------------------------------------------------------------------- */ "use strict";function Translator(d){var q=this;var w=log4javascript.getLogger("j1.core.translator");var m=new liteURL(window.location.href);var c=(m.protocol.includes("https"))?true:false;var r=false;var h;var u;var g={set:function(x,D,F,A,E,B){var C=window.btoa(D);var y="; expires=Thu, 01 Jan 1970 00:00:00 UTC";if(F>0){var z=new Date();z.setTime(z.getTime()+(F*24*60*60*1000));y="; expires="+z.toUTCString()}if(B){document.cookie=x+"="+(C||"")+y+"; Path=/; SameSite="+A+"; Domain="+E+"; Secure="+B+";"}else{document.cookie=x+"="+(C||"")+y+"; Path=/; SameSite="+A+";Domain="+E+"; "}},get:function(y){var B=y+"=";var x=document.cookie.split(";");for(var z=0;zB.length){z.visibleRows=B.length}MsDropdown.make(x,{byJson:{data:B,name:z.name,size:z.size,width:z.width,multiple:z.multiple,},enableAutoFilter:z.enableAutoFilter,visibleRows:z.visibleRows,})},error:function(A,C,B){w.error("\nfailed to retrieve JSON data from: "+z.url)}})}function n(){o.documentReady(function(){q.modal=document.getElementById(q.props.dialogContainerID);if(!q.modal){w.info("\nload consent modal");q.modal=document.createElement("div");q.modal.id=q.props.dialogContainerID;q.modal.style.display="none";q.modal.setAttribute("class","modal fade");q.modal.setAttribute("tabindex","-1");q.modal.setAttribute("role","dialog");q.modal.setAttribute("aria-labelledby",q.props.dialogContainerID);document.body.append(q.modal);q.$modal=$(q.modal);q.$modal.on("show.bs.modal",function(){var y;var z;w.info("\nshow.bs.modal: entered");$.when(k({url:"/assets/data/iso-639-language-codes-flags.json",elm:"iso-639-languages",selector:"dropdownJSON",width:400,visibleRows:8,})).then(function(A){w.info("\ncreating msDropdown from JSON data: finished")})});q.$modal.on("shown.bs.modal",function(){var y;var z;z=setInterval(function(){if(typeof document.getElementById("dropdownJSON").msDropdown!=="undefined"){y=document.getElementById("dropdownJSON").msDropdown;if(!y.length){w.error("\nno msDropdown found in translation dialog");q.$modal.hide()}else{if(q.props.translationLanguage==="auto"){h=navigator.language||navigator.userLanguage;u=h.split("-")[0]}else{u=q.props.translationLanguage}y.selectedIndex=$("#dropdownJSON option[value="+u+"]").index();if(q.props.disableLanguageSelector){y.disabled=true}$("#dropdownJSON").show();$("body").addClass("stop-scrolling");w.info("\nmsDropdown successfully loaded in translation dialog");clearInterval(z)}}},25)});q.$modal.on("hidden.bs.modal",function(){$("body").removeClass("stop-scrolling");i(q.props.postSelectionCallback,window)});var x=q.props.contentURL+"/index.html";$.get(x).done(function(y){w.info("\nloading consent modal: successfully");q.modal.innerHTML=y;q.modal.innerHTML=$("#"+q.props.xhrDataElement).eq(0).html();q.modal.style.display="block";$(q.modal).modal({backdrop:"static",keyboard:false});q.$buttonDoNotAgree=$("#translator-buttonDoNotAgree");q.$buttonAgree=$("#translator-buttonAgree");q.$buttonSave=$("#translator-buttonSave");q.$buttonAgreeAll=$("#translator-buttonAgreeAll");w.info("\nload/initialze options from cookie");l();j();$("#google-options").on("hide.bs.collapse",function(){r=false;l()}).on("show.bs.collapse",function(){r=true;l()});w.info("\ninitialze button event handler");q.$buttonDoNotAgree.click(function(){b()});q.$buttonAgree.click(function(){p()});q.$buttonSave.click(function(){$("#google-options").collapse("hide");t();j()});q.$buttonAgreeAll.click(function(){$("#google-options").collapse("hide");p()});q.$modal.modal("show")}).fail(function(){w.error("\nloading translator dialog (modal): failed");w.warn("\nprobably no|wrong `contentURL` set")})}else{q.$modal.modal("show")}}.bind(this))}function j(){var z=q.getSettings();if(z){for(var y in z){var x=q.$modal.find("#google-options .translator-option[data-name="+y+'] input[type="checkbox"]');x.prop("checked",z[y])}}}function l(){if(r){q.$buttonDoNotAgree.hide();q.$buttonAgree.hide();q.$buttonSave.show();q.$buttonAgreeAll.show()}else{q.$buttonDoNotAgree.show();q.$buttonAgree.show();q.$buttonSave.hide();q.$buttonAgreeAll.hide()}}function a(y){var x=q.$modal.find("#google-options .translator-option");var A={};for(var B=0;B