function InitializeLoginWidget() { var currentScript = null; var all_scripts = document.getElementsByTagName('script'); for (var i = 0; i < all_scripts.length; i++) { var script_url = all_scripts[i].src; if (script_url.indexOf('/js/LoginWidget.js') >= 0) currentScript = all_scripts[i]; } if (currentScript == null) currentScript = document.currentScript; let login_is_visible = (currentScript.getAttribute('data-is-visible') == "true"); let urlParams = new URLSearchParams(window.location.search); if (login_is_visible) { let login_lang = currentScript.getAttribute('data-lang'); if (login_lang == "zh-cn") login_lang = "zh"; let login_callback = currentScript.getAttribute('data-callback'); let login_parent_element_class = currentScript.getAttribute('data-parent-element-class'); var login_profile_avatar_image = currentScript.getAttribute('data-avatar-element-class'); var login_version = currentScript.getAttribute('data-version'); if ((!login_version) || (login_version == "")) { login_version = 1; } let login_callback_exists = (login_callback) && (typeof window[login_callback] === "function"); let login_parent_element_class_exists = (login_parent_element_class); function ResizeElement(element) { $(element).show(); } if ((login_callback_exists) || (login_parent_element_class_exists)) { let original_url = window.location.href; if (window.location.pathname == "/login_widget.php") original_url = urlParams.get("original_url"); $.ajax({ type: "POST", url: "/login_widget.php", data: { "lang": login_lang, "mode": "login_widget_ajax", "version": login_version, "original_url": original_url }, success: function (response) { if ((response) && (response != "")) { let server_answer = JSON.parse(response); if (server_answer.status == "ok") { if ((login_profile_avatar_image) && (server_answer.profile_avatar_image_html)) { $("." + login_profile_avatar_image).each(function () { $(this).html(server_answer.profile_avatar_image_html); }); } if (login_parent_element_class_exists) { $("." + login_parent_element_class).each(function () { $(this).html(server_answer.html); ResizeElement(this); }); } if (login_callback_exists) { window[login_callback](server_answer); } } } }, error: function (thrownError) { // do nothing } }); } } } InitializeLoginWidget();