(function () { var REGISTER_FALLBACK = "https://documents.laboitealivres.com/"; function isMobileViewport() { return window.matchMedia && window.matchMedia("(max-width: 991px)").matches; } function whenJQuery(fn) { if (isMobileViewport()) return; if (window.jQuery && window.jQuery.fn) { fn(window.jQuery); return; } var attempts = 0; var timer = setInterval(function () { if (window.jQuery && window.jQuery.fn) { clearInterval(timer); fn(window.jQuery); } else if (++attempts >= 120) { clearInterval(timer); } }, 50); } function showFormFallback(container) { if (!container) return; container.innerHTML = '
' + 'ลงทะเบียน' + "
"; } function boot($) { var registerModal = document.querySelector("#register_modal"); if (registerModal) { var registerAlert = document.querySelector("#register_alert"); var registerSuccessAlert = document.querySelector("#register_success_alert"); if (registerAlert) registerAlert.hidden = true; if (registerSuccessAlert) registerSuccessAlert.hidden = true; window.onRegisterAjaxRequestSuccess = function (response) { if (registerAlert) registerAlert.hidden = true; if (registerSuccessAlert) registerSuccessAlert.hidden = true; if (typeof window.registerPopup === "function") { registerPopup({ contentTitle: response.statusText, content: response.message, }); } if (response.status !== true) { if (registerAlert) { registerAlert.innerText = response.message; registerAlert.hidden = false; } return; } if (registerSuccessAlert) { registerSuccessAlert.innerText = response.message; registerSuccessAlert.hidden = false; } var dest = response.externalUrl; if (typeof dest === "string" && /^https?:\/\//i.test(dest)) { window.location.href = dest; } setTimeout(function () { var submitButtons = document.querySelectorAll(".btn-primary"); $(submitButtons).prop("disabled", true); }); }; $(registerModal).on("shown.bs.modal", function () { var registerPopupContainer = document.querySelector("#ajax_register_popup_container"); if (!registerPopupContainer) return; var registerForm = registerPopupContainer.querySelector("#register_form"); if (!registerForm) { $.ajax({ type: "GET", url: "/Register/AjaxRegisterPopup?language=th", contentType: "application/json; charset=utf-8", dataType: "html", timeout: 8000, success: function (response) { if (!response || response.indexOf("register_form") === -1) { showFormFallback(registerPopupContainer); return; } registerPopupContainer.innerHTML = response; var registerScriptTemplate = document.body.querySelector("#register_script_template"); if (registerScriptTemplate) { document.body.appendChild(registerScriptTemplate.content.cloneNode(true)); } if ( registerPopupContainer.querySelector("#register_form") && typeof $.validator !== "undefined" && $.validator.unobtrusive ) { $.validator.unobtrusive.parse("#register_form"); } if (typeof window.initializeBonusSelection === "function") initializeBonusSelection(); if (typeof window.initializeRegisterInfo === "function") initializeRegisterInfo(); if (typeof window.initializeThumbmark === "function") initializeThumbmark(); if (typeof window.initializeCountryCodeDropdown === "function") { initializeCountryCodeDropdown({ parentForm: "#register_form", translations: { contactNumberLengthErrorMessage: "Contact number can only consist of 9-12 digits.", }, }); } var copyButtons = document.querySelectorAll("#register_form [data-copy-button]"); Array.from(copyButtons).forEach(function (button) { if (typeof window.addCopyAction === "function") { window.addCopyAction(button); } }); var captchaContainer = document.querySelector("#register_form .captcha-container"); if (captchaContainer) { var refreshButton = document.querySelector( "#register_form .captcha-container #refresh_register_captcha_button" ); if (typeof window.initializeCaptcha === "function" && refreshButton) { window.initializeCaptcha({ button: refreshButton, image: captchaContainer.querySelector("#register_captcha_image"), }); refreshButton.click(); } } }, error: function () { showFormFallback(registerPopupContainer); }, }); } }); } if (window.location.search.startsWith("?register")) { $("#register_modal").modal(); $("#popup_modal").modal("hide"); } } whenJQuery(boot); })();