1(function (win, doc, $) { 2 'use strict'; 3 4 var KEYENCE = {}; 5 6 if ($ === undefined) { 7 return; 8 } 9 10 KEYENCE.setMultiStepForm = function () { 11 var multiStepForm = win.MultiStepForm; 12 13 if (multiStepForm) { 14 multiStepForm.init(); 15 } 16 }; 17 18 KEYENCE.MultiStepForm = (function () { 19 var $htmlBody = $('html, body'); 20 21 var LAUNCH_MODE = { 22 DEV: 0, 23 PUB: 1 24 }; 25 26 var EVENT_TYPE = { 27 CLICK_LEFT: 1 28 }; 29 30 var PANEL_INDEX = { 31 FIRST: 0, 32 SECOND: 1, 33 THIRD: 2, 34 FOURTH: 3 35 }; 36 37 var PANEL_NUM = { 38 NONE: 0, 39 FIRST: 1, 40 SECOND: 2, 41 THIRD: 3, 42 FOURTH: 4 43 }; 44 45 var isScrolling = false; 46 47 var Form = (function () { 48 var classNames = { 49 isHide: 'is-hide', 50 isCurrent: 'is-current', 51 errText: 'js-formErrText', 52 isError: 'is-error', 53 isInitialized: 'is-initialized', 54 errMessage: 'suz_errorMsg', 55 header: 'js-headerProduct', 56 checkCurrentScreen: 'js-checkCurrentFormScreen' 57 }; 58 59 var idNames = { 60 trigger: 'js-multiStepForm', 61 signinForm: 'js-multiStepForm-signin', 62 regForm: 'js-multiStepForm-registration', 63 formRoot: 'suz_registrationForm' 64 }; 65 66 var urls = { 67 validator: '/ajax/registrationAjax/validator/', 68 getEmailStatus: '/ajax/registrationAjax/getEmailStatus/', 69 getMobileNumberStatus: '/ajax/registrationAjax/getMobileNumberStatus/', 70 createVerificationCode: '/ajax/registrationAjax/createVerificationCode/', 71 actionPwdAssistance: '/user/passwordAssistance/', 72 }; 73 74 var names = { 75 passwordAssistanceActionForm: 'user_passwordAssistanceActionForm', 76 passwordAssistanceResetForm: 'user_passwordAssistance_resetPasswordActionForm', 77 withdrawActionForm: 'user_profile_withdrawActionForm', 78 reloginActionForm: 'user_reloginActionForm', 79 loginActionForm: 'user_loginActionForm', 80 unsubscribeConfirmActionForm: 'enews_unsubscribeConfirmActionForm', 81 inputConfirmActionForm: 'download_inputConfirmActionForm', 82 } 83 84 var selectors = { 85 token: 'input[name="org.apache.struts.taglib.html.TOKEN"]', 86 focusbleElements: 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable], summary, video, audio, [role="button"]', 87 focusbleInputElements: 'input:not([disabled]), select:not([disabled]), textarea:not([disabled])', 88 disabledInputElements: 'input:disabled, select:disabled, textarea:disabled', 89 form: 'form[name="' + names.passwordAssistanceActionForm + '"], ' + 90 'form[name="' + names.passwordAssistanceResetForm + '"], ' + 91 'form[name="' + names.withdrawActionForm + '"], ' + 92 'form[name="' + names.reloginActionForm + '"], ' + 93 'form[name="' + names.loginActionForm + '"], ' + 94 'form[name="' + names.unsubscribeConfirmActionForm + '"], ' + 95 'form[name="' + names.inputConfirmActionForm + '"]', 96 }; 97 98 var siteData = { 99 KA: { 100 id: 1, 101 lang: 'en-US' 102 }, 103 KBR: { 104 id: 14, 105 lang: 'pt-BR' 106 } , 107 KC: { 108 id: 21, 109 lang: 'zh-CN' 110 }, 111 KCN_en: { 112 id: 9, 113 lang: 'en-GB' 114 }, 115 KCN_fr: { 116 id: 9, 117 lang: 'fr-FR' 118 }, 119 KD: { 120 id: 3, 121 lang: 'de-DE' 122 }, 123 KF: { 124 id: 8, 125 lang: 'fr-FR' 126 }, 127 KI: { 128 id: 15, 129 lang: 'it-IT' 130 }, 131 KIB_cs: { 132 id: 10, 133 lang: 'cs-CZ' 134 }, 135 KIB_de: { 136 id: 10, 137 lang: 'de-DE' 138 }, 139 KIB_en: { 140 id: 10, 141 lang: 'en-GB' 142 }, 143 KIB_fr: { 144 id: 10, 145 lang: 'fr-FR' 146 }, 147 KIB_hu: { 148 id: 10, 149 lang: 'hu-HU' 150 }, 151 KIB_nl: { 152 id: 10, 153 lang: 'nl-NL' 154 }, 155 KIB_pl: { 156 id: 10, 157 lang: 'pl-PL' 158 }, 159 KID: { 160 id: 18, 161 lang: 'id-ID' 162 }, 163 KIN: { 164 id: 7, 165 lang: 'en-GB' 166 }, 167 KJ: { 168 id: 17, 169 lang: 'ja-JP' 170 }, 171 KK: { 172 id: 16, 173 lang: 'ko-KR' 174 }, 175 KM: { 176 id: 6, 177 lang: 'en-GB' 178 }, 179 KMX: { 180 id: 12, 181 lang: 'es-MX' 182 }, 183 KPH: { 184 id: 20, 185 lang: 'en-GB' 186 }, 187 KS: { 188 id: 4, 189 lang: 'en-GB' 190 }, 191 KT: { 192 id: 13, 193 lang: 'th-TH' 194 }, 195 KU: { 196 id: 5, 197 lang: 'en-GB' 198 }, 199 KVN: { 200 id: 19, 201 lang: 'vi-VN' 202 }, 203 KW: { 204 id: 11, 205 lang: 'zh-TW' 206 } 207 }; 208 209 var screenNames = { 210 initial: 'initial', 211 login: 'login', 212 OneClickLoginSendEmail: 'ocli-sendEmail',
213 hospitalitySignUp: 'osu', 214 hospitalitySignUpSendEmail: 'osu-sendEmail', 215 step1: 'register-step1', 216 flat: 'register-flat', 217 }; 218 219 var Main = { 220 needScrollAnimation: false, 221 needFocus: true, 222 scrollSpeed: 500, 223 idNames: idNames, 224 classNames: classNames, 225 urls: urls, 226 selectors: selectors, 227 $header: $('.' + classNames.header), 228 siteData: siteData, 229 screenNames: screenNames, 230 formWrapper: doc.querySelector('.' + classNames.checkCurrentScreen), 231 isFirstFocus: false, 232 }; 233 234 Main.mode = LAUNCH_MODE.DEV; 235 236 Main.init = function () { 237 if (doc.getElementById(Main.idNames.trigger)) { 238 if (win.shouldFormInitialFocus === undefined) { 239 win.shouldFormInitialFocus = true; 240 } 241 242 Main.readyPreventUnload(); 243 Main.addEventAll(); 244 Form.PreForm.init(); 245 Form.SignIn.init(); 246 Form.Register.init(); 247 Form.SendEmail.init(); 248 } 249 250 if (doc.getElementById(Main.idNames.formRoot) || doc.querySelector(Main.selectors.form)) { 251 Main.attachKeydownEvent(); 252 } 253 }; 254 255 Main.addEventAll = function () { 256 Main.addScroll(); 257 Main.attachSubmitEvent(); 258 Main.attachBeforeunloadEvent(); 259 }; 260 261 Main.addScroll = function () { 262 var timeID = null; 263 264 $(doc).on('scroll', function () { 265 isScrolling = true; 266 267 if (timeID !== null) { 268 win.clearTimeout(timeID); 269 } 270 271 timeID = win.setTimeout(function () { 272 isScrolling = false; 273 }, 200); 274 }); 275 }; 276 277 Main.attachSubmitEvent = function () { 278 $(doc).on('submit', 'form', this.onSubmitForm.bind(this)); 279 }; 280 281 Main.attachBeforeunloadEvent = function () { 282 win.addEventListener('beforeunload', this.onBeforeunload.bind(this)); 283 }; 284 285 Main.onSubmitForm = function () { 286 delete doc.getElementById(Main.idNames.trigger).dataset.preventUnload; 287 }; 288 289 Main.onBeforeunload = function (e) { 290 if (doc.getElementById(Main.idNames.trigger).dataset.preventUnload === 'true') { 291 e.preventDefault(); 292 e.returnValue = ''; 293 } 294 }; 295 296 Main.readyPreventUnload = function () { 297 var signinForm = doc.getElementById(Main.idNames.signinForm); 298 var regForm = doc.getElementById(Main.idNames.regForm); 299 300 if (!signinForm || !regForm) { 301 return; 302 } 303 304 if (!signinForm.classList.contains(Main.classNames.isHide) || 305 !regForm.classList.contains(Main.classNames.isHide)) { 306 doc.getElementById(Main.idNames.trigger).dataset.preventUnload = 'true'; 307 } 308 }; 309 310 Main.show = function ($element) { 311 var $currentPanel; 312 313 if (!$element || !$element.length) { 314 return; 315 } 316 317 $element.removeClass(this.classNames.isHide); 318 319 if ($element.attr('id') === Form.PreForm.idNames.root) { 320 Form.PreForm.$formCheckEmail.prop('disabled', false); 321 } 322 323 if ($element.attr('id') === Form.SignIn.idNames.signinForm) { 324 Main.clearInputError(Form.SignIn.names.loginPassword, false); 325 } 326 327 if ($element.attr('id') === Form.Register.idNames.regForm) { 328 $element.attr('data-index-current', 1); 329 Form.Register.$description.removeClass('is-hide'); 330 331 $currentPanel = $element.find('[data-panel-index="1"]'); 332 333 if ($currentPanel.attr('data-panel-displayed') === 'false') { 334 Form.Register.clearInputErrorAll($currentPanel); 335 $currentPanel.data('data-panel-displayed', true); 336 } 337 } 338 339 if (Main.needFocus) { 340 $element.on('animationend', function() { 341 Main.scrollToElement(idNames.trigger); 342 343 setTimeout(function () { 344 Form.focusFirstInputElement($element); 345 }, 0); 346 347 $element.off('animationend'); 348 }); 349 } else { 350 Main.scrollToElement(idNames.trigger); 351 } 352 }; 353 354 Main.focusFirstInputElement = function ($element) { 355 var $inputElement = this.getFocusbleFirstInputElement($element); 356 357 if ($inputElement.length) { 358 $inputElement.get(0).focus(); 359 } 360 }; 361 362 Main.hide = function ($element) { 363 if (!$element || !$element.length) { 364 return; 365 } 366 367 $element.addClass(this.classNames.isHide); 368 369 if ($element.attr('id') === Form.PreForm.idNames.root) { 370 Form.PreForm.$formCheckEmail.prop('disabled', true); 371 } 372 }; 373 374 Main.getEmailStatus = function (emailAddress) { 375 var deferred = new $.Deferred(); 376 var options; 377 var url; 378 379 if (typeof emailAddress !== 'string') { 380 return deferred.reject(); 381 } 382 383 url = win.suz_getCurrentDomain() + this.urls.getEmailStatus; 384 385 options = { 386 url: url, 387 data: { 388 emailAddress: emailAddress, 389 token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr('value') 390 }, 391 dataType: 'jsonp', 392 jsonp: 'callback', 393 scriptCharset: 'UTF-8' 394 } 395 396 $.ajax(options).done(function (data) { 397 deferred.resolve(data); 398 }).fail(function (jqXHR, textStatus, errorThrown) { 399 Main.asyncErrorHundler(jqXHR.status, textStatus); 400 deferred.reject(jqXHR, textStatus, errorThrown); 401 }); 402 403 return deferred.promise(); 404 }; 405 406 Main.asyncErrorHundler = function (status, err) { 407 if (status && status === 401) { 408 window.location.href = suz_getCurrentDomain() + "/error/tokenError.jsp"; 409 410 return false; 411 } 412 413 if (err) { 414 win.alert(err); 415 } 416 417 return true; 418 }; 419 420 Main.insertErrorText = function (nameAttr, text) { 421 var $formElement; 422 var $errText; 423 var $group; 424 425 if (typeof nameAttr === 'string') { 426 $formElement = $('input[name="' + nameAttr + '"'); 427 } 428 429 if (!$formElement || !$formElement.length) { 430 return; 431 } 432 433 if (Main.isEditProfileForm()) { 434 if (text === 'data-message-zipcode-format') { 435 $group = $formElement.closest('.m-form-layout__item'); 436 } else { 437 $group = $formElement.closest('.js-checkSMSCodeValid'); 438 } 439 } else { 440 $group = $formElement.closest('.m-form-layout__item'); 441 } 442 443 if ($group.length) {
444 $group.addClass(Main.classNames.isError); 445 446 $errText = $group.find('.' + Main.classNames.errText); 447 448 if (!$errText.length) { 449 return; 450 } 451 452 if (typeof $errText.get(0).getAttribute('style') === 'string') { 453 $errText.css('display', 'block'); 454 } else { 455 $errText.removeClass('is-hide'); 456 } 457 458 if ( 459 text === 'data-message-required' && 460 typeof $errText.attr('data-message-required') === 'string' 461 ) { 462 text = $errText.attr('data-message-required'); 463 } else if ( 464 text === 'data-message-mobile-number-format' && 465 typeof $errText.attr('data-message-required') === 'string' 466 ) { 467 text = $errText.attr('data-message-mobile-number-format'); 468 } else if ( 469 text === 'data-message-verification-code-format' && 470 typeof $errText.attr('data-message-required') === 'string' 471 ) { 472 text = $errText.attr('data-message-verification-code-format'); 473 } else if ( 474 text === 'data-message-email-address-format' && 475 typeof $errText.attr('data-message-required') === 'string' 476 ) { 477 text = $errText.attr('data-message-email-address-format'); 478 } else if ( 479 text === 'data-message-zipcode-format' 480 ) { 481 text = $errText.attr('data-message-zipcode-format'); 482 } 483 484 if (typeof text === 'string') { 485 $errText.text(text); 486 } 487 } 488 }; 489 490 Main.clearInputError = function (name, isSaveText) { 491 var $formElement; 492 var $errText; 493 var $group; 494 495 if (typeof name === 'string') { 496 $formElement = $('input[name="' + name + '"'); 497 } 498 499 if (!$formElement || !$formElement.length) { 500 return; 501 } 502 503 if (Main.isEditProfileForm()) { 504 $group = $formElement.closest('.js-checkSMSCodeValid'); 505 506 if (!$group.length) { 507 $group = $formElement.closest('.js-controlVerificationTargetValue'); 508 } 509 } else { 510 $group = $formElement.closest('.m-form-layout__item'); 511 } 512 513 if ($group.length) { 514 $group.removeClass(Main.classNames.isError); 515 516 $errText = $group.find('.' + Main.classNames.errText + ', .' + Main.classNames.errMessage); 517 518 if (!$errText.length) { 519 return; 520 } 521 522 if (typeof $errText.get(0).getAttribute('style') === 'string') { 523 $errText.css('display', 'none'); 524 } else { 525 $errText.addClass('is-hide'); 526 } 527 528 if (!isSaveText) { 529 $errText.text(''); 530 } 531 } 532 }; 533 534 Main.enableFocus = function ($elements) { 535 if ($elements.length) { 536 $elements.attr('tabindex', 0); 537 } 538 }; 539 540 Main.disableFocus = function ($elements) { 541 if ($elements.length) { 542 $elements.attr('tabindex', -1); 543 } 544 }; 545 546 Main.scrollToElement = function (id) { 547 var position = 0; 548 var adjust = 0; 549 var gap = 5; 550 551 if (typeof id !== 'string') { 552 return; 553 } 554 555 if (Main.$header.length) { 556 adjust = Main.$header.height(); 557 } 558
559 position = ($('#' + id).offset().top - gap) - adjust; 560 561 if (Main.needScrollAnimation) { 562 $htmlBody.animate({ 563 scrollTop: position 564 }, Main.scrollSpeed, 'ease'); 565 } else { 566 $htmlBody.animate({ 567 scrollTop: position 568 }, 1); 569 } 570 }; 571 572 Main.isShow = function ($element) { 573 if (($element && $element.length) && !$element.hasClass(classNames.isHide)) { 574 return true; 575 } 576 577 return false; 578 }; 579 580 Main.isReEnterPage = function (screenObject) { 581 if (!screenObject.$root.hasClass(classNames.isHide)) { 582 return true; 583 } 584 585 return false; 586 }; 587 588 Main.isInView = function (elem, isInside) { 589 var rect = elem.getBoundingClientRect(); 590 var isInView; 591 592 if (isInside) { 593 isInView = (0 < rect.top) && (rect.bottom < window.innerHeight); 594 } else { 595 isInView = (0 < rect.bottom) && (rect.top < window.innerHeight); 596 } 597 598 return isInView; 599 }; 600 601 Main.setInitialFocus = function ($page) { 602 var $firstInputElem; 603 604 if (!win.shouldFormInitialFocus || !$page || !$page.length || $page.hasClass(classNames.isHide)) { 605 return; 606 } 607 608 $firstInputElem = this.getFocusbleFirstInputElement($page); 609 610 if ($firstInputElem.length && this.isInView($firstInputElem.get(0), false)) { 611 Main.isFirstFocus = true; 612 Main.focusFirstInputElement($page); 613 } 614 }; 615 616 Main.getFocusbleFirstInputElement = function ($element) { 617 var $inputElem = $(null); 618 var $parents; 619 620 if (!$element || !$element.length) { 621 return $(null); 622 } 623 624 if ($element.attr('id') === Form.Register.idNames.root) { 625 $parents = $element.find('.' + Form.Register.classNames.formPanel).eq(0); 626 } else { 627 $parents = $element; 628 } 629 630 if ($parents && $parents.length) { 631 $inputElem = $parents.find(Main.selectors.focusbleInputElements).filter(':visible'); 632 } 633 634 return $inputElem; 635 }; 636 637 Main.focusFirstErrorItem = function ($argParentElement) { 638 var $parentElement; 639 var $errorItems; 640 var $formElem; 641 var availableValidator = win.KeyenceForm.AvailableValidator; 642 643 if ($argParentElement && $argParentElement.length) { 644 $parentElement = $argParentElement; 645 } else { 646 $parentElement = $('#' + idNames.trigger); 647 } 648 649 if ($parentElement.length) { 650 $errorItems = $parentElement.find('[id^="suz_div_"].is-error:visible', '[id^="suz_div_"].' + availableValidator.targetClass.status + ':visible'); 651 652 if ($errorItems.length) { 653 $formElem = $errorItems.eq(0).find(Form.selectors.focusbleInputElements); 654 } 655 656 if ($formElem && $formElem.length) { 657 if ($formElem.length === 2) { 658 if ( 659 $formElem.get(0).tagName.toLowerCase() === 'select' && 660 ($formElem.get(1).tagName.toLowerCase() === 'input' && 661 $formElem.get(1).getAttribute('type') !== 'hidden') 662 ) { 663 $formElem.get(1).focus(); 664 Main.scrollToErrorElement($formElem.get(1)); 665 } else { 666 $formElem.get(0).focus(); 667 Main.scrollToErrorElement($formElem.get(0)); 668 } 669 } else { 670 $formElem.get(0).focus(); 671 Main.scrollToErrorElement($formElem.get(0)); 672 } 673 } 674 } 675 }; 676 677 Main.getMobileNumberStatus = function (mobileCountryId, mobileNumber) { 678 var deferred = new $.Deferred(); 679 var options; 680 var url; 681 682 if (typeof mobileCountryId !== 'string' || typeof mobileNumber !== 'string') { 683 return; 684 } 685 686 url = win.suz_getCurrentDomain() + this.urls.getMobileNumberStatus; 687 688 options = { 689 url: url, 690 data: { 691 mobileCountryId: mobileCountryId, 692 mobileNumber: mobileNumber, 693 token: $("input[name='org.apache.struts.taglib.html.TOKEN']").attr('value') 694 }, 695 dataType: 'jsonp', 696 jsonp: 'callback', 697 scriptCharset: 'UTF-8' 698 }; 699 700 $.ajax(options).done(function (data) { 701 deferred.resolve(data); 702 }).fail(function (jqXHR, textStatus, errorThrown) { 703 Main.asyncErrorHundler(jqXHR.status, textStatus); 704 deferred.reject(jqXHR, textStatus, errorThrown); 705 }); 706 707 return deferred.promise(); 708 }; 709 710 Main.createVerificationCode = function (mobileNumber,
710countyCode) { 711 var deferred = new $.Deferred(); 712 var options; 713 var url; 714 715 if (typeof mobileNumber !== 'string' || typeof countyCode !== 'string') { 716 return; 717 } 718 719 url = win.suz_getCurrentDomain() + this.urls.getMobileNumberStatus; 720 721 options = { 722 url: url, 723 data: { 724 mobileCountryId: mobileCountryId, 725 mobileNumber: mobileNumber 726 }, 727 dataType: 'jsonp', 728 jsonp: 'callback', 729 scriptCharset: 'UTF-8' 730 }; 731 732 $.ajax(options).done(function (data) { 733 deferred.resolve(data); 734 }).fail(function (jqXHR, textStatus, errorThrown) { 735 Main.asyncErrorHundler(jqXHR.status, textStatus); 736 deferred.reject(jqXHR, textStatus, errorThrown); 737 }); 738 739 return deferred.promise(); 740 }; 741 742 Main.isEditProfileForm = function () { 743 var form = doc.querySelector('form[name="user_profileActionForm"]'); 744 745 return form !== null; 746 }; 747 748 Main.attachKeydownEvent = function () { 749 var targets = doc.querySelectorAll('.js-preventSubmitWithEnter'); 750 751 if (targets.length) { 752 targets.forEach(function (target) { 753 target.addEventListener('keydown', Main.preventSubmit, false); 754 }); 755 } 756 }; 757 758 Main.preventSubmit = function (e) { 759 if (e.key === 'Enter') { 760 e.preventDefault(); 761 } 762 }; 763 764 Main.scrollToErrorElement = function (target) { 765 if (!MultiStepForm.isInView(target, false)) { 766 target.scrollIntoView({ 767 behavior: 'smooth', 768 block: 'center' 769 }); 770 } 771 }; 772 773 Main.changeCurrentScreenName = function (screenName, stepNumber) { 774 if (!this.formWrapper) { 775 return; 776 } 777 778 if (screenName === 'step' && stepNumber) { 779 this.formWrapper.dataset.currentScreenName = 'register-step' + stepNumber; 780 } else if (screenName) { 781 this.formWrapper.dataset.currentScreenName = screenName; 782 } 783 }; 784 785 return Main; 786 }()); 787 788 /** 789 * Signin or Registration 790 */ 791 Form.PreForm = (function () { 792 var idNames = { 793 btnConitnue: 'js-form-btnCheckRegistered', 794 root: 'js-multiStepForm-signinOrRegister', 795 showEmailForm: 'js-showEmailForm', 796 multiStepForm: 'js-multiStepForm', 797 }; 798 799 var classNames = { 800 formFilterGeneral: 'js-formFilterGeneral', 801 formFilterGeneralTrigger: 'js-formFilterGeneral-trigger', 802 isFilterEmail: 'is-filter-email', 803 isFilterMobileNumber: 'is-filter-mobileNumber', 804 isFilterDefault: 'is-filter-default', 805 }; 806 807 var PreForm = { 808 idNames: idNames, 809 $root: $('#' + idNames.root), 810 $btnContinue: $('#' + idNames.btnConitnue), 811 $formCheckEmail: $('input[name="checkRegistered"]'), 812 $formCheckMobileNumber: $('input[name="checkMobileNumber"]'), 813 $formFilterGeneral: $('.' + classNames.formFilterGeneral), 814 $formFilterGeneralTriggers: $('.' + classNames.formFilterGeneralTrigger), 815 $buttonShowEmailForm: $('#' + idNames.showEmailForm), 816 $multiStepFormTrigger: $('#' + idNames.multiStepForm), 817 $passwordAssistanceFormTrigger: $('form[name="user_passwordAssistanceActionForm"]'), 818 }; 819 820 var signInMessageEvent = { 821 handleEvent: null, 822 }; 823 824 PreForm.init = function () { 825 if (this.$root.length) { 826 this.$root.find('svg').attr('focusable', false); 827 this.addEventAll(); 828 Form.setInitialFocus(this.$root); 829 } 830 }; 831 832 PreForm.addEventAll = function () { 833 this.clickContinueButton(); 834 this.attachEmailFormKeydownEvent(); 835 this.onMessageAction(); 836 }; 837 838 PreForm.clickContinueButton = function () { 839 PreForm.$btnContinue.on('click', this.onClickContinue.bind(this)); 840 }; 841 842 PreForm.onClickContinue = function (e) { 843 var BlankFieldValidator = KeyenceForm.BlankFieldValidator; 844 var MobileNumberValidator = KeyenceForm.MobileNumberValidator; 845 var PatternValidator = KeyenceForm.PatternMatchValidator; 846 var AvailableValidator = KeyenceForm.AvailableValidator; 847 var FilledFieldValidator = KeyenceForm.filledFieldValidator; 848 var ControlErrorDisplay = KeyenceForm.ControlErrorDisplay; 849 var formType = KEYENCE.Form.FormFilter.General.getFormType() 850 var formInfo = PreForm.getFormInfo(); 851 var FormFilter = KEYENCE.Form.FormFilter; 852 var targetInput = doc.querySelector('input[name="' + formInfo.name + '"]'); 853 var multiStepFormElem = doc.getElementById(PreForm.idNames.multiStepForm); 854 var formEnquete = win.KeyenceEnquete.form; 855 856 if (e.type === 'click' 857 && win.AnalyticsViews 858 && PreForm.checkMessageTargetForm()) { 859 return; 860 } 861 862 if (e.type === 'message' 863 && e.data !== AnalyticsViews.Utility.messageNames.nextForm) { 864 return; 865 } 866 867 if (targetInput && win.kpi_siteSettings.siteId === Form.siteData.KA.id) { 868 if (targetInput.classList.contains('js-check-blank') && !BlankFieldValidator.isBlank(targetInput)) { 869 AvailableValidator.updatePreFormBlockStatus(formType, FormFilter, PreForm, e); 870 871 if (AvailableValidator.config.isPreFormContinueBlocked) { 872 return; 873 } 874 } 875 } 876 877 // for beforeunload event 878 if (multiStepFormElem) { 879 multiStepFormElem.dataset.preventUnload = 'true'; 880 } 881 882 BlankFieldValidator.config.isClickedContinueButton = true; 883 884 if (targetInput) { 885 if (targetInput.classList.contains('js-check-blank') && BlankFieldValidator.isBlank(targetInput)) { 886 MultiStepForm.insertErrorText(formInfo.name, 'data-message-required'); 887 targetInput.classList.add(BlankFieldValidator.classNames.status); 888 targetInput.classList.remove(MobileNumberValidator.classNames.status); 889 targetInput.classList.remove(PatternValidator.classNames.status); 890 targetInput.focus(); 891 892 if (formEnquete._validateEnqueteWithProceedButton()) { 893 MultiStepForm.scrollToErrorElement(targetInput); 894 } 895 896 ControlErrorDisplay.setTriggerClickedData(PreForm.$btnContinue.get(0)); 897 898 return; 899 } else { 900 MultiStepForm.clearInputError(formInfo.name, true); 901 targetInput.classList.remove(BlankFieldValidator.classNames.status); 902 } 903 } 904 905 if (formType === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 906 if (PreForm.$formCheckMobileNumber.hasClass('js-checkMobileNumberFormat')) { 907 KeyenceForm.MobileNumberValidator.checkFormat(formInfo.countryCode, formInfo.mobileNumber ).done(function (status) { 908 if (status.message) { 909 Form.insertErrorText(formInfo.name, status.message); 910 targetInput.focus(); 911 if (formEnquete._validateEnqueteWithProceedButton()) { 912 MultiStepForm.scrollToErrorElement(targetInput); 913 } 914 } else { 915 Form.getMobileNumberStatus(formInfo.countryCode, formInfo.mobileNumber).done(function (status) { 916 if (status.message) { 917 Form.insertErrorText(formInfo.name, status.message); 918 targetInput.focus(); 919 if (formEnquete._validateEnqueteWithProceedButton()) { 920 MultiStepForm.scrollToErrorElement(targetInput); 921 } 922 } else { 923 if (!formEnquete._validateEnqueteWithProceedButton()) { 924 return; 925 } 926 927 PreForm.showNextForm(status.isRegistered, formInfo, PreForm.isAutoSignupUser(status)); 928 } 929 }); 930 } 931 }); 932 } else { 933 Form.getMobileNumberStatus(formInfo.countryCode, formInfo.mobileNumber).done(function (status) { 934 if (status.message) { 935 Form.insertErrorText(formInfo.name, status.message); 936 targetInput.focus(); 937 if (formEnquete._validateEnqueteWithProceedButton()) { 938 MultiStepForm.scrollToErrorElement(targetInput); 939 } 940 } else { 941 if (!formEnquete._validateEnqueteWithProceedButton()) { 942 return; 943 } 944 945 PreForm.showNextForm(status.isRegistered, formInfo, PreForm.isAutoSignupUser(status)); 946 } 947 }); 948 } 949 } else { 950 Form.getEmailStatus(formInfo.value).done(function (status) { 951 // done 952 if (status.message) { 953 Form.insertErrorText(formInfo.name, status.message); 954 targetInput.focus(); 955 if (formEnquete._validateEnqueteWithProceedButton()) { 956 MultiStepForm.scrollToErrorElement(targetInput); 957 } 958 959 ControlErrorDisplay.setTriggerClickedData(PreForm.$btnContinue.get(0)); 960 } else { 961 if (targetInput && !ControlErrorDisplay.isTriggerClicked(targetInput)) { 962 FilledFieldValidator.changeFieldStatus($(targetInput), true); 963 } 964 965 if (!formEnquete._validateEnqueteWithProceedButton()) { 966 ControlErrorDisplay.setTriggerClickedData(PreForm.$btnContinue.get(0)); 967 968 return; 969 } 970 971 PreForm.showNextForm(status.isRegistered, formInfo, PreForm.isEmailAutoSignupUser(status)); 972 ControlErrorDisplay.setTriggerClickedData(PreForm.$btnContinue.get(0)); 973 } 974 }); 975 } 976 }; 977 978 PreForm.showNextForm = function (isRegistered, formInfo, isAutoSignup) { 979 var formType = KEYENCE.Form.FormFilter.General.getFormType(); 980 var $email; 981 var FormFilter = KEYENCE.Form.FormFilter; 982 var countryCode = ''; 983 var mobileNumber = ''; 984 var currentScreen = ''; 985 986 if (typeof isRegistered !== 'boolean' || !formInfo) { 987 return; 988 } 989 990 if (isRegistered || isAutoSignup) { 991 if (formType === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 992 Form.SignIn.$loginMobileNumber.val(formInfo.mobileNumber); 993 document.getElementById('loginCountryNumber').value = formInfo.mobileNumberCode; 994 995 FormFilter.SignIn.changeAutoSignUp(isAutoSignup, formType); 996 } else { 997 if ((isRegistered && isAutoSignup) || (isRegistered && !isAutoSignup)) { 998 Form.SignIn.$loginUserName.val(formInfo.value); 999 Form.SignIn.$loginPassword.removeAttr('disabled'); 1000 currentScreen = 'login'; 1001 } else { 1002 Form.SendEmail.enterEmailAddress(); 1003 FormFilter.SignIn.changeAutoSignUp(isAutoSignup, formType); 1004 1005 if (Form.SignIn.$root.hasClass(FormFilter.SignIn.classNames.isFilterAutoSignUp
1005)) { 1006 currentScreen = 'hospitalitySignUp'; 1007 } else { 1008 currentScreen = 'login'; 1009 } 1010 } 1011 } 1012 1013 Form.show(Form.SignIn.$root); 1014 Form.hide(Form.PreForm.$root); 1015 1016 Form.changeCurrentScreenName(Form.screenNames[currentScreen]); 1017 Form.clearInputError(formInfo.name, false); 1018 1019 countryCode = $('#checkCountryNumber').find('option:selected').attr('data-code'); 1020 mobileNumber = $('#checkMobileNumber').val(); 1021 1022 $('#loginFullMobileNumber').val(countryCode + mobileNumber); 1023 } else { 1024 if (formType === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 1025 $('#' + Form.Register.idNames.mobileNumber).val(formInfo.mobileNumber); 1026 $('#suz_mobileCountryNumber').val(formInfo.mobileNumberCode); 1027 } else { 1028 $email = $('#' + Form.Register.idNames.email); 1029 1030 $email.val(formInfo.value); 1031 win.suz_callRegValidator($email, $email.val()); 1032 } 1033 1034 Form.Register.showPanelByIndex(0); 1035 1036 Form.show(Form.Register.$root); 1037 Form.hide(Form.PreForm.$root); 1038 1039 Form.changeCurrentScreenName(Form.screenNames.step1); 1040 Form.clearInputError(formInfo.name, false); 1041 } 1042 }; 1043 1044 PreForm.onMessageAction = function () { 1045 signInMessageEvent.handleEvent = PreForm.onClickContinue; 1046 1047 win.addEventListener('message', signInMessageEvent, false); 1048 }; 1049 1050 PreForm.attachEmailFormKeydownEvent = function () { 1051 PreForm.$formCheckEmail.on('keydown.enterKeySubmit', PreForm.onKeydownEmailForm); 1052 1053 if (PreForm.$formCheckMobileNumber.length) { 1054 PreForm.$formCheckMobileNumber.on('keydown.enterKeySubmit', PreForm.onKeydownEmailForm); 1055 } 1056 }; 1057 1058 PreForm.onKeydownEmailForm = function (event) { 1059 var AvailableValidator = win.KeyenceForm.AvailableValidator; 1060 var PatternMatchValidator = win.KeyenceForm.PatternMatchValidator; 1061 var $field = null; 1062 1063 if (event.key === 'Enter') { 1064 if (win.kpi_siteSettings.siteId === Form.siteData.KA.id) { 1065 $field = PreForm.$root.find('.' + AvailableValidator.targetClass.emailAddress + ':visible, .' + AvailableValidator.targetClass.mobileNumber + ':visible'); 1066 1067 if ($field.length === 1) { 1068 AvailableValidator.runValidate($(this).attr('name'), true).always(function (field) { 1069 PatternMatchValidator.updateFieldStatus(field); 1070 AvailableValidator.changeDisplayNoteText(field.name); 1071 PreForm.$btnContinue.get(0).click(); 1072 }); 1073 } else { 1074 PreForm.$btnContinue.get(0).click(); 1075 } 1076 } else { 1077 PreForm.$btnContinue.get(0).click(); 1078 } 1079 1080 return false; 1081 } 1082 }; 1083 1084 PreForm.getFormInfo = function () { 1085 var FormFilter = KEYENCE.Form.FormFilter; 1086 var formInfo = { 1087 name: PreForm.$formCheckEmail.attr('name'), 1088 value: PreForm.$formCheckEmail.val() 1089 }; 1090 1091 if (FormFilter.General.getFormType() === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 1092 formInfo = { 1093 name: $('#checkMobileNumber').attr('name'), 1094 mobileNumber: $('#checkMobileNumber').val(), 1095 countryCode: $('#checkCountryNumber').val(), 1096 mobileNumberCode: $('#checkCountryNumber').find('option:selected').attr('data-code'), 1097 }; 1098 } 1099 1100 return formInfo; 1101 }; 1102 1103 PreForm.getMobileCountryInfo = function () { 1104 var info = {}; 1105 var $select = $('#checkCountryNumber'); 1106 var $option; 1107 1108 if (!$select.length) { 1109 return info; 1110 } 1111 1112 $option = $select.find('option:selected'); 1113 1114 info.id = $select.val(); 1115 info.code = $option.attr('data-code'); 1116 info.text = $option.text(); 1117 1118 return info; 1119 }; 1120 1121 PreForm.isAutoSignupUser = function (accountStatus) { 1122 if (accountStatus && (accountStatus.isAutoSignup && doc.getElementById(Form.SignIn.idNames.asuLoginButton))) { 1123 return true; 1124 } 1125 1126 return false; 1127 }; 1128 1129 PreForm.isEmailAutoSignupUser = function (accountStatus) { 1130 if (accountStatus && (accountStatus.isAutoSignup && doc.getElementById(Form.SignIn.idNames.asuSendMailButton))) { 1131 return true; 1132 } 1133 1134 return false; 1135 }; 1136 1137 PreForm.changeDisplayForm = function (isRegistered, formInfo, isAutoSignup) { 1138 if (typeof isRegistered !== 'boolean' || !formInfo) { 1139 return; 1140 } 1141 1142 if (isRegistered || isAutoSignup) { 1143 Form.show(Form.SignIn.$root); 1144 Form.hide(Form.PreForm.$root); 1145 } else { 1146 Form.show(Form.Register.$root); 1147 Form.hide(Form.PreForm.$root); 1148 } 1149 }; 1150 1151 PreForm.checkMessageTargetForm = function () { 1152 var isTargetForm = false; 1153 1154 if (PreForm.$multiStepFormTrigger.length || PreForm.$passwordAssistanceFormTrigger.length) { 1155 isTargetForm = true; 1156 } else { 1157 isTargetForm = false; 1158 } 1159 1160 return isTargetForm; 1161 }; 1162 1163 return PreForm; 1164 }()); 1165 1166 Form.SignIn = (function () { 1167 var idNames = { 1168 signinForm: 'js-multiStepForm-signin', 1169 btnBack: 'js-signinForm-btnBackToEmail',
1170 btnBackToMobileNumber: 'js-signinForm-btnBackToMobile', 1171 loginUserName: 'loginUserName', 1172 loginMobileNumber: 'loginMobileNumber', 1173 loginPassword: 'loginPassword', 1174 loginVerificationCode: 'loginVerificationCode', 1175 asuLoginButton: 'js-form-autoSignupSwitch', 1176 registerLoginPassword: 'suz_registerLoginPassword', 1177 btnCheckSendEmail: 'js-form-btnCheckSendMail', 1178 asuSendMailButton: 'js-form-btnCheckSendAutoSignupMail', 1179 btnForwardToRegister: 'js-signinForm-btnForwardToRegister', 1180 }; 1181 1182 var names = { 1183 loginActionForm: $('#' + idNames.signinForm).parent().attr('name'), 1184 loginPassword: 'loginPassword' 1185 }; 1186 1187 var SignIn = { 1188 idNames: idNames, 1189 names: names, 1190 $root: $('#' + idNames.signinForm), 1191 $loginUserName: $('#' + idNames.loginUserName), 1192 $btnBackToEmail: $('#' + idNames.btnBack), 1193 $btnBackToMobile: $('#' + idNames.btnBackToMobileNumber), 1194 $loginActionForm: $('form[name="' + names.loginActionForm + '"]'), 1195 $loginMobileNumber: $('#' + idNames.loginMobileNumber), 1196 $loginPassword: $('#' + idNames.loginPassword), 1197 $loginVerificationCode: $('#' + idNames.loginVerificationCode), 1198 $registerLoginPassword: $('#' + idNames.registerLoginPassword), 1199 $btnCheckSendEmail: $('#' + idNames.btnCheckSendEmail), 1200 $asuSendMailButton: $('#' + idNames.asuSendMailButton), 1201 $btnForwardToRegister: $('#' + idNames.btnForwardToRegister), 1202 }; 1203 1204 var backMessageEvent = { 1205 handleEvent: null, 1206 }; 1207 1208 var forwardMessageEvent = { 1209 handleEvent: null, 1210 }; 1211 1212 SignIn.init = function () { 1213 if (this.$root.length) { 1214 this.initAttributes(); 1215 this.addEventAll(); 1216 this.checkSendEmailButton(); 1217 1218 if (Form.isReEnterPage(this) && !win.KeyenceEnquete.hasError()) { 1219 Form.setInitialFocus(this.$root); 1220 Form.scrollToElement(idNames.signinForm); 1221 } 1222 } 1223 }; 1224 1225 SignIn.initAttributes = function () { 1226 this.$root.find('svg').attr('focusable', false); 1227 this.$loginUserName.prop('disabled', true); 1228 }; 1229 1230 SignIn.addEventAll = function () { 1231 this.clickBackButton(); 1232 this.clickForwardButton(); 1233 this.submitSignin(); 1234 this.attachKeydownFormInputEvent(); 1235 this.onMessageAction(); 1236 }; 1237 1238 SignIn.clickBackButton = function () { 1239 this.$btnBackToEmail.on('click', this.onclickBackButton.bind(this)); 1240 1241 if (this.$btnBackToMobile.length) { 1242 this.$btnBackToMobile.on('click', this.onclickBackButton.bind(this)); 1243 } 1244 }; 1245 1246 SignIn.clickForwardButton = function () { 1247 if (this.$btnForwardToRegister.length) { 1248 this.$btnForwardToRegister.on('click', this.onclickForwardButton.bind(this)); 1249 } 1250 }; 1251 1252 SignIn.onclickBackButton = function (event) { 1253 var AvailableValidator = win.KeyenceForm.AvailableValidator; 1254 1255 event.preventDefault(); 1256 1257 if (!win.AnalyticsViews || !Form.PreForm.checkMessageTargetForm()) { 1258 AvailableValidator.hideNoteText(Form.PreForm.$root); 1259 1260 Form.show(Form.PreForm.$root); 1261 Form.hide(this.$root); 1262 1263 KEYENCE.Form.FormFilter.SignIn.clickLoginPasswordTrigger(); 1264 } 1265 }; 1266 1267 SignIn.onclickForwardButton = function (event) { 1268 var $email = null; 1269 var formInfo = null; 1270 1271 event.preventDefault(); 1272 1273 if (!win.AnalyticsViews || !Form.PreForm.checkMessageTargetForm()) { 1274 $email = $('#' + Form.Register.idNames.email); 1275 formInfo = Form.PreForm.getFormInfo(); 1276 1277 if (!formInfo.value || !$email.length) { 1278 return; 1279 } 1280 1281 $email.val(formInfo.value); 1282 win.suz_callRegValidator($email, $email.val()); 1283 1284 Form.Register.showPanelByIndex(0); 1285 1286 if (Form.SignIn.$root.hasClass(KEYENCE.Form.FormFilter.SignIn.classNames.isFilterAutoSignUp
1286)) { 1287 Form.SignIn.$root.addClass(KEYENCE.Form.FormFilter.SignIn.classNames.isFilterPassword); 1288 Form.SignIn.$root.removeClass(KEYENCE.Form.FormFilter.SignIn.classNames.isFilterAutoSignUp); 1289 } 1290 1291 Form.show(Form.Register.$root); 1292 Form.hide(Form.SignIn.$root); 1293 1294 Form.clearInputError(Form.SignIn.$loginUserName.attr('name'), false); 1295 } 1296 }; 1297 1298 SignIn.onMessageAction = function () { 1299 backMessageEvent.handleEvent = SignIn.changeBackDisplayForm; 1300 forwardMessageEvent.handleEvent = SignIn.changeForwardDisplayForm 1301 1302 win.addEventListener('message', backMessageEvent, false); 1303 win.addEventListener('message', forwardMessageEvent, false); 1304 }; 1305 1306 SignIn.checkSendEmailButton = function () { 1307 if (this.$btnCheckSendEmail.length) { 1308 Form.SendEmail.attachClickSendEmailButton(this.$btnCheckSendEmail); 1309 } 1310 1311 if (this.$asuSendMailButton.length) { 1312 Form.SendEmail.attachClickSendEmailButton(this.$asuSendMailButton); 1313 } 1314 }; 1315 1316 SignIn.submitSignin = function () { 1317 if (this.$loginActionForm.length) { 1318 this.$loginActionForm.on('submit', this.onSubmitLoginAction.bind(this)); 1319 } 1320 }; 1321 1322 SignIn.onSubmitLoginAction = function () { 1323 SignIn.$loginUserName.prop('disabled', false); 1324 }; 1325 1326 SignIn.validateForm = function (trigger) { 1327 var BlankFieldValidator = KEYENCE.Form.BlankFieldValidator; 1328 var ControlErrorDisplay = KEYENCE.Form.ControlErrorDisplay 1329 var FormFilter = KEYENCE.Form.FormFilter; 1330 var formTypeGeneral = FormFilter.General.getFormType(); 1331 var formTypeSignIn = FormFilter.SignIn.getFormType(); 1332 var inputBlankCheckTargetList = $.makeArray(SignIn.$root.find('.js-check-blank:visible')); 1333 var controlErrorDisplayTrigger = null; 1334 1335 controlErrorDisplayTrigger = trigger ? trigger : ControlErrorDisplay.browserValidatorTarget; 1336 ControlErrorDisplay.setTriggerClickedData(controlErrorDisplayTrigger); 1337 1338 if (formTypeGeneral === FormFilter.General.FORM_TYPE.EMAIL) { 1339 if (inputBlankCheckTargetList.length && BlankFieldValidator.validateFieldAll(inputBlankCheckTargetList)) { 1340 SignIn.$loginPassword.focus(); 1341 Form.scrollToErrorElement(SignIn.$loginPassword.get(0)); 1342 1343 return false; 1344 } 1345 1346 Form.clearInputError(Form.SignIn.$loginPassword.attr('name'), true); 1347 FormFilter.General.enableFields('email', true); 1348 } else if (formTypeGeneral === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 1349 if (formTypeSignIn === FormFilter.SignIn.FORM_TYPE.PASSWORD) { 1350 if (inputBlankCheckTargetList.length && BlankFieldValidator.validateFieldAll(inputBlankCheckTargetList)) { 1351 SignIn.$loginPassword.focus(); 1352 Form.scrollToErrorElement(SignIn.$loginPassword.get(0)); 1353 1354 return false; 1355 } 1356 1357 Form.clearInputError(Form.SignIn.$loginPassword.attr('name'), true); 1358 FormFilter.SignIn.enableFields('password', true); 1359 } else if (formTypeSignIn === FormFilter.SignIn.FORM_TYPE.SMS_CODE) { 1360 if (inputBlankCheckTargetList.length && BlankFieldValidator.validateFieldAll(inputBlankCheckTargetList)) { 1361 SignIn.$loginVerificationCode.focus(); 1362 Form.scrollToErrorElement(SignIn.$loginVerificationCode.get(0)); 1363 1364 return false; 1365 } 1366 1367 Form.clearInputError(Form.SignIn.$loginVerificationCode.attr('name'), true); 1368 FormFilter.SignIn.enableFields('smscode', true); 1369 } else if (formTypeSignIn === FormFilter.SignIn.FORM_TYPE.ASU) { 1370 if (inputBlankCheckTargetList.length && BlankFieldValidator.validateFieldAll(inputBlankCheckTargetList)) { 1371 if (BlankFieldValidator.isBlank(SignIn.$loginVerificationCode.get(0))) { 1372 SignIn.$loginVerificationCode.focus(); 1373 Form.scrollToErrorElement(SignIn.$loginVerificationCode.get(0)); 1374 } else { 1375 SignIn.$registerLoginPassword.focus(); 1376 Form.scrollToErrorElement(SignIn.$registerLoginPassword.get(0)); 1377 } 1378 1379 return false; 1380 } 1381 1382 Form.clearInputError(Form.SignIn.$loginVerificationCode.attr('name'), true); 1383 Form.clearInputError(Form.SignIn.$registerLoginPassword.attr('name'), true); 1384 FormFilter.SignIn.enableFields('asu', true); 1385 } 1386 } else if (formTypeGeneral === FormFilter.General.FORM_TYPE.DEFAULT) { 1387 if (inputBlankCheckTargetList.length && BlankFieldValidator.validateFieldAll(inputBlankCheckTargetList)) { 1388 SignIn.$loginPassword.focus(); 1389 Form.scrollToErrorElement(SignIn.$loginPassword.get(0)); 1390 1391 return false; 1392 } 1393 1394 Form.SignIn.$loginUserName.prop('disabled', false); 1395 } 1396 1397 return true; 1398 }; 1399 1400 SignIn.attachKeydownFormInputEvent = function () { 1401 this.$root.on('keydown.enterKeyAutoSignUpSubmit', 'input, textarea', this.onKeydownFormInput.bind(this)); 1402 }; 1403 1404 SignIn.onKeydownFormInput = function (event) { 1405 if (event.key !== 'Enter') { 1406 return; 1407 } 1408 1409 if (this.$root.get(0).classList.contains(KEYENCE.Form.FormFilter.SignIn.classNames.isFilterAutoSignUp
1409)) { 1410 $('#' + this.idNames.asuLoginButton).click(); 1411 1412 return false; 1413 } 1414 }; 1415 1416 SignIn.changeBackDisplayForm = function (e) { 1417 var availableValidator = win.KeyenceForm.AvailableValidator; 1418 1419 if (e.data === AnalyticsViews.Utility.messageNames.backLink) { 1420 KEYENCE.Form.FormFilter.SignIn.clickLoginPasswordTrigger(); 1421 availableValidator.hideNoteText(Form.PreForm.$root); 1422 1423 Form.show(Form.PreForm.$root); 1424 Form.hide(win.MultiStepForm.SignIn.$root); 1425 1426 Form.changeCurrentScreenName(Form.screenNames.initial); 1427 } 1428 }; 1429 1430 SignIn.changeForwardDisplayForm = function (e) { 1431 var $email = null; 1432 var formInfo = null; 1433 1434 if (e.data === AnalyticsViews.Utility.messageNames.forwardLink) { 1435 $email = $('#' + Form.Register.idNames.email); 1436 formInfo = Form.PreForm.getFormInfo(); 1437 1438 if (!formInfo.value || !$email.length) { 1439 return; 1440 } 1441 1442 $email.val(formInfo.value); 1443 win.suz_callRegValidator($email, $email.val()); 1444 1445 Form.Register.showPanelByIndex(0); 1446 1447 if (Form.SignIn.$root.hasClass(KEYENCE.Form.FormFilter.SignIn.classNames.isFilterAutoSignUp)) { 1448 Form.SignIn.$root.addClass(KEYENCE.Form.FormFilter.SignIn.classNames.isFilterPassword); 1449 Form.SignIn.$root.removeClass(KEYENCE.Form.FormFilter.SignIn.classNames.isFilterAutoSignUp); 1450 } 1451 1452 Form.show(Form.Register.$root); 1453 Form.hide(Form.SignIn.$root); 1454 1455 Form.changeCurrentScreenName(Form.screenNames.step1); 1456 Form.clearInputError(Form.SignIn.$loginUserName.attr('name'), false); 1457 } 1458 }; 1459 1460 return SignIn; 1461 }()); 1462 1463 /** 1464 * Create Register Form 1465 */ 1466 Form.Register = (function () { 1467 var canSubmit = false; 1468 1469 var idNames = { 1470 btnSubmit: 'js-regForm-btnSubmit', 1471 regForm: 'js-multiStepForm-registration', 1472 ageeBox: 'as_agreeBoxCheked', 1473 btnBackLink: 'js-regForm-btnBackToEmail', 1474 formPanelParent: 'js-multiStep-targetParent', 1475 formRoot: 'suz_registrationForm', 1476 email: 'suz_emailAddress', 1477 description: 'js-regForm-description', 1478 progressBarRoot: 'js-formProgress-trigger', 1479 progressTotalNum: 'js-formProgress-totalNum', 1480 progressCurrentNum: 'js-formProgress-currentNum', 1481 progressBarTrigger: 'js-formProgress-triggerBar', 1482 btnSearchAddress: 'js-regForm-btnSearchAddress', 1483 btnBackToMobileLink: 'js-regForm-btnBackToMobile', 1484 mobileNumber: 'suz_mobileNumber', 1485 formStepCurrentNum: 'js-formStep-currentNum', 1486 country: 'suz_countryID', 1487 stateWrapper: 'suz_div_stateID', 1488 state: 'suz_stateID', 1489 city: 'suz_cityName', 1490 addressWrapper: 'suz_div_address1', 1491 address1: 'suz_address1', 1492 address2Wrapper: 'suz_div_address2', 1493 zipCodeWrapper: 'suz_div_zipCode', 1494 zipCode: 'suz_zipCode', 1495 suzRegArea: 'suz_regArea' 1496 }; 1497 1498 var classNames = { 1499 btnSubmit: 'js-regForm-btnSubmit', 1500 btnNext: 'js-regForm-btnNext', 1501 formPanel: 'js-multiStep-target', 1502 required: 'js-form-required', 1503 isRequired: 'is-required', 1504 btnPrevious: 'js-regForm-btnPrevious', 1505 progressBar: 'js-formProgress-triggerBar',
1506 progressBarStepTarget: 'js-formProgress-stepTarget', 1507 isRegError: 'is-register-error', 1508 isRegFlat: 'is-register-flat', 1509 isHide: 'is-hide', 1510 isAutoCompleteElementHide: 'is-autoCompleteElement-hide', 1511 isError: 'is-error', 1512 inputWrapper: 'm-form-layout__item', 1513 errorText: 'm-form-text__item' 1514 }; 1515 1516 var names = { 1517 privacyChk: 'privacyChk' 1518 }; 1519 1520 var Register = { 1521 idNames: idNames, 1522 classNames: classNames, 1523 names: names, 1524 $root: $('#' + idNames.regForm), 1525 $formRoot: $('#' + idNames.formRoot), 1526 $description: $('#' + idNames.description), 1527 $email: $('#' + idNames.email), 1528 $agreeBox: $('#' + idNames.ageeBox), 1529 $progressBarRoot: $('#' + idNames.progressBarRoot), 1530 $progressBar: $('#' + idNames.progressBar), 1531 $progressBarTrigger: $('#' + idNames.progressBarTrigger), 1532 $progressTotalNum: $('#' + idNames.progressTotalNum), 1533 $progressCurrentNum: $('#' + idNames.progressCurrentNum), 1534 $btnSearchAddress: $('#' + idNames.btnSearchAddress), 1535 isErrorPage: Form.isShow($('#' + idNames.regForm)), 1536 $formStepCurrentNum: $('#' + idNames.formStepCurrentNum), 1537 isAutoCompleteElementsHide: false 1538 }; 1539 1540 Register.init = function () { 1541 if (!this.$root.length) { 1542 return; 1543 } 1544 1545 if (this.isRegError() || this.isRegFlat()) { 1546 this.initAttributes(); 1547 this.clickBackLink(); 1548 this.clickPrevButton(); 1549 this.attachKeydownFormInputEvent(); 1550 this.submitForm(); 1551 1552 if (Form.isEditProfileForm() && $('#' + Form.idNames.trigger).find('[id^="suz_div_"].is-error').length) { 1553 Form.isFirstFocus = true; 1554 setTimeout(function () { 1555 Form.focusFirstErrorItem(); 1556 }, 0); 1557 } else if (Form.isEditProfileForm()) { 1558 Form.setInitialFocus(this.$root); 1559 } else if ($('#' + Form.idNames.trigger).find('[id^="suz_div_"].is-error').length) { 1560 Form.isFirstFocus = true; 1561 setTimeout(function () { 1562 Form.focusFirstErrorItem(); 1563 }, 0); 1564 } else { 1565 Form.setInitialFocus(this.$root); 1566 } 1567 } else { 1568 this.initAttributes(); 1569 this.addEventAll(); 1570 this.setPanelAttributes(); 1571 this.initProgressBar(); 1572 this.initAutoComplete(); 1573 1574 Form.focusFirstErrorItem(); 1575 } 1576 }; 1577 1578 Register.initAttributes = function () { 1579 this.$root.attr('data-index-current', 0); 1580 this.$root.addClass(Form.classNames.isInitialized); 1581 1582 if (!this.isErrorPage) { 1583 $('#' + idNames.email).prop('disabled', true); 1584 } 1585 }; 1586 1587 Register.addEventAll = function () { 1588 this.clickNextButton(); 1589 this.clickPrevButton(); 1590 this.clickBackLink(); 1591 this.submitForm(); 1592 this.attachKeydownFormInputEvent(); 1593 }; 1594 1595 Register.isRegError = function () { 1596 if (this.$root.hasClass(classNames.isRegError)) { 1597 return true; 1598 } 1599 1600 return false; 1601 }; 1602 1603 Register.isRegFlat = function () { 1604 if (this.$root.hasClass(classNames.isRegFlat)) { 1605 return true; 1606 } 1607 1608 return false; 1609 }; 1610 1611 Register.getPanels = function () { 1612 var $parentElement = this.$root.find('#' + idNames.formPanelParent); 1613 var $panels; 1614 1615 if ($parentElement.length) { 1616 $panels = $parentElement.children('.' + classNames.formPanel); 1617 } else { 1618 $panels = this.$root.find('.' + classNames.formPanel); 1619 } 1620 1621 return $panels; 1622 }; 1623 1624 Register.setPanelAttributes = function () { 1625 var $panels = this.getPanels(); 1626 var mobileContryInfo = Form.PreForm.getMobileCountryInfo(); 1627 var $regMobileContryNumber = $('#suz_mobileCountryNumber'); 1628 1629 $panels.each(function (index) { 1630 $(this).attr('data-panel-index', index + 1); 1631 $(this).attr('data-panel-displayed', false); 1632 }); 1633 1634 if (!this.isErrorPage) { 1635 $('#' + idNames.email).prop('disabled', true); 1636 } 1637 1638 if (Register.$root.attr('data-index-current') === PANEL_NUM.NONE) { 1639 this.showPanelByIndex(PANEL_INDEX.FIRST) 1640 } 1641 1642 if (!this.isRegError() && !this.isRegFlat()) { 1643 Form.setInitialFocus(this.$root); 1644 } 1645 1646 Form.focusFirstErrorItem(Register.$root.find('#' + idNames.formPanelParent)); 1647 1648 if ($regMobileContryNumber.length) { 1649 $regMobileContryNumber.val(mobileContryInfo.code); 1650 $regMobileContryNumber.attr('disabled', true); 1651 $('#suz_mobileNumber').val($('#checkMobileNumber').val()); 1652 } 1653 }; 1654 1655 Register.setPassedStatusByButton = function (button, status) { 1656 var $panel; 1657 1658 if (button && typeof status === 'boolean') { 1659 $panel = $(button).parents('.' + this.classNames.formPanel); 1660 1661 if ($panel.length) { 1662 $panel.attr('data-panel-passed', status); 1663 } 1664 } 1665 }; 1666 1667 Register.showNext = function (event, isEnterKeyTrigger) { 1668 var button = event.currentTarget; 1669 var $panels = this.getPanels(); 1670 var $currentPanel; 1671 var $autoCompleteElements = null; 1672 var AvailableValidator = KeyenceForm.AvailableValidator; 1673 var FilledFieldValidator = KeyenceForm.filledFieldValidator; 1674 var ControlErrorDisplay = KeyenceForm.ControlErrorDisplay; 1675 var $mobileNumber = null; 1676 var $phoneNumber = null; 1677 var formEnquete = win.KeyenceEnquete.form; 1678 1679 if (button.disabled) { 1680 return; 1681 } 1682 1683 if (event.handleObj.type !== 'keydown') { 1684 event.preventDefault(); 1685 } 1686 1687 if (!isEnterKeyTrigger) { 1688 if (event.handleObj.type === 'keydown' && event.key !== 'Enter') { 1689 return; 1690 } 1691 1692 if (event.handleObj.type === 'mousedown' && event.which !== EVENT_TYPE.CLICK_LEFT) { 1693 return; 1694 } 1695 1696 if (event.handleObj.type === 'touchend' && isScrolling) { 1697 return; 1698 } 1699 } 1700 1701 if (this.getCurrentIndex() === this.getLastIndex()) { 1702 ControlErrorDisplay.setTriggerClickedData(button, 'register'); 1703 1704 return; 1705 } 1706 1707 $currentPanel = $(button).parents('.' + this.classNames.formPanel + '.' + Form.classNames.isCurrent); 1708 1709 if ($currentPanel.attr('data-panel-passed') === 'true') { 1710 return; 1711 } 1712 1713 if (win.kpi_siteSettings.siteId === Form.siteData.KA.id) { 1714 AvailableValidator.updateRegisterBlockStatus($currentPanel, event, 'n
1714otLastPanel'); 1715 1716 if (AvailableValidator.config.isRegisterContinueBlocked) { 1717 return; 1718 } 1719 1720 $mobileNumber = $currentPanel.find('.' + AvailableValidator.targetWrapperClass.mobile); 1721 $phoneNumber = $currentPanel.find('.' + AvailableValidator.targetWrapperClass.phone); 1722 } 1723 1724 $autoCompleteElements = $currentPanel.find('.' + classNames.isAutoCompleteElementHide); 1725 1726 if ($autoCompleteElements.length) { 1727 Register.removeAutoCompleteHideClass(); 1728 } 1729 1730 if (!ControlErrorDisplay.isTriggerClicked(button)) { 1731 ControlErrorDisplay.setTriggerClickedData(button, 'register'); 1732 FilledFieldValidator.validateOptionalField($currentPanel); 1733 } 1734 1735 $currentPanel.attr('data-panel-passed', true); 1736 1737 if (win.kpi_siteSettings.siteId === Form.siteData.KA.id) { 1738 if ($mobileNumber.length) { 1739 if ($mobileNumber.hasClass(AvailableValidator.targetClass.status)) { 1740 $mobileNumber.attr('data-unavailable', 'true'); 1741 } 1742 } 1743 1744 if ($phoneNumber.length) { 1745 if ($phoneNumber.hasClass(AvailableValidator.targetClass.status)) { 1746 $phoneNumber.attr('data-unavailable', 'true'); 1747 } 1748 } 1749 } 1750 1751 this.updateInputFieldStatus($currentPanel).done(function (hasError) { 1752 var $currentPanel; 1753 var $newPanel; 1754 var nextIndex; 1755 1756 $currentPanel = $panels.filter('.' + Form.classNames.isCurrent); 1757 1758 if (hasError) { 1759 $currentPanel.removeAttr('data-panel-passed'); 1760 Form.focusFirstErrorItem($currentPanel); 1761 formEnquete._validateEnqueteWithProceedButton(); 1762 1763 return; 1764 } 1765 1766 if (!$currentPanel.length) { 1767 return; 1768 } 1769 1770 $newPanel = $panels.filter('.' + Form.classNames.isCurrent).next(); 1771 1772 if ($newPanel.length) { 1773 AvailableValidator.hideNoteText($newPanel); 1774 1775 nextIndex = $newPanel.index(); 1776 1777 Register.disableInputElementAll($currentPanel.find(Form.selectors.focusbleInputElements)); 1778 formEnquete._validateEnqueteWithProceedButton(); 1779 Register.showPanelByIndex(nextIndex); 1780 1781 Form.changeCurrentScreenName('step', nextIndex + 1); 1782 1783 Register.changeProgress($newPanel.data('panelIndex')); 1784 Form.scrollToElement(Register.idNames.regForm); 1785 1786 $currentPanel.removeAttr('data-panel-passed'); 1787 1788 if ($newPanel.attr('data-panel-displayed') === 'false') { 1789 Form.Register.clearInputErrorAll($newPanel); 1790 $newPanel.attr('data-panel-displayed', true); 1791 } 1792 } 1793 }).fail(function () { 1794 $currentPanel.removeAttr('data-panel-passed'); 1795 }); 1796 }; 1797 1798 Register.showPrev = function (event) { 1799 var button = event.currentTarget; 1800 var $panels = this.getPanels(); 1801 var $currentPanel; 1802 var $prevPanel; 1803 var prevIndex; 1804 var availableValidator = KeyenceForm.AvailableValidator; 1805 1806 if (event.handleObj.type !== 'keydown') { 1807 event.preventDefault(); 1808 } 1809 1810 if (event.handleObj.type === 'keydown' && event.key !== 'Enter') { 1811 return; 1812 } 1813 1814 if (event.handleObj.type === 'mousedown' && event.which !== EVENT_TYPE.CLICK_LEFT) { 1815 return; 1816 } 1817 1818 if (event.handleObj.type === 'touchend' && isScrolling) { 1819 return; 1820 } 1821 1822 $currentPanel = $(button).parents('.' + this.classNames.formPanel + '.' + Form.classNames.isCurrent); 1823 1824 if (!$currentPanel.length) { 1825 return; 1826 } 1827 1828 if ($currentPanel.attr('data-panel-passed') === 'true') { 1829 return; 1830 } 1831 1832 this.$root.off('keypress.enterKeySubmit'); 1833 $currentPanel.attr('data-panel-passed', true); 1834 1835 $prevPanel = $panels.filter('.' + Form.classNames.isCurrent).prev(); 1836 1837 if ($prevPanel.length) { 1838 availableValidator.hideNoteText($prevPanel); 1839 1840 prevIndex = $prevPanel.index(); 1841 1842 Register.showPanelByIndex(prevIndex); 1843 Form.changeCurrentScreenName('step', prevIndex + 1); 1844 Register.changeProgress($prevPanel.data('panelIndex')); 1845 } else { 1846 availableValidator.hideNoteText(Form.PreForm.$root); 1847 1848 Form.show(Form.PreForm.$root); 1849 Form.hide(Register.$root); 1850 1851 Form.changeCurrentScreenName(Form.screenNames.initial); 1852 } 1853 1854 $currentPanel.removeAttr('data-panel-passed'); 1855 Form.scrollToElement(Form.idNames.trigger); 1856 1857 }; 1858 1859 Register.updateInputFieldStatus = function ($currentPanel) { 1860 var $requiredInputs; 1861 var deferred = new $.Deferred(); 1862 var hasError = false; 1863 var deferreds = []; 1864 var BlankFieldValidator = win.KeyenceForm.BlankFieldValidator; 1865 var PatternMatchValidator = win.KeyenceForm.PatternMatchValidator; 1866 var FilledFieldValidator = win.KeyenceForm.filledFieldValidator; 1867 1868 if (!$currentPanel.length) { 1869 deferred.resolve(false); 1870 } 1871 1872 $requiredInputs = $currentPanel.find('.' + this.classNames.required).filter(':visible'); 1873 1874 if ($requiredInputs.length) { 1875 $requiredInputs.each(function () { 1876 var field = this; 1877 1878 if (field.classList.contains(BlankFieldValidator.classNames.trigger) 1879 && field.classList.contains(PatternMatchValidator.classNames.replaceValueTrigger)) { 1880 if (BlankFieldValidator.isBlank(field)) { 1881 Form.insertErrorText(field.name); 1882 1883 hasError = true; 1884 return; 1885 } 1886 1887 PatternMatchValidator.updateFieldStatus(field); 1888 1889 if (field.classList.contains(PatternMatchValidator.classNames.status)) { 1890 FilledFieldValidator.changeFieldStatus($(field), true); 1891 hasError = true; 1892 return; 1893 } 1894 1895 Form.clearInputError(field.name, true, false); 1896 } else if (field.classList.contains(BlankFieldValidator.classNames.trigger)) { 1897 if (BlankFieldValidator.isBlank(field)) { 1898 Form.insertErrorText(field.name); 1899 1900 hasError = true; 1901 } else { 1902 Form.clearInputError(field.name, true, false); 1903 } 1904 } else if (field.classList.contains(PatternMatchValidator.classNames.replaceValueTrigger)) { 1905 PatternMatchValidator.updateFieldStatus(field); 1906 1907 if (field.classList.contains(PatternMatchValidator.classNames.status)) { 1908 FilledFieldValidator.changeFieldStatus($(field), true); 1909 hasError = true; 1910 } else { 1911 deferreds.push(win.suz_callRegValidator($(field))); 1912 } 1913 } else { 1914 deferreds.push(win.suz_callRegValidator($(field), field.value)); 1915 } 1916 }); 1917 1918 if (hasError) { 1919 deferred.resolve(hasError); 1920 } else { 1921 $.when.apply(null, deferreds).then(function () { 1922 Array.prototype.slice.call(arguments).forEac
1922h(function (result) { 1923 if (result && (result.message && result.message.length)) { 1924 hasError = true; 1925 } 1926 }); 1927 1928 deferred.resolve(hasError); 1929 }); 1930 } 1931 } else { 1932 deferred.resolve(false); 1933 } 1934 1935 return deferred.promise(); 1936 }; 1937 1938 Register.enableInputElements = function ($inputElements) { 1939 if ($inputElements && $inputElements.length) { 1940 $inputElements.prop('disabled', false); 1941 } 1942 }; 1943 1944 Register.disableInputElementAll = function ($inputElements) { 1945 if ($inputElements && $inputElements.length) { 1946 $inputElements.prop('disabled', true); 1947 } 1948 }; 1949 1950 Register.showPanelByIndex = function (nextIndex) { 1951 var $panels = this.getPanels(); 1952 var $email = $('#suz_emailAddress'); 1953 1954 if (typeof nextIndex !== 'number' || !$panels.length) { 1955 return; 1956 } 1957 1958 if (nextIndex === 0) { 1959 Form.Register.$description.removeClass('is-hide'); 1960 } else { 1961 Form.Register.$description.addClass('is-hide'); 1962 } 1963 1964 $panels.each(function (index) { 1965 var $this = $(this); 1966 1967 $this.find('svg').attr('focusable', false); 1968 1969 if (index === nextIndex) { 1970 Register.showPanel($this); 1971 } else { 1972 if (Register.isRegError() || Register.isRegFlat()) { 1973 return; 1974 } 1975 1976 Register.hidePanel($this); 1977 1978 if (index < nextIndex) { 1979 Register.disableInputElementAll($this.find(Form.selectors.focusbleInputElements)); 1980 } 1981 } 1982 }); 1983 }; 1984 1985 Register.showPanel = function ($panel) { 1986 var $inputElements; 1987 var panelNum; 1988 1989 if (!$panel || !$panel.length) { 1990 return; 1991 } 1992 1993 panelNum = $panel.data('panelIndex'); 1994 1995 if (panelNum === undefined) { 1996 panelNum = PANEL_NUM.FIRST; 1997 } 1998 1999 $inputElements = $panel.find(Form.selectors.disabledInputElements + ',' + Form.selectors.focusbleInputElements); 2000 2001 if ($inputElements.length) { 2002 if (panelNum === PANEL_NUM.FIRST) { 2003 $inputElements = $inputElements.filter(function () { 2004 return this.name !== 'emailAddress' && this.name !== 'mobileNumber' && this.name !== 'countryNumber' && this.name !== 'mobileCountryNumber' 2005 }); 2006 } 2007 2008 Register.enableInputElements($inputElements); 2009 } 2010 2011 Form.enableFocus($panel.find(Form.selectors.focusbleElements)); 2012 $panel.addClass(Form.classNames.isCurrent); 2013 this.$root.attr('data-index-current', panelNum); 2014 2015 if (Form.needFocus && $inputElements.length && !this.isRegError() && !this.isRegFlat()) { 2016 $inputElements.get(0).focus(); 2017 } 2018 }; 2019 2020 Register.hidePanel = function ($panel) { 2021 var $focusbleElements; 2022 2023 if (!$panel || !$panel.length) { 2024 return; 2025 } 2026 2027 $panel.removeClass(Form.classNames.isCurrent); 2028 2029 $focusbleElements = $panel.find(Form.selectors.focusbleElements); 2030 2031 Form.disableFocus($focusbleElements); 2032 }; 2033 2034 Register.initProgressBar = function () { 2035 var $panels = this.getPanels(); 2036 2037 if ($panels.length) { 2038 this.$progressTotalNum.text($panels.length); 2039 this.changeProgress(1); 2040 } 2041 }; 2042 2043 Register.changeProgress = function (num) { 2044 var $panels = this.getPanels(); 2045 var $progressStepList = $('.' + classNames.progressBar); 2046 var $progressBarListItems = null; 2047 2048 if (typeof num !== 'number' || !$panels.length) { 2049 return; 2050 } 2051 2052 if ($progressStepList.length) { 2053 $progressBarListItems = $progressStepList.find('.' + classNames.progressBarStepTarget); 2054 2055 $progressBarListItems.each(function (index) { 2056 if (index === num - 1) { 2057 $(this).attr('aria-current', 'step'); 2058 } else { 2059 $(this).removeAttr('aria-current'); 2060 } 2061 }); 2062 } 2063 2064 if (Register.$formStepCurrentNum.length) { 2065 Register.$formStepCurrentNum.text(num); 2066 } else { 2067 Register.$progressCurrentNum.text(num); 2068 } 2069 }; 2070 2071 Register.clickNextButton = function () { 2072 this.$root.on('keydown mousedown touchend', '.' + this.classNames.btnNext, this.showNext.bind(this)); 2073 }; 2074 2075 Register.clickPrevButton = function () { 2076 this.$root.on('keydown mousedown touchend', '.' + this.classNames.btnPrevious, this.showPrev.bind(this)); 2077 }; 2078 2079 Register.clickBackLink = function () { 2080 this.$root.on('click', '#' + this.idNames.btnBackLink, function (event) { 2081 event.preventDefault(); 2082 Form.show(Form.PreForm.$root); 2083 Form.hide(Register.$root); 2084 2085 Form.changeCurrentScreenName(Form.screenNames.initial); 2086 }); 2087 2088 this.$root.on('click', '#' + this.idNames.btnBackToMobileLink, function (event) { 2089 event.preventDefault(); 2090 Form.show(Form.PreForm.$root); 2091 Form.hide(Register.$root); 2092 }); 2093 }; 2094 2095 Register.getCurrentIndex = function () { 2096 var $panels = this.getPanels(); 2097 var $current; 2098 2099 if (!$panels.length) { 2100 return null; 2101 } 2102 2103 $current = $panels.filter('.' + Form.classNames.isCurrent); 2104 2105 return $current.index(); 2106 }; 2107 2108 Register.getLastIndex = function () { 2109 var $panels = this.getPanels(); 2110 2111 if ($panels.length) { 2112 return $panels.length - 1; 2113 } 2114 2115 return null; 2116 }; 2117 2118 Register.isLastPage = function () { 2119 var $panels = this.getPanels(); 2120 2121 if ($panels.length === this.getCurrentIndex()) { 2122 return true; 2123 } 2124 2125 return false; 2126 }; 2127 2128 Register.isActionPwdAssistance = function () { 2129 var actionValue = Register.$formRoot.attr('action'); 2130 2131 if (new RegExp(Form.urls.actionPwdAssistance).test(actionValue)) { 2132 return true; 2133 } 2134 2135 return false; 2136 }; 2137 2138 Register.submitForm = function () { 2139 this.$formRoot.on('submit.reg-submit', this.onSubmitForm.bind(this)); 2140 }; 2141 2142 Register.onSubmitForm = function (event) { 2143 var FormFilter = KEYENCE.Form.FormFilter; 2144 var $panels = this.getPanels(); 2145 var $currentPanel; 2146 var formTypeGeneral = FormFilter.General.getFormType(); 2147 var $autoCompleteElements = null; 2148 var AvailableValidator = win.KeyenceForm.AvailableValidator; 2149 var PatternMatchValidator = win.KeyenceForm.PatternMatchValidator; 2150 var FilledFieldValidator = win.KeyenceForm.filledFieldValidator; 2151 var ControlErrorDisplay = win.KeyenceForm.ControlErrorDisplay; 2152 var $mobileNumber = null; 2153 var $phoneNumber = null; 2154 var $replaceValueTargets = null; 2155 var replaceValueTargetsLength = 0; 2156 var patternError = false; 2157 var errorElementsLength = 0; 2158 var controlErrorDisplayTrigger = null; 2159 var isInvalid = false; 2160 2161 if (Form.isShow(Form.PreForm.$root)) { 2162 return false; 2163 } 2164 2165 if (Register.isActionPwdAssistance()) { 2166 return true; 2167 } 2168 2169 if (Form.isShow(Form.SignIn.$root)) { 2170 if (Form.SignIn.validateForm(event.originalEvent.submitter)) { 2171 return true; 2172 } 2173 2174 return false; 2175 } 2176 2177 $currentPanel = $panels.filter('.' + Form.classNames.isCurrent); 2178
2179 if (event.type === 'invalid') { 2180 isInvalid = true; 2181 controlErrorDisplayTrigger = ControlErrorDisplay.browserValidatorTarget; 2182 } else { 2183 controlErrorDisplayTrigger = event.originalEvent.submitter ? event.originalEvent.submitter : ControlErrorDisplay.browserValidatorTarget; 2184 } 2185 2186 if (win.kpi_siteSettings.siteId === Form.siteData.KA.id) { 2187 AvailableValidator.updateRegisterBlockStatus($currentPanel, event, 'lastPanel'); 2188 2189 if (AvailableValidator.config.isRegisterContinueBlocked) { 2190 return false; 2191 } 2192 2193 $mobileNumber = $currentPanel.find('.' + AvailableValidator.targetWrapperClass.mobile); 2194 $phoneNumber = $currentPanel.find('.' + AvailableValidator.targetWrapperClass.phone); 2195 } 2196 2197 if (Register.isRegError() || Register.isRegFlat()) { 2198 if (isInvalid) { 2199 ControlErrorDisplay.setTriggerClickedData(controlErrorDisplayTrigger, 'register'); 2200 Register.updateInputFieldStatus($panels).done(function () { 2201 Form.focusFirstErrorItem(); 2202 }); 2203 2204 return; 2205 } else { 2206 $replaceValueTargets = $currentPanel.find('.' + PatternMatchValidator.classNames.replaceValueTrigger); 2207 2208 if ($replaceValueTargets.length) { 2209 replaceValueTargetsLength = $replaceValueTargets.length; 2210 2211 $replaceValueTargets.each(function () { 2212 PatternMatchValidator.updateFieldStatus(this); 2213 2214 if (this.classList.contains(PatternMatchValidator.classNames.status)) { 2215 FilledFieldValidator.changeFieldStatus($(this), true); 2216 patternError = true; 2217 } 2218 }); 2219 2220 errorElementsLength = $currentPanel.find('.' + this.classNames.isError).length; 2221 } 2222 2223 if (patternError && replaceValueTargetsLength === errorElementsLength) { 2224 Form.focusFirstErrorItem(); 2225 2226 return false; 2227 } 2228 2229 if (formTypeGeneral === FormFilter.General.FORM_TYPE.EMAIL) { 2230 $('#' + idNames.email).prop('disabled', false); 2231 } else if (formTypeGeneral === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 2232 $('#' + idNames.mobileNumber).prop('disabled', false); 2233 } else { 2234 $('#' + idNames.email).prop('disabled', false); 2235 } 2236 2237 return true; 2238 } 2239 } 2240 2241 if (this.getCurrentIndex() !== this.getLastIndex()) { 2242 ControlErrorDisplay.setTriggerClickedData(controlErrorDisplayTrigger, 'register'); 2243 2244 return false; 2245 } 2246 2247 if (canSubmit) { 2248 $panels.each(function () { 2249 Register.enableInputElements($(this).find(Form.selectors.disabledInputElements)); 2250 }); 2251 2252 if (Form.isEditProfileForm()) { 2253 KEYENCE.Form.MultiFactorAuthentication.enableAllInputs(); 2254 } 2255 2256 if (formTypeGeneral === FormFilter.General.FORM_TYPE.EMAIL) { 2257 FormFilter.General.disableFields('mobileNumber', true); 2258 } else if (formTypeGeneral === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 2259 FormFilter.General.disableFields('email', true); 2260 } 2261 2262 return true; 2263 } 2264 2265 $autoCompleteElements = $currentPanel.find('.' + classNames.isAutoCompleteElementHide); 2266 2267 if ($autoCompleteElements.length) { 2268 Register.removeAutoCompleteHideClass(); 2269 } 2270 2271 if (!ControlErrorDisplay.isTriggerClicked(controlErrorDisplayTrigger)) { 2272 ControlErrorDisplay.setTriggerClickedData(controlErrorDisplayTrigger, 'register'); 2273 FilledFieldValidator.validateOptionalField($currentPanel); 2274 } 2275 2276 if (win.kpi_siteSettings.siteId === Form.siteData.KA.id) { 2277 if ($mobileNumber.length) { 2278 if ($mobileNumber.hasClass(AvailableValidator.targetClass.status)) { 2279 $mobileNumber.attr('data-unavailable', 'true'); 2280 } 2281 } 2282 2283 if ($phoneNumber.length) { 2284 if ($phoneNumber.hasClass(AvailableValidator.targetClass.status)) { 2285 $phoneNumber.attr('data-unavailable', 'true'); 2286 } 2287 } 2288 } 2289 2290 this.updateInputFieldStatus($currentPanel).done(function (hasError) { 2291 if (hasError) { 2292 Form.scrollToElement(Form.idNames.trigger); 2293 Form.focusFirstErrorItem($currentPanel); 2294 } else { 2295 canSubmit = true; 2296 2297 $('.' + classNames.btnSubmit).click(); 2298 } 2299 }); 2300 2301 return false; 2302 }; 2303 2304 Register.clearInputErrorAll = function ($panel) {
2305 var $inputs; 2306 2307 if ($panel && $panel.length) { 2308 $inputs = $panel.find('.' + this.classNames.required); 2309 2310 $inputs.each(function () { 2311 Form.clearInputError(this.name, false); 2312 }); 2313 } 2314 }; 2315 2316 Register.attachKeydownFormInputEvent = function () { 2317 this.$root.on('keydown.enterKeySubmit', 'input:not([disabled]), textarea:not([disabled])', this.onKeydownFormInput.bind(this)); 2318 }; 2319 2320 Register.onKeydownFormInput = function (event, isEnquete) { 2321 var $currentPanel; 2322 var $buttonContinue; 2323 var company; 2324 var companySuggestCursoredItem; 2325 var companySuggestCloseButton; 2326 2327 if (event.key !== 'Enter') { 2328 return; 2329 } 2330 2331 company = document.getElementById('corporate_name'); 2332 companySuggestCursoredItem = document.querySelector('.StandeStyle-cursoredItem'); 2333 companySuggestCloseButton = document.getElementById('stande-closebutton'); 2334 2335 if (company && companySuggestCursoredItem) { 2336 if (company === document.activeElement) { 2337 window.setTimeout(function () { 2338 win.KeyenceForm.filledFieldValidator.runSuggestValidator(); 2339 }, 0); 2340 2341 return; 2342 } 2343 } else if (company && companySuggestCloseButton) { 2344 if (company === document.activeElement) { 2345 companySuggestCloseButton.click(); 2346 } 2347 } 2348 2349 if (Register.isRegError() || Register.isRegFlat() || (this.getCurrentIndex() === this.getLastIndex())) { 2350 $('.' + classNames.btnSubmit).click(); 2351 2352 return false; 2353 } 2354 2355 if (isEnquete) { 2356 $currentPanel = $('.js-multiStep-target.is-current'); 2357 } else { 2358 $currentPanel = $(event.currentTarget).parents('.js-multiStep-target'); 2359 } 2360 2361 if ($currentPanel.length && $currentPanel.hasClass('is-current')) { 2362 $buttonContinue = $currentPanel.find('.js-regForm-btnNext'); 2363 2364 if ($buttonContinue.length) { 2365 $buttonContinue.trigger('mousedown', true); 2366 } 2367 } 2368 2369 return false; 2370 }; 2371 2372 Register.initAutoComplete = function () { 2373 var wrapperElement = document.getElementById(idNames.suzRegArea); 2374 var country = document.getElementById(idNames.country); 2375 2376 if (!wrapperElement || !country) { 2377 return; 2378 } 2379 2380 Register.setAutoCompleteMutationObserver(wrapperElement); 2381 Register.runAutoCompleteDisplayChange(country); 2382 }; 2383 2384 Register.setAutoCompleteMutationObserver = function (elem) { 2385 var target = elem; 2386 var observer = null; 2387 var country = null; 2388 var observerAutoCompleteConfig = { 2389 attributeFilter: ['id'], 2390 childList: true 2391 }; 2392 2393 observer = new MutationObserver(function (record) { 2394 if (record[0].target.id === idNames.suzRegArea) { 2395 country = document.getElementById(idNames.country); 2396 2397 if (!country) { 2398 return; 2399 } 2400 2401 Register.runAutoCompleteDisplayChange(country); 2402 } 2403 }); 2404 2405 observer.observe(target, observerAutoCompleteConfig); 2406 }; 2407 2408 Register.runAutoCompleteDisplayChange = function (selector) { 2409 var countryValue = selector.options[selector.selectedIndex].value; 2410 2411 if (countryValue === 'JP' && Register.isCompanySuggest()) { 2412 Register.addAutoCompleteHideClass(); 2413 Register.attachDisplayChangeEvent(); 2414 } 2415 }; 2416 2417 Register.isCompanySuggest = function () { 2418 try { 2419 new StandeArgument(); 2420 } catch (exception) { 2421 return false; 2422 } 2423 2424 return true; 2425 }; 2426 2427 Register.addAutoCompleteHideClass = function () { 2428 var targets = { 2429 zipCode: document.getElementById(idNames.zipCodeWrapper), 2430 state: document.getElementById(idNames.stateWrapper), 2431 address1: document.getElementById(idNames.addressWrapper), 2432 address2: document.getElementById(idNames.address2Wrapper) 2433 } 2434 2435 if (!targets.zipCode || !targets.state || !targets.address1 || !targets.address2) { 2436 return; 2437 } 2438
2439 Object.keys(targets).forEach(function (key) { 2440 if (targets[key]) { 2441 targets[key].classList.add(classNames.isAutoCompleteElementHide); 2442 2443 Register.isAutoCompleteElementsHide = true; 2444 } 2445 }); 2446 }; 2447 2448 Register.attachDisplayChangeEvent = function () { 2449 var companyInput = document.getElementsByName("companyName"); 2450 2451 if (companyInput.length) { 2452 companyInput[0].addEventListener('click', Register.removeAutoCompleteHideClass, false); 2453 companyInput[0].addEventListener('input', Register.removeAutoCompleteHideClass, false); 2454 } 2455 }; 2456 2457 Register.removeAutoCompleteHideClass = function () { 2458 var targets = {}; 2459 var companyInput = null; 2460 2461 if (!Register.isAutoCompleteElementsHide) { 2462 companyInput = document.getElementsByName("companyName"); 2463 2464 if (companyInput.length) { 2465 companyInput[0].removeEventListener('click', Register.removeAutoCompleteHideClass, false); 2466 companyInput[0].removeEventListener('input', Register.removeAutoCompleteHideClass, false); 2467 } 2468 2469 return; 2470 } 2471 2472 targets = { 2473 zipCode: document.getElementById(idNames.zipCodeWrapper), 2474 state: document.getElementById(idNames.stateWrapper), 2475 address1: document.getElementById(idNames.addressWrapper), 2476 address2: document.getElementById(idNames.address2Wrapper) 2477 }; 2478 2479 if (!targets.zipCode || !targets.state || !targets.address1 || !targets.address2) { 2480 return; 2481 } 2482 2483 Object.keys(targets).forEach(function (key) { 2484 if (targets[key] && targets[key].classList.contains(classNames.isAutoCompleteElementHide)) { 2485 targets[key].classList.remove(classNames.isAutoCompleteElementHide); 2486 2487 Register.isAutoCompleteElementsHide = false; 2488 } 2489 }); 2490 }; 2491 2492 return Register; 2493 }()); 2494 2495 Form.SendEmail = (function () { 2496 var idNames = { 2497 root: 'js-multiStepForm-sendEmail', 2498 btnBackToSignin: 'js-sendEmail-btnBackToSignin', 2499 btnBackToAutoSignup: 'js-sendEmail-btnBackToAutoSignup', 2500 }; 2501 2502 var classNames = { 2503 enterEmailAddress: 'js-enterEmailAddress', 2504 verificationEmailTarget: 'js-showVerificationEmail-target', 2505 isVerificationEmailActive: 'is-sendVerificationEmail-active', 2506 isHide: 'is-hide', 2507 }; 2508 2509 var config = { 2510 api: { 2511 signin: { 2512 url: '/ajax/userAjax/publishLoginUrl/', 2513 }, 2514 autoSignup: { 2515 url: '/ajax/userAjax/publishAutoSignupUrl/', 2516 } 2517 } 2518 } 2519 2520 var SendEmail = { 2521 idNames: idNames, 2522 classNames: classNames, 2523 config: config, 2524 root: doc.getElementById(idNames.root), 2525 btnBackToSignin: doc.getElementById(idNames.btnBackToSignin), 2526 enterEmailAddressTargets: doc.querySelectorAll('.' + classNames.enterEmailAddress), 2527 verificationEmailTarget: doc.querySelectorAll('.' + classNames.verificationEmailTarget), 2528 btnBackToAutoSignup: doc.getElementById(idNames.btnBackToAutoSignup), 2529 }; 2530 2531 SendEmail.init = function () { 2532 if (!this.root) { 2533 return; 2534 } 2535 2536 if (Form.PreForm.$multiStepFormTrigger.hasClass(this.classNames.isVerificationEmailActive)) { 2537 this.showTarget(this.verificationEmailTarget); 2538 } 2539 2540 SendEmail.addClickBackButton(); 2541 }; 2542 2543 SendEmail.showTarget = function (targets) { 2544 if (typeof targets === 'object' && targets.length) {
2545 targets.forEach(function (target) { 2546 target.classList.remove(SendEmail.classNames.isHide); 2547 }); 2548 } 2549 }; 2550 2551 SendEmail.attachClickSendEmailButton = function ($trigger) { 2552 if ($trigger.length) { 2553 $trigger.on('click', this.showResultView.bind(this)); 2554 } 2555 }; 2556 2557 SendEmail.showResultView = function (e) { 2558 var triggerId = e.currentTarget.id; 2559 2560 if (!this.root || !triggerId) { 2561 return; 2562 } 2563 2564 if (triggerId === Form.SignIn.idNames.btnCheckSendEmail) { 2565 this.sendVerificationEmail(this.config.api.signin.url).done(function () { 2566 SendEmail.enterEmailAddress(); 2567 KEYENCE.Form.FormFilter.SendEmail.changeFilterClass(triggerId); 2568 Form.show($(Form.SendEmail.root)); 2569 Form.hide(Form.SignIn.$root); 2570 2571 Form.changeCurrentScreenName(Form.screenNames.OneClickLoginSendEmail); 2572 }).fail(function () { 2573 console.log('error'); 2574 }); 2575 } else if (triggerId === Form.SignIn.idNames.asuSendMailButton) { 2576 this.sendVerificationEmail(this.config.api.autoSignup.url).done(function () { 2577 KEYENCE.Form.FormFilter.SendEmail.changeFilterClass(triggerId); 2578 Form.show($(Form.SendEmail.root)); 2579 Form.hide(Form.SignIn.$root); 2580 2581 Form.changeCurrentScreenName(Form.screenNames.hospitalitySignUpSendEmail); 2582 }).fail(function () { 2583 console.log('error'); 2584 }); 2585 } 2586 }; 2587 2588 SendEmail.sendVerificationEmail = function (apiUrl) { 2589 var deferred = new $.Deferred(); 2590 var options; 2591 var $triggerField = Form.PreForm.$formCheckEmail; 2592 var $targetForm = null; 2593 var formData = ''; 2594 2595 if ($triggerField.length) { 2596 $targetForm = $triggerField.closest('form'); 2597 } 2598 2599 if ($targetForm.length) { 2600 formData = $targetForm.serialize(); 2601 } 2602 2603 if (!formData.length || !apiUrl) { 2604 return deferred.resolve(); 2605 } 2606 2607 options = { 2608 url: win.suz_getCurrentDomain() + apiUrl, 2609 type: 'post', 2610 data: { 2611 formData: formData 2612 }, 2613 dataType: 'jsonp', 2614 jsonp: 'callback', 2615 scriptCharset: 'UTF-8', 2616 timeout: 10000, 2617 }; 2618 2619 $.ajax(options).done(function () { 2620 deferred.resolve(); 2621 }).fail(function () { 2622 // Treat failure as success 2623 deferred.resolve(); 2624 }); 2625 2626 return deferred.promise(); 2627 }; 2628 2629 SendEmail.enterEmailAddress = function () { 2630 var emailAddressField = Form.PreForm.$formCheckEmail; 2631 2632 if (emailAddressField.length && this.enterEmailAddressTargets.length) { 2633 this.enterEmailAddressTargets.forEach(function (target) { 2634 target.textContent = emailAddressField.val(); 2635 }); 2636 } 2637 }; 2638 2639 SendEmail.addClickBackButton = function () { 2640 if (this.btnBackToSignin) { 2641 this.btnBackToSignin.addEventListener('click', this.changeDisplayForm.bind(this)); 2642 } 2643 2644 if (this.btnBackToAutoSignup) { 2645 this.btnBackToAutoSignup.addEventListener('click', this.changeDisplayForm.bind(this)); 2646 } 2647 }; 2648 2649 SendEmail.changeDisplayForm = function (event) { 2650 Form.show(Form.SignIn.$root); 2651 Form.hide($(this.root)); 2652 2653 if (event.currentTarget.id === 'js-sendEmail-btnBackToSignin') { 2654 Form.changeCurrentScreenName(Form.screenNames.login); 2655 } else { 2656 Form.changeCurrentScreenName(Form.screenNames.hospital
2656itySignUp); 2657 } 2658 }; 2659 2660 return SendEmail; 2661 }()); 2662 2663 win.MultiStepForm = Form; 2664 }()); 2665 2666 KEYENCE.Form = {}; 2667 2668 KEYENCE.Form.FormFilter = (function () { 2669 var FormFilter = {}; 2670 2671 FormFilter.init = function () { 2672 FormFilter.General.init(); 2673 FormFilter.SignIn.init(); 2674 FormFilter.SendEmail.init(); 2675 }; 2676 2677 FormFilter.General = (function () { 2678 var idNames = { 2679 mobileNumberTrigger: 'js-formFilterGeneral-mobileNumber', 2680 emailTtrigger: 'js-formFilterGeneral-email' 2681 }; 2682 2683 var classNames = { 2684 root: 'js-formFilterGeneral', 2685 trigger: 'js-formFilterGeneral-trigger', 2686 isFilterMobilenumber: 'is-filter-mobileNumber', 2687 isFilterEmail: 'is-filter-email', 2688 itemMobileNumber: 'js-formFilterGeneralItem-mobileNumber', 2689 itemEmail: 'js-formFilterGeneralItem-email', 2690 itemFilterEmal: 'js-formFilter-registEmail', 2691 runFilterEmail: 'js-runFilter-email', 2692 runFilterMobileNumber: 'js-runFilter-mobileNumber', 2693 }; 2694 2695 var urls = { 2696 updateFormElement: '/ajax/registrationAjax/getFormListForMobileNumber/', 2697 }; 2698 2699 var General = { 2700 idNames: idNames, 2701 classNames: classNames, 2702 rootElement: null, 2703 triggerElements: null, 2704 disabledIds: [], 2705 urls: urls, 2706 }; 2707 2708 var generalMessageEvent = { 2709 handleEvent: null, 2710 target: null, 2711 }; 2712 2713 General.FORM_TYPE = { 2714 EMAIL: 'email', 2715 MOBILE_NUMBER: 'mobileNumber', 2716 DEFAULT: 'default', 2717 }; 2718 2719 General.init = function () { 2720 this.rootElement = doc.querySelector('.' + classNames.root); 2721 this.triggerElements = doc.querySelectorAll('.' + classNames.trigger); 2722 2723 if (!this.rootElement || !this.triggerElements.length) { 2724 return; 2725 } 2726 2727 this.getDisalbedIds(); 2728 2729 if (this.getFormType() === this.FORM_TYPE.MOBILE_NUMBER) { 2730 FormFilter.General.disableFields('email'); 2731 } else { 2732 FormFilter.General.disableFields('mobileNumber'); 2733 } 2734 2735 this.attachClickFilterEvent(); 2736 this.attachClickShowEmailFormButton(); 2737 this.onMessageAction(); 2738 }; 2739 2740 General.getFormType = function () { 2741 var formType = this.FORM_TYPE.DEFAULT; 2742 2743 if (!this.rootElement) { 2744 return this.FORM_TYPE.DEFAULT; 2745 } 2746 2747 if (this.rootElement.classList.contains(classNames.isFilterEmail)) { 2748 formType = this.FORM_TYPE.EMAIL; 2749 } else if (this.rootElement.classList.contains(classNames.isFilterMobilenumber)) { 2750 formType = this.FORM_TYPE.MOBILE_NUMBER; 2751 } 2752 2753 return formType; 2754 }; 2755 2756 General.attachClickFilterEvent = function () { 2757 var self = this; 2758 2759 Array.prototype.forEach.call(this.triggerElements, function (trigger) { 2760 trigger.addEventListener('click', self.onClickFilter.bind(this)); 2761 }); 2762 }; 2763 2764 General.getDisalbedIds = function () { 2765 var items = document.querySelectorAll('.' + classNames.itemMobileNumber + ', .' + classNames.itemEmail); 2766 2767 Array.prototype.forEach.call(items, function (item) { 2768 var disabledFormElements = item.querySelectorAll('input:disabled, select:disabled, textarea:disabled'); 2769 2770 Array.prototype.forEach.call(disabledFormElements, function (disabledFormElement) { 2771 General.disabledIds.push(disabledFormElement.id); 2772 }); 2773 }); 2774 }; 2775 2776 General.getFilterFields = function (type) { 2777 var fields; 2778 2779 switch (type) { 2780 case 'mobileNumber': 2781 fields = document.querySelectorAll('.' + classNames.itemMobileNumber); 2782 break; 2783 case 'email': 2784 default: 2785 fields = document.querySelectorAll('.' + classNames.itemEmail); 2786 break; 2787 } 2788 2789 return fields; 2790 }; 2791 2792 General.disableFields = function (type) { 2793 var fields = this.getFilterFields(type); 2794 2795 if (!fields.length) { 2796 return; 2797 } 2798 2799 Array.prototype.forEach.call(fields, function (item) { 2800 var formElements = item.querySelectorAll('input, select, textarea'); 2801 2802 Array.prototype.forEach.call(formElements, function (formElement) { 2803 formElement.disabled = true; 2804 }); 2805 }); 2806 }; 2807 2808 General.enableFields = function (type, isAll) { 2809 var items = this.getFilterFields(type); 2810 2811 Array.prototype.forEach.call(items, function (item) { 2812 var formElements = item.querySelectorAll('input, select, textarea'); 2813 2814 Array.prototype.forEach.call(formElements, function (formElement) { 2815 if (isAll) { 2816 formElement.disabled = false; 2817 } else if (General.disabledIds.indexOf(formElement.id) === -1) { 2818 formElement.disabled = false; 2819 } 2820 }); 2821 }); 2822 }; 2823 2824 General.onClickFilter = function (event) { 2825 var currentTarget = event.currentTarget; 2826 var $regArea = null; 2827 2828 generalMessageEvent.target = currentTarget; 2829 2830 Array.prototype.forEach.call(General.triggerElements, function (trigger) { 2831 trigger.removeAttribute('aria-current'); 2832 }); 2833 2834 currentTarget.setAttribute('aria-current', 'page'); 2835 2836 $('.' + KEYENCE.Form.InputInterlock.classNames.trigger + ':visible').each(function () { 2837 var targetIdList = KEYENCE.Form.InputInterlock.getTargetIdListFromTrigger(this); 2838 2839 this.value = ''; 2840 2841 targetIdList.forEach(function (id) { 2842 var target = doc.getElementById(id); 2843 2844 if (target && target.tagName.toLowerCase() === 'input') { 2845 target.value = ''; 2846 } 2847 2848 KEYENCE.Form.InputInterlock.changeRelatedInputStatus(target, 'enable'); 2849 }); 2850 }); 2851 2852 if (!win.AnalyticsViews || !win.MultiStepForm.PreForm.checkMessageTargetForm()) { 2853 $regArea = $('#suz_regArea'); 2854 2855 if (currentTarget.id === idNames.mobileNumberTrigger) { 2856 General.rootElement.classList.remove(classNames.isFilterEmail); 2857 General.rootElement.classList.add(classNames.isFilterMobilenumber); 2858 2859 if ($regArea.length) { 2860 General.updateFormElement(true).done(function (data) { 2861 $regArea.html(data); 2862 General.enableFields('mobileNumber'); 2863 General.disableFields('email'); 2864 }).fail(function () { 2865 General.enableFields('mobileNumber'); 2866 General.disableFields('email'); 2867 }); 2868 } else { 2869 General.enableFields('mobileNumber'); 2870 General.disableFields('email'); 2871 } 2872 } else { 2873 General.rootElement.classList.remove(classNames.isFilterMobilenumber); 2874 General.rootElement.classList.add(classNames.isFilterEmail); 2875 2876 if ($regArea.length) { 2877 General.updateFormElement(false).done(function (data) { 2878 $regArea.html(data); 2879 General.enableFields('email'); 2880 General.disableFields('mobileNumber'); 2881 }).fail(function () { 2882 General.enableFields('email'); 2883 General.disableFields('mobileNumber'); 2884 }); 2885 } else { 2886 General.enableFields('email'); 2887 General.disableFields('mobileNumber'); 2888 } 2889 } 2890 } 2891 }; 2892 2893 General.attachClickShowEmailFormButton = function () { 2894 var filterEmailButton = doc.querySelector('#' + idNames.emailTtrigger); 2895 2896 $(doc).on('click', '.' + classNames.runFilterEmail, function () { 2897 if (filterEmailButton) { 2898 filterEmailButton.click(); 2899 } 2900 }); 2901 }; 2902 2903 General.onMessageAction = function () { 2904 generalMessageEvent.handleEvent = General.changeGeneralFilterClass; 2905 2906 win.addEventListener('message', generalMessageEvent, false); 2907 }; 2908 2909 General.changeGeneralFilterClass = function (e) { 2910 var $regArea = $('#suz_regArea'); 2911 2912 if (e.data === AnalyticsViews.Utility.messageNames.generalForm) { 2913 if (this.target.id === idNames.mobileNumberTrigger) { 2914 General.rootElement.classList.remove(classNames.isFilterEmail); 2915 General.rootElement.classList.add(classNames.isFilterMobilenumber); 2916 2917 if ($regArea.length) { 2918 General.updateFormElement(true).done(function (data) { 2919 $regArea.html(data); 2920 General.enableFields('mobileNumber'); 2921 General.disableFields('email'); 2922 }).fail(function () { 2923 General.enableFields('mobileNumber'); 2924 General.disableFields('email'); 2925 }); 2926 } else { 2927 General.enableFields('mobileNumber'); 2928 General.disableFields('email'); 2929 } 2930 } else { 2931 General.rootElement.classList.remove(classNames.isFilterMobilenumber); 2932 General.rootElement.classList.add(classNames.isFilterEmail); 2933 2934 if ($regArea.length) { 2935 General.updateFormElement(false).done(function (data) { 2936 $regArea.html(data); 2937 General.enableFields('email'); 2938 General.disableFields('mobileNumber'); 2939 }).fail(function () { 2940 General.enableFields('email'); 2941 General.disableFields('mobileNumber'); 2942 }); 2943 } else { 2944 General.enableFields('email'); 2945 General.disableFields('mobileNumber'); 2946 } 2947 } 2948 } 2949 }; 2950 2951 General.checkRootElement = function () { 2952 if (!this.rootElement) { 2953 return false; 2954 } 2955 2956 return true; 2957 }; 2958 2959 General.updateFormElement = function (isFilterMobileNumber) { 2960 var deferred = new $.Deferred(); 2961 var options; 2962 var url; 2963 2964 url = win.suz_getCurrentDomain() + this.urls.updateFormElement; 2965 2966 options = { 2967 url: url, 2968 type: 'POST', 2969 data: { 2970 mobileNumberTabFlag: isFilterMobileNumber 2971 }, 2972 dataType: 'html', 2973 scriptCharset: 'UTF-8', 2974 }; 2975 2976 $.ajax(options).done(function (data) { 2977 deferred.resolve(data); 2978 }).fail(function (jqXHR, textStatus, errorThrown) { 2979 deferred.reject(jqXHR, textStatus, errorThrown); 2980 }); 2981 2982 return deferred.promise(); 2983 }; 2984 2985 return General; 2986 }()); 2987 2988 FormFilter.SignIn = (function () { 2989 var idNames = {
2990 passwordTrigger: 'js-formFilterLogin-password', 2991 smscode: 'js-formFilterLogin-smscode', 2992 loginCountryNumber: 'loginCountryNumber', 2993 }; 2994 2995 var classNames = { 2996 root: 'js-formFilterLogin', 2997 trigger: 'js-formFilterLogin-trigger', 2998 isFilterPassword: 'is-filter-password', 2999 isFilterSmscode: 'is-filter-smscode', 3000 isFilterPasswordItem: 'js-formFilter-loginPassword', 3001 isFilterSMSCodeItem: 'js-formFilter-loginSMSCode', 3002 isFilterEmailItem: 'js-formFilter-loginEmail', 3003 itemPassword: 'js-formFilterLoginItem-password', 3004 itemSMSCode: 'js-formFilterLoginItem-smscode', 3005 isFilterAutoSignUp: 'is-filter-autoSignUp', 3006 itemAutoSignUp: 'js-formFilterLoginItem-autoSignUp', 3007 }; 3008 3009 var SignIn = { 3010 idNames: idNames, 3011 classNames: classNames, 3012 rootElement: null, 3013 triggerElements: null, 3014 disabledIds: [], 3015 $passwordTrigger: $('#' + idNames.passwordTrigger), 3016 $loginCountryNumber: $('#' + idNames.loginCountryNumber), 3017 }; 3018 3019 var asuMessageEvent = { 3020 handleEvent: null, 3021 }; 3022 3023 SignIn.FORM_TYPE = { 3024 EMAIL: 'email', 3025 PASSWORD: 'password', 3026 SMS_CODE: 'smscode', 3027 DEFAULT: 'default', 3028 ASU: 'asu', 3029 }; 3030 3031 SignIn.init = function () { 3032 this.rootElement = doc.querySelector('.' + classNames.root); 3033 this.triggerElements = doc.querySelectorAll('.' + classNames.trigger); 3034 3035 if (!this.rootElement || !this.triggerElements.length) { 3036 return; 3037 } 3038 3039 this.getDisalbedIds(); 3040 3041 if (this.getFormType() === this.FORM_TYPE.PASSWORD) { 3042 FormFilter.SignIn.disableFields('smscode'); 3043 FormFilter.SignIn.disableFields('asu'); 3044 FormFilter.SignIn.enableFields('password', true); 3045 } else if (this.getFormType() === this.FORM_TYPE.SMS_CODE) { 3046 FormFilter.SignIn.disableFields('password'); 3047 FormFilter.SignIn.disableFields('asu'); 3048 FormFilter.SignIn.enableFields('smscode', true); 3049 } else if (this.getFormType() === this.FORM_TYPE.ASU) { 3050 FormFilter.SignIn.disableFields('password'); 3051 FormFilter.SignIn.disableFields('smscode'); 3052 FormFilter.SignIn.enableFields('asu', true); 3053 } 3054 3055 FormFilter.SignIn.$loginCountryNumber.prop('disabled', true); 3056 win.MultiStepForm.SignIn.$loginMobileNumber.prop('disabled', true); 3057 3058 this.attachClickFilterEvent(); 3059 // this.onMessageAction(); 3060 }; 3061 3062 SignIn.attachClickFilterEvent = function () { 3063 var self = this; 3064 3065 Array.prototype.forEach.call(this.triggerElements, function (trigger) { 3066 trigger.addEventListener('click', self.onClickFilter.bind(this)); 3067 }); 3068 }; 3069 3070 SignIn.onClickFilter = function (event) { 3071 Array.prototype.forEach.call(SignIn.triggerElements, function (trigger) { 3072 trigger.removeAttribute('aria-current'); 3073 }); 3074 3075 event.currentTarget.setAttribute('aria-current', 'page'); 3076 3077 if (event.currentTarget.id === idNames.smscode) { 3078 SignIn.rootElement.classList.remove(classNames.isFilterPassword); 3079 SignIn.rootElement.classList.remove(classNames.isFilterAutoSignUp); 3080 SignIn.rootElement.classList.add(classNames.isFilterSmscode); 3081 $('#' + win.MultiStepForm.SignIn.idNames.loginPassword).prop('disabled', true); 3082 $('#' + win.MultiStepForm.SignIn.idNames.loginVerificationCode).prop('disabled', false); 3083 $('#' + win.MultiStepForm.SignIn.idNames.registerLoginPassword).prop('disabled', true); 3084 } else { 3085 SignIn.rootElement.classList.remove(classNames.isFilterSmscode); 3086 SignIn.rootElement.classList.remove(classNames.isFilterAutoSignUp
3086); 3087 SignIn.rootElement.classList.add(classNames.isFilterPassword); 3088 $('#' + win.MultiStepForm.SignIn.idNames.loginPassword).prop('disabled', false); 3089 $('#' + win.MultiStepForm.SignIn.idNames.loginVerificationCode).prop('disabled', true); 3090 $('#' + win.MultiStepForm.SignIn.idNames.registerLoginPassword).prop('disabled', true); 3091 } 3092 }; 3093 3094 SignIn.onMessageAction = function () { 3095 asuMessageEvent.handleEvent = SignIn.runValidation; 3096 3097 win.addEventListener('message', asuMessageEvent, false); 3098 }; 3099 3100 SignIn.changeAutoSignUp = function (isAutoSignup, formType) { 3101 if (!isAutoSignup) { 3102 return; 3103 } 3104 3105 SignIn.rootElement.classList.add(classNames.isFilterAutoSignUp); 3106 SignIn.rootElement.classList.remove(classNames.isFilterPassword); 3107 SignIn.rootElement.classList.remove(classNames.isFilterSmscode); 3108 $('#' + win.MultiStepForm.SignIn.idNames.loginPassword).prop('disabled', true); 3109 3110 if (formType === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 3111 $('#' + win.MultiStepForm.SignIn.idNames.loginVerificationCode).prop('disabled', false); 3112 $('#' + win.MultiStepForm.SignIn.idNames.registerLoginPassword).prop('disabled', false); 3113 } 3114 }; 3115 3116 SignIn.clickLoginPasswordTrigger = function () { 3117 if (SignIn.rootElement.classList.contains(classNames.isFilterAutoSignUp) && this.$passwordTrigger.length) { 3118 this.$passwordTrigger.click(); 3119 } 3120 }; 3121 3122 SignIn.getFormType = function () { 3123 var formType = this.FORM_TYPE.DEFAULT; 3124 3125 if (!this.rootElement) { 3126 return this.FORM_TYPE.DEFAULT; 3127 } 3128 3129 if (this.rootElement.classList.contains(classNames.isFilterPassword)) { 3130 formType = this.FORM_TYPE.PASSWORD; 3131 } else if (this.rootElement.classList.contains(classNames.isFilterSmscode)) { 3132 formType = this.FORM_TYPE.SMS_CODE; 3133 } else if (this.rootElement.classList.contains(classNames.isFilterAutoSignUp)) { 3134 formType = this.FORM_TYPE.ASU; 3135 } 3136 3137 return formType; 3138 }; 3139 3140 SignIn.getDisalbedIds = function () { 3141 var items = document.querySelectorAll('.' + classNames.itemPassword + ', .' + classNames.itemSMSCode); 3142 3143 Array.prototype.forEach.call(items, function (item) { 3144 var disabledFormElements = item.querySelectorAll('input:disabled, select:disabled, textarea:disabled'); 3145 3146 Array.prototype.forEach.call(disabledFormElements, function (disabledFormElement) { 3147 SignIn.disabledIds.push(disabledFormElement.id); 3148 }); 3149 }); 3150 }; 3151 3152 SignIn.getFilterFields = function (type) { 3153 var fields = []; 3154 3155 switch (type) { 3156 case 'password': 3157 fields = document.querySelectorAll('.' + classNames.itemPassword); 3158 break; 3159 case 'smscode': 3160 fields = document.querySelectorAll('.' + classNames.itemSMSCode); 3161 break; 3162 case 'asu': 3163 fields = document.querySelectorAll('.' + classNames.itemAutoSignUp); 3164 break; 3165 default: 3166 break; 3167 } 3168 3169 return fields; 3170 }; 3171 3172 SignIn.disableFields = function (type) { 3173 var fields = this.getFilterFields(type); 3174 3175 if (!fields.length) { 3176 return; 3177 } 3178 3179 Array.prototype.forEach.call(fields, function (item) { 3180 var formElements = item.querySelectorAll('input, select, textarea'); 3181 3182 Array.prototype.forEach.call(formElements, function (formElement) { 3183 formElement.disabled = true; 3184 }); 3185 }); 3186 }; 3187 3188 SignIn.enableFields = function (type, isAll) { 3189 var fields = this.getFilterFields(type); 3190 3191 Array.prototype.forEach.call(fields, function (field) { 3192 var formElements = field.querySelectorAll('input, select, textarea'); 3193 3194 Array.prototype.forEach.call(formElements, function (formElement) { 3195 if (isAll) { 3196 formElement.disabled = false; 3197 } else if (SignIn.disabledIds.indexOf(formElement.id) === -1) { 3198 formElement.disabled = false; 3199 } 3200 }); 3201 }); 3202 }; 3203 3204 SignIn.runValidation = function (e) { 3205 var BlankFieldValidator = win.KeyenceForm.BlankFieldValidator; 3206 var preForm = win.MultiStepForm.PreForm; 3207 var formInfo = preForm.getFormInfo(); 3208 var formType = KEYENCE.Form.FormFilter.General.getFormType(); 3209 var targetInput = doc.querySelector('input[name="' + formInfo.name + '"]'); 3210 3211 if (e.data === AnalyticsViews.Utility.messageNames.nextForm) { 3212 if (targetInput) { 3213 if (targetInput.classList.contains('js-check-blank') && BlankFieldValidator.isBlank(targetInput)) { 3214 return; 3215 } 3216 } 3217 3218 if (formType === KEYENCE.Form.FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 3219 if (preForm.$formCheckMobileNumber.hasClass('js-checkMobileNumberFormat')) { 3220 KeyenceForm.MobileNumberValidator.checkFormat(formInfo.countryCode, formInfo.mobileNumber ).done(function (status) { 3221 if (!status.message) { 3222 win.MultiStepForm.getMobileNumberStatus(formInfo.countryCode, formInfo.mobileNumber).done(function (status) { 3223 if (!status.message) { 3224 SignIn.changeAsuFilterClass(status.isRegistered, formInfo, preForm.isAutoSignupUser(status)); 3225 } 3226 }); 3227 } 3228 }); 3229 } else { 3230 win.MultiStepForm.getMobileNumberStatus(formInfo.countryCode, formInfo.mobileNumber).done(function (status) { 3231 if (!status.message) { 3232 SignIn.changeAsuFilterClass(status.isRegistered, formInfo, PreForm.isAutoSignupUser(status)); 3233 } 3234 }); 3235 } 3236 } 3237 } 3238 }; 3239 3240 SignIn.changeAsuFilterClass = function (isRegistered, formInfo, isAutoSignup) { 3241 if (typeof isRegistered !== 'boolean' || !formInfo) { 3242 return; 3243 } 3244 3245 if (isAutoSignup) { 3246 SignIn.rootElement.classList.add(classNames.isFilterAutoSignUp
3246); 3247 SignIn.rootElement.classList.remove(classNames.isFilterPassword); 3248 SignIn.rootElement.classList.remove(classNames.isFilterSmscode); 3249 $('#' + win.MultiStepForm.SignIn.idNames.loginPassword).prop('disabled', true); 3250 $('#' + win.MultiStepForm.SignIn.idNames.loginVerificationCode).prop('disabled', false); 3251 $('#' + win.MultiStepForm.SignIn.idNames.registerLoginPassword).prop('disabled', false); 3252 } 3253 }; 3254 3255 return SignIn; 3256 }()); 3257 3258 FormFilter.SendEmail = (function () { 3259 var classNames = { 3260 root: 'js-formFilterSendEmail', 3261 isFilterSignin: 'is-filter-signin', 3262 isFilterAutoSignup: 'is-filter-autoSignUp', 3263 }; 3264 3265 var SendEmail = { 3266 classNames: classNames, 3267 rootElement: null, 3268 }; 3269 3270 SendEmail.FORM_TYPE = { 3271 SIGNIN: 'signin', 3272 ASU: 'autoSignup', 3273 }; 3274 3275 SendEmail.init = function () { 3276 this.root = doc.querySelector(this.classNames.root); 3277 } 3278 3279 SendEmail.changeFilterClass = function (triggerId) { 3280 var multiStepForm = win.MultiStepForm; 3281 3282 if (typeof triggerId !== 'string' || !triggerId) { 3283 return; 3284 } 3285 3286 if (triggerId === multiStepForm.SignIn.idNames.btnCheckSendEmail) { 3287 multiStepForm.SendEmail.root.classList.add(classNames.isFilterSignin); 3288 multiStepForm.SendEmail.root.classList.remove(classNames.isFilterAutoSignup); 3289 } else if (triggerId === multiStepForm.SignIn.idNames.asuSendMailButton) { 3290 multiStepForm.SendEmail.root.classList.add(classNames.isFilterAutoSignup); 3291 multiStepForm.SendEmail.root.classList.remove(classNames.isFilterSignin); 3292 } 3293 }; 3294 3295 return SendEmail; 3296 }()); 3297 3298 return FormFilter; 3299 }()); 3300 3301 KEYENCE.Form.InputInterlock = (function () { 3302 var classNames = { 3303 trigger: 'js-input-interlock', 3304 group: 'js-input-interlockGroup', 3305 item: 'js-input-interlockItem', 3306 isHide: 'is-hide' 3307 }; 3308 3309 var InputInterlock = { 3310 triggerElements: null, 3311 classNames: classNames 3312 }; 3313 3314 InputInterlock.init = function () { 3315 var self = this; 3316 3317 $(doc).off('input.formInterlock').on('input.formInterlock', '.' + classNames.trigger, this.onInput.bind(self)); 3318 }; 3319 3320 InputInterlock.onInput = function (event) { 3321 var target = event.currentTarget; 3322 var targetIdList = this.getTargetIdListFromTrigger(target); 3323 3324 if (!targetIdList.length) { 3325 return; 3326 } 3327 3328 if (target.value.length > 0) { 3329 targetIdList.forEach(function (id) { 3330 InputInterlock.changeRelatedInputStatus(document.getElementById(id), 'disable'); 3331 }); 3332 } else if (target.value.length === 0) { 3333 targetIdList.forEach(function (id) { 3334 InputInterlock.changeRelatedInputStatus(document.getElementById(id), 'enable'); 3335 }); 3336 } 3337 }; 3338 3339 InputInterlock.changeRelatedInputStatus = function (targetElement, status) { 3340 if (!targetElement || typeof status !== 'string') { 3341 return; 3342 } 3343 3344 if (status === 'enable') { 3345 targetElement.disabled = false; 3346 3347 if (targetElement.tagName.toLowerCase() === 'button') { 3348 targetElement.removeAttribute('aria-disabled'); 3349 } 3350 3351 InputInterlock.toggleItems(targetElement, 'show'); 3352 } else if (status === 'disable') { 3353 targetElement.disabled = true; 3354 3355 if (targetElement.name) { 3356 win.MultiStepForm.clearInputError(targetElement.name, true); 3357 } 3358 3359 if (targetElement.tagName.toLowerCase() === 'button') { 3360 targetElement.setAttribute('aria-disabled', true); 3361 } 3362 3363 InputInterlock.toggleItems(targetElement, 'hide'); 3364 } 3365 }; 3366 3367 InputInterlock.getTargetIdListFromTrigger = function (target) { 3368 var idList = []; 3369 3370 if (target && target.dataset.interlock) { 3371 idList = target.dataset.interlock.split(','); 3372 } 3373 3374 return idList; 3375 }; 3376 3377 InputInterlock.toggleItems = function (targetInputItem, status) { 3378 var $interlockGroup; 3379 var $targetItems; 3380 3381 if (!targetInputItem || typeof status !== 'string') { 3382 return; 3383 } 3384 3385 $interlockGroup = $(targetInputItem).closest('.' + classNames.group); 3386 3387 if ($interlockGroup.length) { 3388 $targetItems = $interlockGroup.find('.' + classNames.item); 3389 } 3390 3391 if (!$targetItems || !$targetItems.length) { 3392 return 3393 } 3394 3395 if (status === 'hide') { 3396 $targetItems.addClass(classNames.isHide); 3397 } else if (status === 'show') { 3398 $targetItems.removeClass(classNames.isHide); 3399 } 3400 }; 3401 3402 return InputInterlock; 3403 }()); 3404 3405 KEYENCE.Form.SMSCodeButton = (function () { 3406 var classNames = {
3407 trigger: 'js-sendSMSCode', 3408 text: 'js-sendSMSCode-text', 3409 resendCount: 'js-sendSMSCode-resendCount', 3410 resendCountNumber: 'js-sendSMSCode-resendCountNumber', 3411 isHide: 'is-hide' 3412 }; 3413 3414 var urls = { 3415 createVerificationCode: '/ajax/registrationAjax/createVerificationCode/', 3416 getVerificationCodeRemainingTime: '/ajax/registrationAjax/getVerificationCodeRemainingTime/', 3417 }; 3418 3419 var SMSCodeButton = { 3420 urls: urls, 3421 classNames: classNames, 3422 defaultResendTime: 10, 3423 timeIds: {}, 3424 targetButtons: { 3425 preformMobile: 'js-form-btnCheckMobileRegistered', 3426 mobile: 'getCode', 3427 email: 'getEmailCode', 3428 }, 3429 }; 3430 3431 SMSCodeButton.init = function () { 3432 var self = this; 3433 3434 $(doc).off('click.formSMSCodeButton').on('click.formSMSCodeButton', '.' + classNames.trigger, self.onclick.bind(self)); 3435 this.showResendRemainingTime(); 3436 }; 3437 3438 SMSCodeButton.replaceButtonText = function (button, text) { 3439 var textElement; 3440 3441 if (!button || typeof text !== 'string') { 3442 return; 3443 } 3444 3445 textElement = button.querySelector('.' + classNames.text); 3446 3447 if (!textElement) { 3448 return; 3449 } 3450 3451 textElement.textContent = text; 3452 }; 3453 3454 SMSCodeButton.toggleResendCount = function (button, status) { 3455 var countContent; 3456 3457 if (!button || typeof status !== 'string') { 3458 return; 3459 } 3460 3461 countContent = button.querySelector('.' + classNames.resendCount); 3462 3463 if (!countContent) { 3464 return; 3465 } 3466 3467 if (status === 'show') { 3468 countContent.classList.remove(classNames.isHide); 3469 } else if (status === 'hide') { 3470 countContent.classList.add(classNames.isHide); 3471 } 3472 }; 3473 3474 SMSCodeButton.insertResetCountNumber = function (button, number) { 3475 var numberElement; 3476 3477 if (!button || typeof number !== 'number') { 3478 return; 3479 } 3480 3481 numberElement = button.querySelector('.' + classNames.resendCountNumber); 3482 3483 if (!numberElement) { 3484 return; 3485 } 3486 3487 numberElement.textContent = number; 3488 }; 3489 3490 SMSCodeButton.removeResetCountNumber = function (button) { 3491 var numberElement; 3492 3493 if (!button) { 3494 return; 3495 } 3496 3497 numberElement = button.querySelector('.' + classNames.resendCountNumber); 3498 3499 if (!numberElement) { 3500 return; 3501 } 3502 3503 numberElement.textContent = ''; 3504 }; 3505 3506 SMSCodeButton.onclick = function (event) { 3507 var button = event.currentTarget; 3508 var MultiStepForm = window.MultiStepForm; 3509 var input = SMSCodeButton.getInput(button); 3510 var mobileNumberInfo = SMSCodeButton.getMobileNumberInfo(button); 3511 3512 if ( 3513 !input || 3514 ( 3515 typeof mobileNumberInfo.number !== 'string' || 3516 typeof mobileNumberInfo.countryId !== 'string' 3517 ) 3518 ) { 3519 return; 3520 } 3521 3522 SMSCodeButton.disableButton(button); 3523 SMSCodeButton.replaceButtonText(button, button.getAttribute('data-resend-text'));
3524 SMSCodeButton.toggleResendCount(button, 'show'); 3525 3526 SMSCodeButton.createVerificationCode( 3527 mobileNumberInfo.countryId, 3528 mobileNumberInfo.number 3529 ).done(function (status) { 3530 if (status.message && (MultiStepForm && MultiStepForm.insertErrorText)) { 3531 MultiStepForm.insertErrorText(input.name, status.message); 3532 } else { 3533 MultiStepForm.clearInputError(input.name, true); 3534 } 3535 }).fail(function (jqXHR, textStatus, errorThrown) { 3536 if (jqXHR.status !== 200) { 3537 MultiStepForm.insertErrorText(input.name, kpi_translation.ServerConnectErrorMessage); 3538 3539 return; 3540 } 3541 3542 MultiStepForm.asyncErrorHundler(jqXHR.status, textStatus); 3543 }); 3544 3545 SMSCodeButton.countResendTime(button); 3546 }; 3547 3548 SMSCodeButton.countResendTime = function (button, argCount) { 3549 var countNum = typeof argCount === 'number' ? argCount : this.getResendTime(button); 3550 3551 SMSCodeButton.insertResetCountNumber(button, countNum); 3552 3553 SMSCodeButton.timeIds[button.id] = {}; 3554 3555 SMSCodeButton.timeIds[button.id].timeId = win.setInterval(function () { 3556 countNum--; 3557 SMSCodeButton.timeIds[button.id].timerCount = countNum; 3558 3559 if (countNum === 0) { 3560 SMSCodeButton.enableButton(button); 3561 SMSCodeButton.toggleResendCount(button, 'hide'); 3562 SMSCodeButton.removeResetCountNumber(button); 3563 3564 if (SMSCodeButton.timeIds[button.id] && typeof SMSCodeButton.timeIds[button.id].timeId === 'number') { 3565 win.clearInterval(SMSCodeButton.timeIds[button.id].timeId); 3566 } 3567 3568 delete SMSCodeButton.timeIds[button.id]; 3569 3570 return; 3571 } 3572 3573 SMSCodeButton.insertResetCountNumber(button, countNum); 3574 }, 1000); 3575 }; 3576 3577 SMSCodeButton.getMobileNumberInfo = function (button) { 3578 var id; 3579 var mobileCountrySelectId; 3580 var mobileCountrySelectElem; 3581 var mobileNumberInputId; 3582 var mobileNumberInputElem; 3583 var info = {}; 3584 3585 if (!button) { 3586 return ''; 3587 } 3588 3589 id = button.id; 3590 3591 if (id === 'loginVerificationCode-getCode') { 3592 mobileNumberInputId = 'loginMobileNumber'; 3593 3594 if (doc.getElementById('checkCountryNumber')) { 3595 mobileCountrySelectId = 'checkCountryNumber'; 3596 } else { 3597 mobileCountrySelectId = 'loginCountryNumber'; 3598 } 3599 } else if (button.id === 'suz_verificationCode-getCode') { 3600 mobileNumberInputId = 'suz_mobileNumber'; 3601 3602 if (doc.getElementById('suz_mobileCountryID')) { 3603 mobileCountrySelectId = 'suz_mobileCountryID'; 3604 } else { 3605 mobileCountrySelectId = 'checkCountryNumber'; 3606 } 3607 } else if (id === 'remindVerificationCode-getCode') { 3608 mobileCountrySelectId = 'remindCountryNumber'; 3609 mobileNumberInputId = 'remindMobileNumber'; 3610 } 3611 3612 mobileCountrySelectElem = doc.getElementById(mobileCountrySelectId); 3613 mobileNumberInputElem = doc.getElementById(mobileNumberInputId); 3614 3615 if (mobileCountrySelectElem && mobileNumberInputElem) { 3616 info.number = mobileNumberInputElem.value; 3617 info.countryId = mobileCountrySelectElem.value; 3618 } 3619 3620 return info; 3621 }; 3622 3623 SMSCodeButton.getInput = function (button) { 3624 var $group; 3625 var $input; 3626 var $input; 3627 3628 if (button) { 3629 $group = $(button).closest('.m-form-layout__item'); 3630 3631 if ($group && $group.length) { 3632 $input = $group.find('input'); 3633 } 3634 3635 if ($input && $input.length) { 3636 return $input.get(0); 3637 } 3638 } 3639 3640 return null; 3641 }; 3642 3643 SMSCodeButton.getResendTime = function (buttonElement) { 3644 var resendTime = ''; 3645 3646 if (buttonElement) { 3647 resendTime = buttonElement.getAttribute('data-timeout'); 3648 3649 if (typeof resendTime === 'string') { 3650 resendTime = win.parseInt(resendTime, 10); 3651 } else { 3652 resendTime = SMSCodeButton.defaultResendTime; 3653 } 3654 } 3655 3656 return resendTime; 3657 }; 3658 3659 SMSCodeButton.createVerificationCode = function (mobileCountryId, mobileNumber) { 3660 var deferred = new $.Deferred(); 3661 var options; 3662 var url; 3663 3664 if (typeof mobileCountryId !== 'string' || typeof mobileNumber !== 'string') { 3665 return deferred.reject(); 3666 } 3667 3668 url = win.suz_getCurrentDomain() + this.urls.createVerificationCode; 3669 3670 options = { 3671 url: url, 3672 data: { 3673 mobileCountryId: mobileCountryId, 3674 mobileNumber: mobileNumber 3675 }, 3676 dataType: 'jsonp', 3677 jsonp: 'callback', 3678 scriptCharset: 'UTF-8', 3679 }; 3680 3681 $.ajax(options).done(function (data) { 3682 deferred.resolve(data); 3683 }).fail(function (jqXHR, textStatus, errorThrown) { 3684 deferred.reject(jqXHR, textStatus, errorThrown); 3685 }); 3686 3687 return deferred.promise(); 3688 }; 3689 3690 SMSCodeButton.enableButton = function (button) { 3691 if (button) { 3692 button.disabled = false; 3693 button.setAttribute('aria-disabled', false); 3694 } 3695 }; 3696 3697 SMSCodeButton.disableButton = function (button) { 3698 if (button) { 3699 button.disabled = true; 3700 button.setAttribute('aria-disabled', true); 3701 } 3702 }; 3703 3704 SMSCodeButton.showResendRemainingTime = function () { 3705 var self = this; 3706 var mobileVerificationButtons = null; 3707 var emailVerificationButtons = null 3708 3709 if (!document.querySelectorAll('.' + classNames.trigger).length) { 3710 return; 3711 } 3712 3713 mobileVerificationButtons = document.querySelectorAll(`button[id$='-${this.targetButtons.mobile}'], #${this.targetButtons.preformMobile}`); 3714 emailVerificationButtons = document.querySelectorAll(`button[id$='-${this.targetButtons.email}']`); 3715 3716 SMSCodeButton.getVerificationCodeRemainingTime().done(function (status) { 3717 if (status.errorFlg === '1' 3718 || (status.smsRemainingTime === 0 3719 && status.mailRemainingTime === 0) 3720 ) { 3721 return; 3722 } else { 3723 if (status.smsRemainingTime !== 0 3724 && mobileVerificationButtons.length) { 3725 mobileVerificationButtons.forEach(function (button) { 3726 self.setResendRemainingTime(button, status.smsRemainingTime); 3727 }); 3728 } 3729 3730 if (status.mailRemainingTime !== 0 3731 && emailVerificationButtons.length) { 3732 emailVerificationButtons.forEach(function (button) { 3733 self.setResendRemainingTime(button, status.mailRemainingTime); 3734 }); 3735 } 3736 } 3737 }).fail(function (jqXHR, textStatus, errorThrown) { 3738 console.error('Get Verification Code Remaining Time Error'); 3739 }); 3740 }; 3741 3742 SMSCodeButton.getVerificationCodeRemainingTime = function () { 3743 var deferred = new $.Deferred(); 3744 var options = {}; 3745 var url = ''; 3746 3747 url = win.suz_getCurrentDomain() + this.urls.getVerificationCodeRemainingTime; 3748 3749 options = { 3750 url: url, 3751 }; 3752 3753 $.ajax(options).done(function (data) { 3754 deferred.resolve(data); 3755 }).fail(function (jqXHR, textStatus, errorThrown) { 3756 deferred.reject(jqXHR, textStatus, errorThrown); 3757 }); 3758 3759 return deferred.promise(); 3760 }; 3761 3762 SMSCodeButton.setResendRemainingTime = function (button, remainingTime) { 3763 if ((typeof button !== 'object' || !button) 3764 || (typeof remainingTime !== 'number' || remainingTime <= 0)) { 3765 return; 3766 } 3767 3768 if (button.id) { 3769 this.disableButton(button); 3770 this.replaceButtonText(button, button.getAttribute('data-resend-text'));
3771 this.toggleResendCount(button, 'show'); 3772 this.countResendTime(button, remainingTime); 3773 } 3774 }; 3775 3776 return SMSCodeButton; 3777 }()); 3778 3779 KEYENCE.Form.MobileNumberEdit = (function () { 3780 var idNames = { 3781 beforeMobileCountryID: 'suz_beforeMobileCountryID', 3782 beforeMobileNumberValue: 'suz_beforeMobileNumberValue', 3783 inputVerificationCode: 'suz_verificationCode', 3784 buttonGetVerificationCode: 'suz_verificationCode-getCode' 3785 }; 3786 3787 var MobileNumberEdit = { 3788 inputVerificationCode: null, 3789 buttonGetVerificationCode: null 3790 }; 3791 3792 MobileNumberEdit.init = function () { 3793 if (this.isEditProfilePage()) { 3794 this.attachInputMobileNumberEvent(); 3795 this.attachChangeCountryID(); 3796 this.toggleStatus(); 3797 } 3798 }; 3799 3800 MobileNumberEdit.isEditProfilePage = function () { 3801 var beforeMobileCountryInput = document.getElementById(idNames.beforeMobileCountryID); 3802 var beforeMobileNumberValue = document.getElementById(idNames.beforeMobileNumberValue); 3803 3804 if (beforeMobileCountryInput || beforeMobileNumberValue) { 3805 return true; 3806 } 3807 3808 return false; 3809 }; 3810 3811 MobileNumberEdit.attachInputMobileNumberEvent = function () { 3812 var input = document.getElementById('suz_mobileNumber'); 3813 3814 input.addEventListener('input', function () { 3815 MobileNumberEdit.toggleStatus(); 3816 }); 3817 }; 3818 3819 MobileNumberEdit.attachChangeCountryID = function () { 3820 var select = document.getElementById('suz_mobileCountryID'); 3821 3822 select.addEventListener('change', function () { 3823 MobileNumberEdit.toggleStatus(); 3824 }); 3825 }; 3826 3827 MobileNumberEdit.toggleStatus = function () { 3828 var verificationCodeInput = document.getElementById('suz_verificationCode'); 3829 var verificationCodeButton = document.getElementById('suz_verificationCode-getCode'); 3830 var afterValues; 3831 var beforeValues; 3832 3833 if (!verificationCodeInput || !verificationCodeButton) { 3834 return; 3835 } 3836 3837 afterValues = this.getAfterValues(); 3838 beforeValues = this.getBeforeValues(); 3839 3840 if ( 3841 (afterValues.mobileNumber === beforeValues.mobileNumber) && 3842 (afterValues.countryId === beforeValues.countryId) 3843 ) { 3844 verificationCodeInput.disabled = true; 3845 verificationCodeButton.disabled = true; 3846 verificationCodeButton.setAttribute('aria-disabled', true); 3847 } else { 3848 verificationCodeInput.disabled = false; 3849 verificationCodeButton.disabled = false; 3850 verificationCodeButton.setAttribute('aria-disabled', false); 3851 } 3852 }; 3853 3854 MobileNumberEdit.getBeforeValues = function () { 3855 var values = { 3856 mobileNumber: null, 3857 countryId: null 3858 }; 3859 var beforeMobileNumberElem = doc.getElementById('suz_beforeMobileNumber'); 3860 var beforeCountryElem = doc.getElementById('suz_beforeMobileCountryID'); 3861 3862 if (beforeMobileNumberElem && beforeCountryElem) { 3863 values.mobileNumber = beforeMobileNumberElem.value; 3864 values.countryId = beforeCountryElem.value; 3865 } 3866 3867 return values; 3868 }; 3869 3870 MobileNumberEdit.getAfterValues = function () { 3871 var values = { 3872 mobileNumber: null, 3873 countryId: null 3874 }; 3875 var mobileNumberElem = doc.getElementById('suz_mobileNumber'); 3876 var countryElem = doc.getElementById('suz_mobileCountryID'); 3877 3878 if (mobileNumberElem && countryElem) { 3879 values.mobileNumber = mobileNumberElem.value; 3880 values.countryId = countryElem.value; 3881 } 3882 3883 return values; 3884 }; 3885 3886 return MobileNumberEdit; 3887 }()); 3888 3889 KEYENCE.Form.BlankFieldValidator = (function () { 3890 var MultiStepForm = null; 3891 3892 var PatternValidator = null; 3893 var AvailableValidator = null; 3894 3895 var names = { 3896 passwordAssistanceActionForm: 'user_passwordAssistanceActionForm', 3897 passwordAssistanceResetForm: 'user_passwordAssistance_resetPasswordActionForm', 3898 withdrawActionForm: 'user_profile_withdrawActionForm', 3899 reloginActionForm: 'user_reloginActionForm', 3900 loginActionForm: 'user_loginActionForm', 3901 unsubscribeConfirmActionForm: 'enews_unsubscribeConfirmActionForm', 3902 }; 3903 3904 var classNames = {
3905 trigger: 'js-check-blank', 3906 status: 'is-error-blank' 3907 }; 3908 3909 var config = { 3910 isClickedContinueButton: false, 3911 }; 3912 3913 var BlankFieldValidator = { 3914 targetForm: null, 3915 formSelector: 'form[name="' + names.passwordAssistanceActionForm + '"], ' + 3916 'form[name="' + names.passwordAssistanceResetForm + '"], ' + 3917 'form[name="' + names.withdrawActionForm + '"], ' + 3918 'form[name="' + names.reloginActionForm + '"], ' + 3919 'form[name="' + names.loginActionForm + '"], ' + 3920 'form[name="' + names.unsubscribeConfirmActionForm + '"]', 3921 fields: null, 3922 classNames: classNames, 3923 config: config, 3924 }; 3925 3926 BlankFieldValidator.init = function () { 3927 var fields; 3928 3929 MultiStepForm = window.MultiStepForm; 3930 this.targetForm = doc.querySelector(this.formSelector); 3931 this.multiStepForm = doc.querySelector('#' + MultiStepForm.idNames.trigger); 3932 fields = doc.querySelectorAll('.' + classNames.trigger); 3933 PatternValidator = win.KeyenceForm.PatternMatchValidator; 3934 AvailableValidator = win.KeyenceForm.AvailableValidator; 3935 3936 if ( 3937 (this.targetForm && fields.length) || 3938 (this.multiStepForm && fields.length) 3939 ) { 3940 this.attachBlurEvent(); 3941 } 3942 }; 3943 3944 BlankFieldValidator.isActionPwdAssistance = function () { 3945 var actionValue = $(this.targetForm).attr('action'); 3946 3947 if (new RegExp(MultiStepForm.urls.actionPwdAssistance).test(actionValue)) { 3948 return true; 3949 } 3950 3951 return false; 3952 }; 3953 3954 BlankFieldValidator.attachBlurEvent = function () { 3955 $(this.formSelector + ', #' + MultiStepForm.idNames.trigger).on('blur', '.' + classNames.trigger, function () { 3956 var MobileNumberValidator = win.KeyenceForm.MobileNumberValidator; 3957 var FilledFieldValidator = win.KeyenceForm.filledFieldValidator; 3958 var ControlErrorDisplay = win.KeyenceForm.ControlErrorDisplay; 3959 var field = this; 3960 3961 if (!ControlErrorDisplay.isTriggerClicked(field)) { 3962 return; 3963 } 3964 3965 if (((field.id === 'checkRegistered') || (field.id === 'checkMobileNumber')) 3966 && !config.isClickedContinueButton) { 3967 3968 if (BlankFieldValidator.isBlank(field)) { 3969 MultiStepForm.clearInputError(field.name, true); 3970 field.classList.add(classNames.status); 3971 field.classList.remove(MobileNumberValidator.classNames.status); 3972 field.classList.remove(PatternValidator.classNames.status); 3973 AvailableValidator.removeUnavailableStatus(field.name); 3974 } else if (!field.classList.contains(PatternValidator.classNames.status) 3975 && !field.classList.contains(MobileNumberValidator.classNames.status)) { 3976 MultiStepForm.clearInputError(field.name, true); 3977 field.classList.remove(classNames.status); 3978 } 3979 3980 return; 3981 } 3982 3983 if (FilledFieldValidator.config.notMultiStepForm 3984 && !FilledFieldValidator.config.isFirstPointerDown 3985 && (field.id === 'loginUserName' || field.id === 'js-reset-EmailAddress') 3986 ) { 3987 setTimeout(function () { 3988 if (FilledFieldValidator.config.isFirstPointerDown) { 3989 if (BlankFieldValidator.isBlank(field)) { 3990 MultiStepForm.insertErrorText(field.name, 'data-message-required'); 3991 field.classList.add(classNames.status); 3992 field.classList.remove(MobileNumberValidator.classNames.status); 3993 field.classList.remove(PatternValidator.classNames.status); 3994 AvailableValidator.removeUnavailableStatus(field.name); 3995 } else if (!field.classList.contains(PatternValidator.classNames.status) 3996 && !field.classList.contains(MobileNumberValidator.classNames.status)) { 3997 MultiStepForm.clearInputError(field.name, true); 3998 field.classList.remove(classNames.status); 3999 } 4000 } 4001 }, 0); 4002 4003 return; 4004 } 4005 4006 if (BlankFieldValidator.isBlank(field)) { 4007 MultiStepForm.insertErrorText(field.name, 'data-message-required'); 4008 field.classList.add(classNames.status); 4009 field.classList.remove(MobileNumberValidator.classNames.status); 4010 field.classList.remove(PatternValidator.classNames.status); 4011 AvailableValidator.removeUnavailableStatus(field.name); 4012 } else if (!field.classList.contains(PatternValidator.classNames.status) 4013 && !field.classList.contains(MobileNumberValidator.classNames.status)) { 4014 MultiStepForm.clearInputError(field.name, true); 4015 field.classList.remove(classNames.status); 4016 } 4017 }); 4018 }; 4019 4020 BlankFieldValidator.isBlank = function (field) { 4021 if (field.value === '' && !field.disabled) { 4022 return true; 4023 } 4024 4025 return false; 4026 }; 4027 4028 BlankFieldValidator.validateFieldAll = function (fieldList) { 4029 var hasError = false; 4030 4031 if (!fieldList || !fieldList.length) { 4032 return hasError; 4033 } 4034 4035 Array.prototype.forEach.call(fieldList, function (field, index) { 4036 if ($(field).is(':visible')) { 4037 if (BlankFieldValidator.isBlank(field)) { 4038 MultiStepForm.insertErrorText(field.name, 'data-message-required'); 4039 field.classList.add(classNames.status); 4040 4041 hasError = true; 4042 } else { 4043 MultiStepForm.clearInputError(field.name, true); 4044 field.classList.remove(classNames.status); 4045 } 4046 } 4047 }); 4048 4049 return hasError; 4050 }; 4051 4052 BlankFieldValidator.asyncValidateFieldAll = function (fieldList) { 4053 var deferred = new $.Deferred(); 4054 var hasError = false; 4055 var lastIndex; 4056 4057 if (!fieldList || !fieldList.length) { 4058 return deferred.resolve(hasError); 4059 } 4060 4061 lastIndex = fieldList.length - 1; 4062 4063 Array.prototype.forEach.call(fieldList, function (field, index) { 4064 if ($(field).is(':visible')) { 4065 if (BlankFieldValidator.isBlank(field)) { 4066 MultiStepForm.insertErrorText(field.name, 'data-message-required'); 4067 field.classList.add(classNames.status); 4068 4069 hasError = true; 4070 } else { 4071 MultiStepForm.clearInputError(field.name, true); 4072 field.classList.remove(classNames.status); 4073 } 4074 } 4075 4076 if (lastIndex === index) { 4077 deferred.resolve(hasError); 4078 } 4079 }); 4080 4081 return deferred.promise(); 4082 }; 4083
4084 return BlankFieldValidator; 4085 }()); 4086 4087 KEYENCE.Form.PatternMatchValidator = (function () { 4088 var MultiStepForm = null; 4089 4090 var BlankFieldValidator = null; 4091 var AvailableValidator = null; 4092 4093 var names = { 4094 passwordAssistanceActionForm: 'user_passwordAssistanceActionForm', 4095 passwordAssistanceResetForm: 'user_passwordAssistance_resetPasswordActionForm', 4096 withdrawActionForm: 'user_profile_withdrawActionForm', 4097 reloginActionForm: 'user_reloginActionForm', 4098 loginActionForm: 'user_loginActionForm', 4099 }; 4100 4101 var classNames = { 4102 trigger: 'js-check-pattern', 4103 status: 'is-error-pattern', 4104 replaceValueTrigger: 'js-replaceValueWithCorrect', 4105 }; 4106 4107 var PatternMatchValidator = { 4108 targetForm: null, 4109 formSelector: 'form[name="' + names.passwordAssistanceActionForm + '"], ' + 4110 'form[name="' + names.passwordAssistanceResetForm + '"], ' + 4111 'form[name="' + names.withdrawActionForm + '"], ' + 4112 'form[name="' + names.reloginActionForm + '"], ' + 4113 'form[name="' + names.loginActionForm + '"]', 4114 classNames: classNames, 4115 }; 4116 4117 PatternMatchValidator.init = function () { 4118 var fields; 4119 4120 MultiStepForm = win.MultiStepForm; 4121 this.targetForm = doc.querySelector(this.formSelector); 4122 this.multiStepForm = doc.querySelector('#' + MultiStepForm.idNames.trigger); 4123 fields = doc.querySelectorAll('.' + classNames.trigger); 4124 BlankFieldValidator = win.KeyenceForm.BlankFieldValidator; 4125 AvailableValidator = win.KeyenceForm.AvailableValidator; 4126 4127 if ( 4128 (this.targetForm && fields.length) || 4129 (this.multiStepForm && fields.length) 4130 ) { 4131 this.attachBlurEvent(); 4132 } 4133 }; 4134 4135 PatternMatchValidator.attachBlurEvent = function () { 4136 $(this.formSelector + ', #' + MultiStepForm.idNames.trigger).on('blur', '.' + classNames.trigger, function () { 4137 var field = this; 4138 var ControlErrorDisplay = win.KeyenceForm.ControlErrorDisplay; 4139 4140 if (!ControlErrorDisplay.isTriggerClicked(field)) { 4141 return; 4142 } 4143 4144 if (BlankFieldValidator.isBlank(field)) { 4145 return; 4146 } else { 4147 field.classList.remove(BlankFieldValidator.classNames.status); 4148 } 4149 4150 AvailableValidator.runValidate(field.name, true).always(function (field) { 4151 PatternMatchValidator.updateFieldStatus(field); 4152 AvailableValidator.changeDisplayNoteText(field.name); 4153 }); 4154 }); 4155 }; 4156 4157 PatternMatchValidator.validateFieldAll = function (fieldList) { 4158 var deferred = new $.Deferred(); 4159 var hasError = false; 4160 var lastIndex = 0; 4161 4162 if (!fieldList || !fieldList.length) { 4163 return deferred.resolve(hasError); 4164 } 4165 4166 lastIndex = fieldList.length - 1; 4167 4168 Array.prototype.forEach.call(fieldList, function (field, index) { 4169 if ($(field).is(':hidden') || BlankFieldValidator.isBlank(field)) { 4170 if (lastIndex === index) { 4171 deferred.resolve(hasError); 4172 } 4173 4174 return false; 4175 } 4176 4177 if (field.dataset.formatPattern !== 'new-password') { 4178 PatternMatchValidator.updateFieldStatus(field); 4179 4180 if (field.classList.contains(classNames.status)) { 4181 hasError = true; 4182 } 4183 4184 if (lastIndex === index) { 4185 deferred.resolve(hasError); 4186 } 4187 4188 return false; 4189 } else { 4190 PatternMatchValidator.checkPasswordErrorMessage($(field)).done(function (status) { 4191 if (status.message) { 4192 MultiStepForm.insertErrorText(field.name, status.message); 4193 field.classList.add(classNames.status); 4194 4195 hasError = true; 4196 } else { 4197 MultiStepForm.clearInputError(field.name, true); 4198 field.classList.remove(classNames.status); 4199 } 4200 4201 if (lastIndex === index) { 4202 deferred.resolve(hasError); 4203 } 4204 }).fail(function (err) { 4205 deferred.resolve(hasError); 4206 }); 4207 } 4208 }); 4209 4210 return deferred.promise(); 4211 }; 4212 4213 PatternMatchValidator.updateFieldStatus = function (field) { 4214 var formatPattarn = field.dataset.formatPattern; 4215 4216 if (typeof field !== 'object' || !field) { 4217 return; 4218 } 4219 4220 switch (formatPattarn) { 4221 case 'tel': 4222 PatternMatchValidator.updateTelField(field); 4223 break; 4224 case 'email': 4225 PatternMatchValidator.updateMailField(field); 4226 break; 4227 case 'smscode': 4228 PatternMatchValidator.updateSmsCodeField(field); 4229 break; 4230 case 'new-password': 4231 PatternMatchValidator.updateNewPasswordField(field); 4232 break; 4233 case 'zipCode': 4234 PatternMatchValidator.updateZipcodeField(field); 4235 break; 4236 default: 4237 break; 4238 } 4239 }; 4240 4241 PatternMatchValidator.updateTelField = function (field) { 4242 var countryID = KeyenceForm.MobileNumberValidator.getCountryIdByInput(field); 4243 4244 if (countryID !== 'CN' || field.value.length === 0 || !$(field).is(':visible')) { 4245 return; 4246 } 4247 4248 if (/^[1][0-9]{10}/.test(field.value) && field.value.length <= 32) { 4249 MultiStepForm.clearInputError(field.name, true); 4250 field.classList.remove(KeyenceForm.MobileNumberValidator.classNames.status); 4251 } else { 4252 MultiStepForm.insertErrorText(field.name, 'data-message-mobile-number-format'); 4253 field.classList.add(KeyenceForm.MobileNumberValidator.classNames.status); 4254 } 4255 }; 4256 4257 PatternMatchValidator.updateMailField = function (field) { 4258 if (/^[a-zA-Z0-9\.!#$%&'*+\/=?^_`{|}~\-]+@[a-zA-Z0-9\-]+(\.[A-Za-z0-9\-]+)+$/.test(field.value)) { 4259 MultiStepForm.clearInputError(field.name, true); 4260 field.classList.remove(classNames.status); 4261 } else { 4262 MultiStepForm.insertErrorText(field.name, 'data-message-email-address-format'); 4263 field.classList.add(classNames.status); 4264 } 4265 }; 4266 4267 PatternMatchValidator.updateSmsCodeField = function (field) { 4268 if (/^[0-9]+$/.test(field.value)) { 4269 MultiStepForm.clearInputError(field.name, true); 4270 field.classList.remove(classNames.status); 4271 } else { 4272 MultiStepForm.insertErrorText(field.name, 'data-message-verification-code-format'); 4273 field.classList.add(classNames.status); 4274 } 4275 }; 4276 4277 PatternMatchValidator.updateNewPasswordField = function (field) { 4278 PatternMatchValidator.checkPasswordErrorMessage($(field)).done(function (status) { 4279 if (status.message) { 4280 MultiStepForm.insertErrorText(field.name, status.message); 4281 field.classList.add(classNames.status); 4282 } else { 4283 MultiStepForm.clearInputError(field.name, true); 4284 field.classList.remove(classNames.status); 4285 } 4286 }).fail(function (err) { 4287 console.log(err); 4288 }); 4289 }; 4290 4291 PatternMatchValidator.updateZipcodeField = function (field) { 4292 var countryIdElement = this.getCountryValue(); 4293 var zipCodeValue = ''; 4294 4295 if (!countryIdElement) { 4296 return; 4297 } 4298 4299 if (countryIdElement === 'CA' && field.value.length !== 0 && $(field).is(':visible')) { 4300 if (/^[a-zA-Z][0-9][a-zA-Z][^a-zA-Z0-9]?[0-9][a-zA-Z][0-9]$/.test(field.value)) { 4301 zipCodeValue = field.value.slice(0, 3) + ' ' + field.value.slice(-3); 4302 } 4303 4304 if (zipCodeValue) { 4305 field.value = zipCodeValue.toUpperCase(); 4306 field.classList.remove(classNames.status); 4307 } else { 4308 MultiStepForm.insertErrorText(field.name, 'data-message-zipcode-format'); 4309 field.classList.add(classNames.status); 4310 } 4311 } else if (countryIdElement === 'CA' && field.value.length === 0 && field.classList.contains(classNames.status)) { 4312 field.classList.remove(classNames.status); 4313 } 4314 }; 4315 4316 PatternMatchValidator.checkPasswordErrorMessage = function (field) { 4317 var deferred = new $.Deferred();
4318 var val = field.val(); 4319 var requestURL = win.suz_getCurrentDomain() + '/ajax/validationAjax/customerRegistrationFieldValidator/'; 4320 4321 if (field.attr('type')==='checkbox') { 4322 if (!field.prop('checked')) { 4323 val = ""; 4324 } 4325 } 4326 4327 $.ajax({ 4328 url: requestURL, 4329 data: { 4330 fieldName : 'password', 4331 fieldValue : encodeURIComponent(val), 4332 token : $("input[name='org.apache.struts.taglib.html.TOKEN']").attr("value") 4333 }, 4334 dataType: "jsonp", 4335 jsonp: "callback", 4336 scriptCharset: "UTF-8" 4337 }).then(function (data) { 4338 deferred.resolve(data); 4339 }, 4340 function (req, stat, err) { 4341 if (req.status == 401) { 4342 win.location.href = win.suz_getCurrentDomain() + "/error/tokenError.jsp"; 4343 4344 return false; 4345 } 4346 deferred.reject(err); 4347 return false; 4348 }); 4349 4350 return deferred.promise(); 4351 }; 4352 4353 PatternMatchValidator.getCountryValue = function () { 4354 var country = doc.getElementById('suz_countryID'); 4355 var optionElements = null; 4356 var CountryValue = null; 4357 4358 if(!country) { 4359 return; 4360 } 4361 4362 optionElements = country.options; 4363 CountryValue = optionElements[country.selectedIndex].value; 4364 4365 return CountryValue; 4366 }; 4367 4368 return PatternMatchValidator; 4369 }()); 4370 4371 KEYENCE.Form.MobileNumberValidator = (function () { 4372 var MultiStepForm = null; 4373 4374 var classNames = { 4375 trigger: 'js-checkMobileNumberFormat', 4376 status: 'is-error-format' 4377 }; 4378 4379 var names = { 4380 passwordAssistanceActionForm: 'user_passwordAssistanceActionForm', 4381 passwordAssistanceResetForm: 'user_passwordAssistance_resetPasswordActionForm', 4382 withdrawActionForm: 'user_profile_withdrawActionForm', 4383 reloginActionForm: 'user_reloginActionForm', 4384 loginActionForm: 'user_loginActionForm', 4385 }; 4386 4387 var MobileNumberValidator = { 4388 targetForm: null, 4389 formSelector: 'form[name="' + names.passwordAssistanceActionForm + '"], ' + 4390 'form[name="' + names.user_passwordAssistance_resetPasswordActionForm + '"], ' + 4391 'form[name="' + names.withdrawActionForm + '"], ' + 4392 'form[name="' + names.reloginActionForm + '"], ' + 4393 'form[name="' + names.loginActionForm + '"]', 4394 classNames: classNames, 4395 multiStepForm: null 4396 }; 4397 4398 MobileNumberValidator.init = function () { 4399 var targets = doc.querySelectorAll('.' + classNames.trigger); 4400 4401 MultiStepForm = window.MultiStepForm; 4402 this.targetForm = doc.querySelector(win.KeyenceForm.CommonSubmitValidator.formSelector); 4403 this.multiStepForm = doc.querySelector('#' + MultiStepForm.idNames.trigger); 4404 4405 // if ((this.targetForm && targets.length) || (this.multiStepForm && targets.length)) { 4406 // Removed input event. To change to Lost Focus. 4407 // this.attachInputEvent(); 4408 // } 4409 }; 4410 4411 MobileNumberValidator.validateFieldAll = function (fields) { 4412 var deferred = new $.Deferred(); 4413 var hasError = false; 4414 var lastIndex; 4415 4416 if (!fields) { 4417 return deferred.resolve(hasError); 4418 } 4419 4420 lastIndex = fields.length - 1; 4421 4422 Array.prototype.forEach.call(fields, function (field, index) { 4423 var value = field.value; 4424 var name = field.name; 4425 var countryID = MobileNumberValidator.getCountryIdByInput(field); 4426 4427 if (countryID !== 'CN' || field.value.length === 0 || !$(field).is(':visible')) { 4428 if (lastIndex === index) { 4429 deferred.resolve(hasError); 4430 } 4431 4432 return false; 4433 } 4434 4435 MobileNumberValidator.checkFormat(countryID, value).done(function (data) { 4436 if (data.message) { 4437 MultiStepForm.insertErrorText(name, data.message); 4438 field.classList.add(classNames.status); 4439 4440 hasError = true; 4441 } else { 4442 MultiStepForm.clearInputError(name, true); 4443 field.classList.remove(classNames.status); 4444 } 4445 4446 if (lastIndex === index) { 4447 deferred.resolve(hasError); 4448 } 4449 }); 4450 }); 4451 4452 return deferred.promise(); 4453 }; 4454 4455 4456 MobileNumberValidator.checkFormat = function (mobileCountryId, mobileNumber) { 4457 var options; 4458 var deferred = new $.Deferred(); 4459 var url; 4460 4461 url = win.suz_getCurrentDomain() + '/ajax/registrationAjax/mobileNumberValidator/'; 4462 4463 options = { 4464 url: url, 4465 data: { 4466 mobileCountryId: mobileCountryId, 4467 mobileNumber: mobileNumber 4468 }, 4469 dataType: 'jsonp', 4470 jsonp: 'callback', 4471 scriptCharset: 'UTF-8' 4472 }; 4473 4474 $.ajax(options).done(function (data) { 4475 deferred.resolve(data); 4476 }).fail(function (jqXHR, textStatus, errorThrown) { 4477 MultiStepForm.asyncErrorHundler(jqXHR.status, textStatus); 4478 deferred.reject(jqXHR, textStatus, errorThrown); 4479 }); 4480 4481 return deferred.promise(); 4482 }; 4483 4484 MobileNumberValidator.getCountryIdByInput = function (input) { 4485 var $select = $(input).prev('.js-selectCountryNumber').find('.js-selectCountryNumber-target'); 4486 var contryId = ''; 4487 4488 if ($select.length) { 4489 contryId = $select.val(); 4490 } 4491 4492 return contryId; 4493 }; 4494 4495 MobileNumberValidator.attachInputEvent = function () { 4496 $(this.formSelector + ', #' + MultiStepForm.idNames.trigger).on('input', '.' + classNames.trigger, function () { 4497 var field = this; 4498 var countryID = MobileNumberValidator.getCountryIdByInput(field); 4499 4500 if (field.value.length === 0) { 4501 return; 4502 } 4503 4504 MobileNumberValidator.checkFormat(countryID, field.value).done(function (data) { 4505 if (!data.message) { 4506 MultiStepForm.clearInputError(field.name, true); 4507 } 4508 }); 4509 }); 4510 }; 4511 4512 return MobileNumberValidator; 4513 }()); 4514 4515 KEYENCE.Form.CommonSubmitValidator = (function () { 4516 var MultiStepForm = null; 4517 4518 var canSubmit = false; 4519 4520 var names = { 4521 passwordAssistanceActionForm: 'user_passwordAssistanceActionForm', 4522 passwordAssistanceResetForm: 'user_passwordAssistance_resetPasswordActionForm', 4523 withdrawActionForm: 'user_profile_withdrawActionForm', 4524 reloginActionForm: 'user_reloginActionForm', 4525 loginActionForm: 'user_loginActionForm', 4526 unsubscribeConfirmActionForm: 'enews_unsubscribeConfirmActionForm', 4527 }; 4528 4529 var CommonSubmitValidator = { 4530 $targetForm: null, 4531 formSelector: 'form[name="' + names.passwordAssistanceActionForm + '"], ' + 4532 'form[name="' + names.passwordAssistanceResetForm + '"], ' + 4533 'form[name="' + names.withdrawActionForm + '"], ' + 4534 'form[name="' + names.reloginActionForm + '"], ' + 4535 'form[name="' + names.loginActionForm + '"], ' + 4536 'form[name="' + names.unsubscribeConfirmActionForm + '"]', 4537 }; 4538 4539 CommonSubmitValidator.init = function () { 4540 MultiStepForm = window.MultiStepForm; 4541 this.$targetForm = $(this.formSelector); 4542 4543 if (this.$targetForm.length) { 4544 MultiStepForm.focusFirstErrorItem(this.$targetForm); 4545 this.attachSubmitEvent(); 4546 } 4547 }; 4548 4549 CommonSubmitValidator.attachSubmitEvent = function () { 4550 this.$targetForm.on('submit', this.onSubmit); 4551 }; 4552 4553 CommonSubmitValidator.onSubmit = function (event) { 4554 var FormFilter = KEYENCE.Form.FormFilter; 4555 var BlankFieldValidator = win.KeyenceForm.BlankFieldValidator; 4556 var PatternValidator = win.KeyenceForm.PatternMatchValidator; 4557 var MobileNumberValidator = win.KeyenceForm.MobileNumberValidator; 4558 var ControlErrorDisplay = win.KeyenceForm.ControlErrorDisplay; 4559 var mobileNumberFields = doc.querySelectorAll('.' +MobileNumberValidator.classNames.trigger); 4560 var requiredFields = doc.querySelectorAll('.' + Blank
4560FieldValidator.classNames.trigger); 4561 var patternCheckedFields = doc.querySelectorAll('.' + PatternValidator.classNames.trigger); 4562 var deferred1 = new $.Deferred(); 4563 var formType = FormFilter.General.getFormType(); 4564 var hasBlankError = false; 4565 var $inputSubmitTrigger = $(CommonSubmitValidator.formSelector).find('input[type="submit"]'); 4566 var $buttonSubmitTrigger = $(CommonSubmitValidator.formSelector).find('button[type="submit"]'); 4567 var controlErrorDisplayTrigger = null; 4568 4569 if ( 4570 win.KeyenceForm.BlankFieldValidator.isActionPwdAssistance() && 4571 !doc.querySelector('form[name="' + names.passwordAssistanceActionForm + '"]') && 4572 !doc.querySelector('form[name="' + names.passwordAssistanceResetForm + '"]') 4573 ) { 4574 return true; 4575 } 4576 4577 if (canSubmit) { 4578 return true; 4579 } 4580 4581 canSubmit = true; 4582 4583 controlErrorDisplayTrigger = event.originalEvent.submitter ? event.originalEvent.submitter : ControlErrorDisplay.browserValidatorTarget; 4584 4585 if ( 4586 formType === FormFilter.General.FORM_TYPE.EMAIL || 4587 formType === FormFilter.General.FORM_TYPE.DEFAULT || 4588 doc.querySelector('form[name="' + names.passwordAssistanceResetForm + '"]') 4589 ) { 4590 ControlErrorDisplay.setTriggerClickedData(controlErrorDisplayTrigger); 4591 4592 if (requiredFields) { 4593 hasBlankError = BlankFieldValidator.validateFieldAll(requiredFields); 4594 4595 if (hasBlankError) { 4596 canSubmit = false; 4597 } 4598 } 4599 4600 if (patternCheckedFields) { 4601 PatternValidator.validateFieldAll(patternCheckedFields).done(function (hasFormatError) { 4602 if (hasFormatError) { 4603 MultiStepForm.focusFirstErrorItem(CommonSubmitValidator.$targetForm); 4604 4605 canSubmit = false; 4606 } 4607 4608 deferred1.resolve(); 4609 }); 4610 } else { 4611 deferred1.resolve(); 4612 } 4613 } else if (formType === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 4614 if (requiredFields) { 4615 hasBlankError = BlankFieldValidator.validateFieldAll(requiredFields); 4616 4617 if (hasBlankError) { 4618 canSubmit = false; 4619 } 4620 } 4621 4622 if (mobileNumberFields.length) { 4623 MobileNumberValidator.validateFieldAll(mobileNumberFields).done(function (hasFormatError) { 4624 if (hasFormatError) { 4625 MultiStepForm.focusFirstErrorItem(CommonSubmitValidator.$targetForm); 4626 4627 canSubmit = false; 4628 } 4629 4630 deferred1.resolve(); 4631 }); 4632 } else { 4633 deferred1.resolve(); 4634 } 4635 } 4636 4637 deferred1.promise().done(function () { 4638 if (canSubmit) { 4639 setTimeout(function () { 4640 // If the submit trigger is a button element, the input field will lose focus when the page transitions, so adjustments have been made to remove the focus beforehand. 4641 var activeElem = doc.activeElement; 4642 4643 if (doc.querySelector('form[name="' + names.passwordAssistanceResetForm + '"]')) { 4644 if ($buttonSubmitTrigger.length && 4645 activeElem?.matches('input:not([type=hidden]), select, textarea') && 4646 typeof activeElem.blur === 'function' 4647 ) { 4648 activeElem.blur(); 4649 } 4650 4651 setTimeout(function () { 4652 if ($inputSubmitTrigger.length) { 4653 $inputSubmitTrigger.trigger('click'); 4654 } else if ($buttonSubmitTrigger.length) { 4655 $buttonSubmitTrigger.trigger('click'); 4656 } 4657 }, 0); 4658 } else { 4659 if ($inputSubmitTrigger.length) { 4660 $inputSubmitTrigger.trigger('click'); 4661 } else if ($buttonSubmitTrigger.length) { 4662 $buttonSubmitTrigger.trigger('click'); 4663 } 4664 } 4665 }, 0); 4666 } else { 4667 MultiStepForm.focusFirstErrorItem(CommonSubmitValidator.$targetForm); 4668 } 4669 }); 4670 4671 return false; 4672 }; 4673 4674 return CommonSubmitValidator; 4675 }()); 4676 4677 KEYENCE.Form.AvailableValidator = (function () { 4678 var MultiStepForm = null; 4679 var BlankFieldValidator = null; 4680 var PatternMatchValidator = null; 4681 4682 var AvailableValidator = { 4683 multiStepForm: null, 4684 preform: null, 4685 RegisterForm: null, 4686 targetWrapperClass: { 4687 email: 'js-validateEmailAvailable',
4688 phone: 'js-validatePhoneAvailable', 4689 mobile: 'js-validateMobileAvailable' 4690 }, 4691 targetClass: { 4692 emailAddress: 'js-validateEmailAvailable-target', 4693 phoneCountryId: 'js-validatePhoneAvailable-countryId', 4694 phoneNumber: 'js-validatePhoneAvailable-number', 4695 mobileCountryId: 'js-validateMobileAvailable-countryId', 4696 mobileNumber: 'js-validateMobileAvailable-number', 4697 status: 'is-unavailable' 4698 }, 4699 targetElements: { 4700 phoneNumber: null, 4701 mobileNumber: null, 4702 }, 4703 targetKey: { 4704 email: 'email', 4705 mobile: 'mobile', 4706 phone: 'phone' 4707 }, 4708 targetData: { 4709 targetWrapper: null, 4710 numberElement: null, 4711 countryIdElement: null, 4712 numberValue: '', 4713 countryIdValue: '', 4714 url: '' 4715 }, 4716 apiUrl: { 4717 email: 'https://emailvalidation.abstractapi.com/v1/?email=', 4718 phone: 'https://phonevalidation.abstractapi.com/v1/?phone=', 4719 emailKey: 'api_key=f9e036567bfc45faaa30f137cd49dbe2', 4720 phoneKey: 'api_key=0f96bf50834f431aaa97290c4df8d12d' 4721 }, 4722 config: { 4723 registerTargets: null, 4724 registerTargetsLength: 0, 4725 isRunningVerification: false, 4726 isUnavailable: false, 4727 preFormProcessingEventObject: null, 4728 registerProcessingEventObject: null, 4729 registerCurrentPanelType: '', 4730 currentArea: null, 4731 currentTarget: null, 4732 isReturnFirstTimePreForm: false, 4733 isReturnFirstTimeRegister: false, 4734 isPreFormContinueBlocked: false 4735 }, 4736 processingUnblocked: { 4737 email: false, 4738 signInMobile: false 4739 } 4740 }; 4741 4742 AvailableValidator.init = function () { 4743 MultiStepForm = win.MultiStepForm; 4744 this.multiStepForm = doc.getElementById(MultiStepForm.idNames.trigger); 4745 this.preform = doc.getElementById(MultiStepForm.PreForm.idNames.root); 4746 this.RegisterForm = doc.getElementById(MultiStepForm.Register.idNames.regForm); 4747 4748 BlankFieldValidator = win.KeyenceForm.BlankFieldValidator; 4749 PatternMatchValidator = win.KeyenceForm.PatternMatchValidator; 4750 4751 if(!this.multiStepForm 4752 || win.kpi_siteSettings.siteId !== MultiStepForm.siteData.KA.id) { 4753 return; 4754 } 4755 4756 if (this.preform) { 4757 this.setTriggerElements(this.preform); 4758 } 4759 4760 if (this.RegisterForm) { 4761 this.setTriggerElements(this.RegisterForm); 4762 this.setNumberElements(); 4763 this.setTargetBlockStatus(); 4764 this.setMutationObserver(); 4765 } 4766 }; 4767 4768 AvailableValidator.setTriggerElements = function (targetForm) { 4769 var targetWrapperElements = null; 4770 4771 Object.keys(this.targetWrapperClass).forEach(function (key) { 4772 targetWrapperElements = targetForm.querySelectorAll('.' + AvailableValidator.targetWrapperClass[key]); 4773 4774 if (targetWrapperElements.length) { 4775 targetWrapperElements.forEach(function (WrapperElement) { 4776 AvailableValidator.setValidateEvent(WrapperElement, key, targetForm); 4777 }); 4778 } 4779 }); 4780 }; 4781 4782 AvailableValidator.setNumberElements = function () { 4783 this.targetElements.mobileNumber = this.RegisterForm.querySelector('.' + this.targetClass.mobileNumber); 4784 this.targetElements.phoneNumber = this.RegisterForm.querySelector('.' + this.targetClass.phoneNumber); 4785 this.config.registerTargets = this.RegisterForm.querySelectorAll('.' + this.targetClass.mobileNumber + ', .' + this.targetClass.phoneNumber); 4786 this.config.registerTargetsLength = this.config.registerTargets.length; 4787 }; 4788 4789 AvailableValidator.setTargetBlockStatus = function () { 4790 if (this.config.registerTargetsLength === 2) { 4791 this.processingUnblocked.mobile = false; 4792 this.processingUnblocked.phone = false; 4793 } else if (this.config.registerTargetsLength === 1) { 4794 if (this.config.registerTargets[0].classList.contains(this.targetClass.mobileNumber)) { 4795 this.processingUnblocked.mobile = false; 4796 } else { 4797 this.processingUnblocked.phone = false; 4798 } 4799 } 4800 }; 4801 4802 AvailableValidator.setValidateEvent = function (targetWrapper, type, targetForm) { 4803 var target = null; 4804 var countryNumber = null; 4805 4806 switch (type) { 4807 case this.targetKey.email: 4808 target = targetWrapper.querySelector('.' + this.targetClass.emailAddress); 4809 4810 if (!target) { 4811 break; 4812 } 4813 4814 if (!target.classList.contains(PatternMatchValidator.classNames.trigger)) { 4815 target.addEventListener('blur', this.runEmailValidate.bind(this), false); 4816 } 4817 4818 target.addEventListener('blur', this.changeRunningStatus, false); 4819 target.addEventListener('input', this.changeBlockStatus, false); 4820 4821 break; 4822 4823 case this.targetKey.mobile: 4824 target = targetWrapper.querySelector('.' + this.targetClass.mobileNumber); 4825 countryNumber = targetWrapper.querySelector('.' + this.targetClass.mobileCountryId); 4826 4827 if (target) { 4828 if (targetForm !== this.RegisterForm 4829 && !target.classList.contains(PatternMatchValidator.classNames.trigger)) { 4830 target.addEventListener('blur', this.runMobileValidate.bind(this), false); 4831 } 4832 4833 target.addEventListener('blur', this.changeRunningStatus, false); 4834 target.addEventListener('input', this.changeBlockStatus, false); 4835 4836 if (targetForm === this.RegisterForm) { 4837 target.addEventListener('input', this.setCurrentTarget, false); 4838 target.addEventListener('focus', this.setCurrentTarget, false); 4839 } 4840 } 4841 4842 if (countryNumber) { 4843 countryNumber.addEventListener('change', this.runMobileValidate.bind(this), false); 4844 } 4845 4846 break; 4847 4848 case this.targetKey.phone: 4849 target = targetWrapper.querySelector('.' + this.targetClass.phoneNumber); 4850 countryNumber = targetWrapper.querySelector('.' + this.targetClass.phoneCountryId); 4851 4852 if (target) { 4853 if (targetForm !== this.RegisterForm 4854 && !target.classList.contains(PatternMatchValidator.classNames.trigger)) { 4855 target.addEventListener('blur', this.runPhoneValidate.bind(this), false); 4856 } 4857 4858 target.addEventListener('blur', this.changeRunningStatus, false); 4859 target.addEventListener('input', this.changeBlockStatus, false); 4860 4861 if (targetForm === this.RegisterForm) { 4862 target.addEventListener('input', this.setCurrentTarget, false); 4863 target.addEventListener('focus', this.setCurrentTarget, false); 4864 } 4865 } 4866 4867 if (countryNumber) { 4868 countryNumber.addEventListener('change', this.runPhoneValidate.bind(this), false); 4869 } 4870 4871 break; 4872 4873 default: 4874 break; 4875 } 4876 }; 4877 4878 AvailableValidator.changeRunningStatus = function (event) { 4879 var targetElement = event.currentTarget; 4880 4881 AvailableValidator.config.isRunningVerification = true; 4882 4883 if (targetElement.closest('.' + MultiStepForm.Register.classNames.formPanel) 4884 && (targetElement.classList.contains(AvailableValidator.targetClass.mobileNumber) 4885 || targetElement.classList.contains(AvailableValidator.targetClass.phoneNumber))) { 4886 if (AvailableValidator.config.currentTarget && AvailableValidator.config.registerProcessingEventObject) { 4887 AvailableValidator.runRegisterVerification(); 4888 } 4889 } 4890 }; 4891 4892 AvailableValidator.changeBlockStatus = function (event) { 4893 var targetElement = event.currentTarget; 4894 4895 if (targetElement.classList.contains(AvailableValidator.targetClass.emailAddress)) { 4896 AvailableValidator.processingUnblocked.email = false; 4897 } else if (targetElement.closest('#' + MultiStepForm.PreForm.idNames.root) 4898 && targetElement.classList.contains(AvailableValidator.targetClass.mobileNumber)) { 4899 AvailableValidator.processingUnblocked.signInMobile = false; 4900 } else if (targetElement.closest('.' + MultiStepForm.Register.classNames.formPanel) 4901 && targetElement.classList.contains(AvailableValidator.targetClass.mobileNumber)) { 4902 AvailableValidator.processingUnblocked.mobile = false; 4903 } else if (targetElement.closest('.' + MultiStepForm.Register.classNames.formPanel) 4904 && targetElement.classList.contains(AvailableValidator.targetClass.phoneNumber)) { 4905 AvailableValidator.processingUnblocked.phone = false; 4906 } 4907 }; 4908 4909 AvailableValidator.setCurrentTarget = function (event) { 4910 AvailableValidator.config.currentTarget = event.currentTarget; 4911 }; 4912 4913 AvailableValidator.runEmailValidate = function (target, $deferred, isErrorCheck) { 4914 var requireElementObject = this.getRequireElements(target, this.targetKey.email); 4915 4916 if (!requireElementObject) { 4917 if ($deferred) { 4918 $deferred.resolve(target); 4919 } 4920 4921 return; 4922 } 4923 4924 if (BlankFieldValidator.isBlank(requireElementObject.target)) { 4925 this.clearNoteText(requireElementObject.targetWrapper); 4926 4927 if ($deferred) { 4928 $deferred.resolve(target); 4929 } 4930 4931 return; 4932 } 4933 4934 this.runAvailableValidate(requireElementObject.target, requireElementObject.targetWrapper, this.apiUrl.emailKey, this.targetKey.email).done(function (resultData) { 4935 if(!resultData) { 4936 if ($deferred) { 4937 $deferred.resolve(target); 4938 } 4939 4940 return; 4941 } 4942 4943 AvailableValidator.updateEmailStatus(resultData, isErrorCheck); 4944 4945 if ($deferred) { 4946 $deferred.resolve(target); 4947 } 4948 }).fail(function () { 4949 AvailableValidator.clearNoteText(requireElementObject.targetWrapper); 4950 4951 if ($deferred) { 4952 $deferred.resolve(target); 4953 } 4954 }); 4955 }; 4956 4957 AvailableValidator.runMobileValidate = function (target, $deferred, isErrorCheck) { 4958 var requireElementObject = this.getRequireElements(target, this.targetKey.mobile); 4959 4960 if (!requireElementObject) { 4961 if ($deferred) { 4962 $deferred.resolve(target); 4963 } 4964 4965 return; 4966 } 4967 4968 if (this.isBlankNumber(requireElementObject, this.targetKey.mobile)) { 4969 this.clearNoteText(requireElementObject.targetWrapper); 4970 4971 if ($deferred) { 4972 $deferred.resolve(target); 4973 } 4974 4975 return; 4976 } 4977 4978 this.runAvailableValidate(requireElementObject.target, requireElementObject.targetWrapper, this.apiUrl.phoneKey, this.targetKey.mobile).done(function (resultData) { 4979 if(!resultData) { 4980 if ($deferred) { 4981 $deferred.resolve(target); 4982 } 4983 4984 return; 4985 } 4986 4987 AvailableValidator.updateNumberStatus(resultData, isErrorCheck); 4988 4989 if ($deferred) { 4990 $deferred.resolve(target); 4991 } 4992 }).fail(function () { 4993 AvailableValidator.clearNoteText(requireElementObject.targetWrapper); 4994 4995 if ($deferred) { 4996 $deferred.resolve(target); 4997 } 4998 }); 4999 }; 5000 5001 AvailableValidator.runPhoneValidate = function (target, $deferred, isErrorCheck) { 5002 var requireElementObject = this.getRequireElements(target, this.targetKey.phone); 5003 5004 if (!requireElementObject) { 5005 if ($deferred) { 5006 $deferred.resolve(target); 5007 } 5008 5009 return; 5010 } 5011 5012 if (this.isBlankNumber(requireElementObject, this.targetKey.phone)) { 5013 this.clearNoteText(requireElementObject.targetWrapper); 5014 5015 if ($deferred) { 5016 $deferred.resolve(target); 5017 } 5018 5019 return; 5020 } 5021 5022 this.runAvailableValidate(requireElementObject.target, requireElementObject.targetWrapper, this.apiUrl.phoneKey, this.targetKey.phone).done(function (resultData) { 5023 if(!resultData) { 5024 if ($deferred) { 5025 $deferred.resolve(target); 5026 } 5027 5028 return; 5029 } 5030 5031 AvailableValidator.updateNumberStatus(resultData, isErrorCheck); 5032 5033 if ($deferred) { 5034 $deferred.resolve(target); 5035 } 5036 }).fail(function () { 5037 AvailableValidator.clearNoteText(requireElementObject.targetWrapper); 5038 5039 if ($deferred) { 5040 $deferred.resolve(target); 5041 } 5042 }); 5043 }; 5044 5045 AvailableValidator.getRequireElements = function (target, type) { 5046 var targetElement = null; 5047 var requireElements = null; 5048 var targetWrapper = null; 5049 5050 if (target.currentTarget) { 5051 targetElement = target.currentTarget; 5052 } else { 5053 targetElement = target; 5054 } 5055 5056 if (!targetElement || !type) { 5057 return requireElements; 5058 } 5059 5060 targetWrapper = targetElement.closest('.' + this.targetWrapperClass[type]); 5061 5062 if (!targetWrapper) { 5063 return requireElements; 5064 } 5065 5066 return requireElements = { 5067 target: targetElement, 5068 targetWrapper: targetWrapper 5069 }; 5070 } 5071 5072 AvailableValidator.hasError = function (targetWrapper) { 5073 if (targetWrapper.classList.contains(MultiStepForm.classNames.isError)) { 5074 return true; 5075 } 5076 5077 return false; 5078 } 5079 5080 AvailableValidator.isBlankNumber = function (requireElementObject, type) { 5081 var isBlank = true; 5082 var numberInput = null; 5083 5084 if (requireElementObject.target.tagName === 'INPUT') { 5085 if (requireElementObject.target.value === '') { 5086 return isBlank; 5087 } else { 5088 isBlank = false; 5089
5089 } 5090 } else { 5091 if (type === this.targetKey.mobile) { 5092 numberInput = requireElementObject.targetWrapper.querySelector('.' + this.targetClass.mobileNumber); 5093 } else { 5094 numberInput = requireElementObject.targetWrapper.querySelector('.' + this.targetClass.phoneNumber); 5095 } 5096 5097 if (numberInput && numberInput.value === '') { 5098 return isBlank; 5099 } else { 5100 isBlank = false; 5101 } 5102 } 5103 5104 return isBlank; 5105 }; 5106 5107 AvailableValidator.runAvailableValidate = function (target, targetWrapper, apiKey, type) { 5108 var $deferred = new $.Deferred(); 5109 var resultData = {}; 5110 5111 this.targetData = { 5112 targetWrapper: targetWrapper, 5113 numberElement: null, 5114 countryIdElement: null, 5115 numberValue: '', 5116 countryIdValue: '', 5117 url: '' 5118 }; 5119 5120 if (type === this.targetKey.email) { 5121 this.targetData.url = this.apiUrl.email + target.value + '&' + apiKey; 5122 } else if (type === this.targetKey.mobile || type === this.targetKey.phone) { 5123 this.setTargetData(this.targetData.targetWrapper, apiKey, type); 5124 } 5125 5126 if (this.targetData.url === '') { 5127 $deferred.reject(); 5128 } 5129 5130 $.ajax({
5131 url: this.targetData.url, 5132 type: 'GET', 5133 dataType: 'json', 5134 timeout: 10000 5135 }).done(function (data) { 5136 if (type !== AvailableValidator.targetKey.email) { 5137 resultData = { 5138 apiData: data, 5139 targetData: AvailableValidator.targetData, 5140 targetType: type 5141 } 5142 } else { 5143 resultData = { 5144 apiData: data, 5145 targetData: AvailableValidator.targetData 5146 } 5147 } 5148 5149 $deferred.resolve(resultData); 5150 }).fail(function () { 5151 $deferred.reject(); 5152 }); 5153 5154 return $deferred.promise(); 5155 }; 5156 5157 AvailableValidator.setTargetData = function (targetWrapper, apiKey, type) { 5158 var data = this.targetData; 5159 var optionElements = null; 5160 var reg = null; 5161 var inputValue = ''; 5162 5163 if (type === this.targetKey.mobile) { 5164 data.numberElement = targetWrapper.querySelector('.' + this.targetClass.mobileNumber); 5165 data.countryIdElement = targetWrapper.querySelector('.' + this.targetClass.mobileCountryId); 5166 } else if (type === this.targetKey.phone) { 5167 data.numberElement = targetWrapper.querySelector('.' + this.targetClass.phoneNumber); 5168 data.countryIdElement = targetWrapper.querySelector('.' + this.targetClass.phoneCountryId); 5169 } 5170 5171 if (data.numberElement && data.countryIdElement) { 5172 data.numberValue = data.numberElement.value; 5173 optionElements = data.countryIdElement.options; 5174 data.countryIdValue = optionElements[data.countryIdElement.selectedIndex].dataset.code; 5175 } 5176 5177 if (!data.numberValue || !data.countryIdValue) { 5178 return; 5179 } 5180 5181 if (data.numberValue.indexOf(data.countryIdValue) === 0) { 5182 inputValue = data.numberValue; 5183 reg = new RegExp('\\' + data.countryIdValue); 5184 5185 data.numberValue = inputValue.replace(reg, ''); 5186 } 5187 5188 data.url = this.apiUrl.phone + encodeURIComponent(data.countryIdValue + data.numberValue) + '&' + apiKey; 5189 }; 5190 5191 AvailableValidator.updateEmailStatus = function (resultData, isErrorCheck) { 5192 var apiData = resultData.apiData; 5193 var targetData = resultData.targetData; 5194 5195 if (!apiData.is_valid_format.value) { 5196 this.insertNoteText(targetData.targetWrapper, 'data-message-email-address-format', isErrorCheck); 5197 5198 if (isErrorCheck) { 5199 targetData.targetWrapper.dataset.unavailable = 'true'; 5200 } else { 5201 this.showNoteText(targetData.targetWrapper); 5202 } 5203 5204 return; 5205 } 5206 5207 if (apiData.deliverability !== 'DELIVERABLE') { 5208 this.insertNoteText(targetData.targetWrapper, 'data-message-email-address-available', isErrorCheck); 5209 5210 if (isErrorCheck) { 5211 targetData.targetWrapper.dataset.unavailable = 'true'; 5212 } else { 5213 this.showNoteText(targetData.targetWrapper); 5214 } 5215 5216 return; 5217 } 5218 5219 this.clearNoteText(targetData.targetWrapper); 5220 }; 5221 5222 AvailableValidator.updateNumberStatus = function (resultData, isErrorCheck) { 5223 var apiData = resultData.apiData; 5224 var targetData = resultData.targetData; 5225 5226 switch (resultData.targetType) { 5227 case this.targetKey.mobile: 5228 if (!apiData.valid) { 5229 this.insertNoteText(targetData.targetWrapper, 'data-message-mobile-number-available', isErrorCheck); 5230 5231 if (isErrorCheck) { 5232 targetData.targetWrapper.dataset.unavailable = 'true'; 5233 } else { 5234 this.showNoteText(targetData.targetWrapper); 5235 } 5236 5237 break; 5238 } 5239 5240 targetData.numberElement.value = this.getLocalNumber(apiData.country.prefix, apiData.format.international, apiData.format.local); 5241 5242 if (apiData.type !== this.targetKey.mobile) { 5243 this.insertNoteText(targetData.targetWrapper, 'data-message-mobile-number-available', isErrorCheck); 5244 5245 if (isErrorCheck) { 5246 targetData.targetWrapper.dataset.unavailable = 'true'; 5247 } else { 5248 this.showNoteText(targetData.targetWrapper); 5249 } 5250 5251 break; 5252 } 5253 5254 this.clearNoteText(targetData.targetWrapper); 5255 5256 break; 5257 5258 case this.targetKey.phone: 5259 if (!apiData.valid) { 5260 this.insertNoteText(targetData.targetWrapper, 'data-message-phone-number-available', isErrorCheck); 5261 5262 if (isErrorCheck) { 5263 targetData.targetWrapper.dataset.unavailable = 'true'; 5264 } else { 5265 this.showNoteText(targetData.targetWrapper); 5266 } 5267 5268 break; 5269 } 5270 5271 targetData.numberElement.value = this.getLocalNumber(apiData.country.prefix, apiData.format.international, apiData.format.local); 5272 5273 this.clearNoteText(targetData.targetWrapper); 5274 5275 if (apiData.type === this.targetKey.mobile) { 5276 this.inputMobileValue(targetData.numberElement.value, targetData.countryIdValue); 5277 } 5278 5279 break; 5280 5281 default: 5282 return; 5283 } 5284 }; 5285 5286 AvailableValidator.getLocalNumber = function (countryCode, internationalValue, localValue) { 5287 var reg = new RegExp('\\' + countryCode); 5288 var internationalFormatValue = internationalValue.replace(reg, ''); 5289 var localFormatValue = ''; 5290 var localFormatRemovedFirstValue = ''; 5291 var firstValueLocalFormat = ''; 5292 var formattedValue = ''; 5293 5294 if (localValue) { 5295 localFormatValue = localValue.replace(/[^0-9]/g, ''); 5296 } 5297 5298 if ((internationalFormatValue && localFormatValue) 5299 && internationalFormatValue !== localFormatValue) { 5300 localFormatRemovedFirstValue = localFormatValue.slice(1); 5301 firstValueLocalFormat = localFormatValue.charAt(0);
5302 5303 if (internationalFormatValue === localFormatRemovedFirstValue) { 5304 formattedValue = firstValueLocalFormat + internationalFormatValue; 5305 } 5306 } else { 5307 return internationalFormatValue; 5308 } 5309 5310 return formattedValue; 5311 }; 5312 5313 AvailableValidator.inputMobileValue = function (numberValue, countryCode) { 5314 var mobileTriggers = this.RegisterForm.querySelectorAll('.' + this.targetWrapperClass.mobile); 5315 var mobileElement = null; 5316 var mobileCountryNumber = null; 5317 var mobileOption = null; 5318 var blurEvent = new Event('blur'); 5319 var changeEvent = new Event('change'); 5320 5321 if (!mobileTriggers.length) { 5322 return; 5323 } 5324 5325 mobileTriggers.forEach(function (trigger) { 5326 mobileElement = trigger.querySelector('.' + AvailableValidator.targetClass.mobileNumber); 5327 mobileCountryNumber = trigger.querySelector('.' + AvailableValidator.targetClass.mobileCountryId); 5328 5329 if (mobileElement && mobileCountryNumber) { 5330 mobileOption = mobileCountryNumber.querySelector('option[data-code="' + countryCode + '"]'); 5331 5332 if (mobileOption) { 5333 mobileElement.value = numberValue; 5334 mobileOption.selected = true; 5335 5336 AvailableValidator.clearNoteText(trigger); 5337 mobileCountryNumber.closest('.js-selectCountryNumber').dispatchEvent(changeEvent); 5338 mobileElement.dispatchEvent(blurEvent); 5339 } 5340 } 5341 }); 5342 }; 5343 5344 AvailableValidator.insertNoteText = function (targetWrapper, dataName, isErrorCheck) { 5345 var errorTextElement = ''; 5346 var errorText = ''; 5347 5348 if (!targetWrapper 5349 || (targetWrapper.classList.contains(MultiStepForm.classNames.isError) && !isErrorCheck)) { 5350 return; 5351 } 5352 5353 errorTextElement = targetWrapper.querySelector('.' + MultiStepForm.classNames.errText); 5354 5355 if (!errorTextElement) { 5356 return; 5357 } 5358 5359 if (dataName === 'data-message-email-address-format' 5360 && typeof errorTextElement.dataset.messageEmailAddressFormat === 'string') { 5361 errorText = errorTextElement.dataset.messageEmailAddressFormat; 5362 } else if (dataName === 'data-message-email-address-available' 5363 && typeof errorTextElement.dataset.messageEmailAddressAvailable === 'string') { 5364 errorText = errorTextElement.dataset.messageEmailAddressAvailable; 5365 } else if (dataName === 'data-message-phone-number-available' 5366 && typeof errorTextElement.dataset.messagePhoneNumberAvailable === 'string') { 5367 errorText = errorTextElement.dataset.messagePhoneNumberAvailable; 5368 } else if (dataName === 'data-message-mobile-number-available' 5369 && typeof errorTextElement.dataset.messageMobileNumberAvailable === 'string') { 5370 errorText = errorTextElement.dataset.messageMobileNumberAvailable; 5371 } 5372 5373 if (isErrorCheck) { 5374 errorTextElement.dataset.unavailableText = errorText; 5375 } else { 5376 errorTextElement.textContent = errorText; 5377 } 5378 }; 5379 5380 AvailableValidator.clearNoteText = function (targetWrapper) { 5381 var errorTextElement = ''; 5382 5383 if (!targetWrapper) { 5384 return; 5385 } 5386 5387 targetWrapper.classList.remove(this.targetClass.status); 5388 delete targetWrapper.dataset.unavailable; 5389 delete targetWrapper.dataset.unavailableText; 5390 errorTextElement = targetWrapper.querySelector('.' + MultiStepForm.classNames.errText); 5391 5392 if (targetWrapper.classList.contains(MultiStepForm.classNames.isError) 5393 || !errorTextElement) { 5394 return; 5395 } 5396 5397 if (typeof errorTextElement.getAttribute('style') === 'string') { 5398 errorTextElement.style.display = 'none'; 5399 } else { 5400 errorTextElement.classList.add('is-hide'); 5401 } 5402 5403 errorTextElement.textContent = ''; 5404 }; 5405 5406 AvailableValidator.setMutationObserver = function () { 5407 var registerFormArea = doc.getElementById(MultiStepForm.Register.idNames.suzRegArea); 5408 var observer = null; 5409 var observersuggestConfig = { 5410 attributeFilter: ['id'], 5411 childList: true 5412 }; 5413 var $currentPanel = null; 5414 var $panels = null; 5415 var $state = null; 5416 5417 if (!registerFormArea) { 5418 return; 5419 } 5420 5421 observer = new MutationObserver(function (record) { 5422 if (record[0].target.id === MultiStepForm.Register.idNames.suzRegArea) { 5423 AvailableValidator.setTriggerElements(AvailableValidator.RegisterForm); 5424 AvailableValidator.setNumberElements(AvailableValidator.RegisterForm); 5425 5426 $panels = MultiStepForm.Register.getPanels(); 5427 5428 if ($panels.length) { 5429 $currentPanel = $panels.filter('.' + MultiStepForm.classNames.isCurrent); 5430 5431 if ($currentPanel.length) { 5432 $state = $currentPanel.find('#' + MultiStepForm.Register.idNames.state); 5433 } 5434 } 5435 5436 if (!$state.length) { 5437 AvailableValidator.processingUnblocked = { 5438 email: false, 5439 signInMobile: false 5440 } 5441 5442 AvailableValidator.setTargetBlockStatus();
5443 } 5444 } 5445 }); 5446 5447 observer.observe(registerFormArea, observersuggestConfig); 5448 }; 5449 5450 AvailableValidator.runValidate = function (fieldName, isErrorCheck) { 5451 var $deferred = new $.Deferred(); 5452 var field = null; 5453 5454 if (typeof fieldName === 'string' || fieldName) { 5455 field = doc.querySelector('[name="' + fieldName + '"]'); 5456 } 5457 5458 if (!field || win.kpi_siteSettings.siteId !== MultiStepForm.siteData.KA.id) { 5459 return $deferred.resolve(field); 5460 } 5461 5462 if (field.classList.contains(this.targetClass.emailAddress)) { 5463 this.runEmailValidate(field, $deferred, isErrorCheck); 5464 } else if (field.classList.contains(this.targetClass.mobileNumber)) { 5465 this.runMobileValidate(field, $deferred, isErrorCheck); 5466 } else if (field.classList.contains(this.targetClass.phoneNumber)) { 5467 this.runPhoneValidate(field, $deferred, isErrorCheck); 5468 } else { 5469 $deferred.resolve(field); 5470 } 5471 5472 return $deferred.promise(); 5473 }; 5474 5475 AvailableValidator.showNoteText = function (targetWrapper) { 5476 var errorTextElement = targetWrapper.querySelector('.' + MultiStepForm.classNames.errText); 5477 5478 if (!errorTextElement || this.hasError(targetWrapper)) { 5479 return; 5480 } 5481 5482 targetWrapper.classList.add(this.targetClass.status); 5483 5484 if (errorTextElement.dataset.unavailableText) { 5485 errorTextElement.textContent = errorTextElement.dataset.unavailableText; 5486 delete targetWrapper.dataset.unavailableText; 5487 } 5488 5489 if (typeof errorTextElement.getAttribute('style') === 'string') { 5490 errorTextElement.style.display = 'block'; 5491 } else { 5492 errorTextElement.classList.remove('is-hide'); 5493 } 5494 }; 5495 5496 AvailableValidator.hideNoteText = function ($targetArea) { 5497 var $targets = null; 5498 5499 $targets = $targetArea.find('.' + this.targetClass.status); 5500 5501 if (!$targets.length || win.kpi_siteSettings.siteId !== MultiStepForm.siteData.KA.id) { 5502 return; 5503 } 5504 5505 $targets.each(function () { 5506 AvailableValidator.clearNoteText(this); 5507 }) 5508 }; 5509 5510 AvailableValidator.removeUnavailableStatus = function (fieldName) { 5511 var fieldWrapper = null; 5512 5513 if (typeof fieldName === 'string' || fieldName) { 5514 fieldWrapper = this.getFieldWrapper(fieldName); 5515 } 5516 5517 if (fieldWrapper) { 5518 delete fieldWrapper.dataset.unavailable; 5519 delete fieldWrapper.dataset.unavailableText; 5520 fieldWrapper.classList.remove(this.targetClass.status); 5521 } 5522 5523 if (this.config.isRunningVerification) { 5524 this.showNextArea('normal'); 5525 } 5526 5527 this.config.isRunningVerification = false; 5528 }; 5529 5530 AvailableValidator.changeDisplayNoteText = function (fieldName) { 5531 var fieldWrapper = null; 5532 5533 if (typeof fieldName === 'string' || fieldName) { 5534 fieldWrapper = this.getFieldWrapper(fieldName); 5535 } 5536 5537 if (!fieldWrapper) { 5538 return; 5539 } 5540 5541 if (fieldWrapper.dataset.unavailable 5542 && !fieldWrapper.classList.contains(MultiStepForm.classNames.isError)) { 5543 delete fieldWrapper.dataset.unavailable; 5544 this.showNoteText(fieldWrapper); 5545 this.showNextArea('note'); 5546 } else if (fieldWrapper.classList.contains(MultiStepForm.classNames.isError)) { 5547 this.clearNoteText(fieldWrapper); 5548 5549 if (this.config.isRunningVerification) { 5550 this.showNextArea('error'); 5551 } 5552 } else if (!fieldWrapper.dataset.unavailable 5553 || !fieldWrapper.classList.contains(MultiStepForm.classNames.isError)) { 5554 this.clearNoteText(fieldWrapper); 5555 5556 if (this.config.isRunningVerification) { 5557 this.showNextArea('normal'); 5558 } 5559 } 5560 5561 this.config.isRunningVerification = false; 5562 }; 5563 5564 AvailableValidator.showNextArea = function (type) { 5565 var formType = KEYENCE.Form.FormFilter.General.getFormType(); 5566 var FormFilter = KEYENCE.Form.FormFilter; 5567 5568 if (!this.processingUnblocked.email && !this.processingUnblocked.signInMobile) { 5569 if (this.config.preFormProcessingEventObject) { 5570 if (formType === FormFilter.General.FORM_TYPE.MOBILE_NUMBER) { 5571 if (type === 'note' && !this.processingUnblocked.signInMobile) { 5572 this.processingUnblocked.signInMobile = true; 5573 this.config.isReturnFirstTimePreForm = false; 5574 this.focusFirstTargetItem(this.config.currentArea); 5575 } else { 5576 MultiStepForm.PreForm.onClickContinue(this.config.preFormProcessingEventObject); 5577 } 5578 } else { 5579 if (type === 'note' && !this.processingUnblocked.email) { 5580 this.processingUnblocked.email = true; 5581 this.config.isReturnFirstTimePreForm = false; 5582 this.focusFirstTargetItem(this.config.currentArea); 5583 } else { 5584 MultiStepForm.PreForm.onClickContinue(this.config.preFormProcessingEventObject); 5585 } 5586 } 5587 5588 this.config.preFormProcessingEventObject = null; 5589 5590 return; 5591 } 5592 } 5593 5594 if (this.config.registerTargetsLength === 2) { 5595 if (!this.config.registerProcessingEventObject) { 5596 return; 5597 } 5598 5599 if (type === 'note' && !this.processingUnblocked.mobile && !this.processingUnblocked.phone) { 5600 if (this.targetElements.mobileNumber.value !== '') { 5601 this.processingUnblocked.mobile = true; 5602 } 5603 5604 if (this.targetElements.phoneNumber.value !== '') { 5605 this.processingUnblocked.phone = true; 5606 } 5607 5608 this.config.isReturnFirstTimeRegister = false; 5609 this.focusFirstTargetItem(this.config.currentArea); 5610 } else if (type === 'note' 5611 && !this.processingUnblocked.mobile 5612 && this.targetElements.mobileNumber.value !== '') { 5613 this.processingUnblocked.mobile = true; 5614 this.config.isReturnFirstTimeRegister = false; 5615 this.focusFirstTargetItem(this.config.currentArea); 5616 } else if (type === 'note' 5617 && !this.processingUnblocked.phone 5618 && this.targetElements.phoneNumber.value !== '') { 5619 this.processingUnblocked.phone = true; 5620 this.config.isReturnFirstTimeRegister = false; 5621 this.focusFirstTargetItem(this.config.currentArea); 5622 } else if (this.config.registerCurrentPanelType === 'notLastPanel') { 5623 if (this.config.registerProcessingEventObject.handleObj.type === 'mousedown') { 5624 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject, true); 5625 } else { 5626 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject); 5627 } 5628 } else if (this.config.registerCurrentPanelType === 'lastPanel') {
5629 MultiStepForm.Register.onSubmitForm(); 5630 } 5631 } else { 5632 if (!this.config.registerProcessingEventObject) { 5633 return; 5634 } 5635 5636 if (typeof this.processingUnblocked.mobile !== 'undefined') { 5637 if (type === 'note' 5638 && !this.processingUnblocked.mobile 5639 && this.targetElements.mobileNumber.value !== '') { 5640 this.processingUnblocked.mobile = true; 5641 this.config.isReturnFirstTimeRegister = false; 5642 this.focusFirstTargetItem(this.config.currentArea); 5643 } else if (this.config.registerCurrentPanelType === 'notLastPanel') { 5644 if (this.config.registerProcessingEventObject.handleObj.type === 'mousedown') { 5645 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject, true); 5646 } else { 5647 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject); 5648 } 5649 } else if (this.config.registerCurrentPanelType === 'lastPanel') { 5650 MultiStepForm.Register.onSubmitForm(); 5651 } 5652 } 5653 5654 if (typeof this.processingUnblocked.phone !== 'undefined') { 5655 if (type === 'note' 5656 && !this.processingUnblocked.phone 5657 && this.targetElements.phoneNumber.value !== '') { 5658 this.processingUnblocked.phone = true; 5659 this.config.isReturnFirstTimeRegister = false; 5660 this.focusFirstTargetItem(this.config.currentArea); 5661 } else if (this.config.registerCurrentPanelType === 'notLastPanel') { 5662 if (this.config.registerProcessingEventObject.handleObj.type === 'mousedown') { 5663 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject, true); 5664 } else { 5665 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject); 5666 } 5667 } else if (this.config.registerCurrentPanelType === 'lastPanel') { 5668 MultiStepForm.Register.onSubmitForm(); 5669 } 5670 } 5671 } 5672 5673 this.config.registerCurrentPanelType === ''; 5674 this.config.registerProcessingEventObject = null; 5675 }; 5676 5677 AvailableValidator.focusFirstTargetItem = function ($currentArea) { 5678 var $targetElements = null; 5679 var $targetElement = null; 5680 5681 if (!$currentArea.length) { 5682 return; 5683 } 5684 5685 $targetElements = $currentArea.find('[id^="suz_div_"].' + MultiStepForm.classNames.isError + ':visible , [id^="suz_div_"].' + this.targetClass.status + ':visible'); 5686 5687 if ($targetElements.length) { 5688 $targetElement = $targetElements.eq(0).find(MultiStepForm.selectors.focusbleInputElements); 5689 5690 if ($targetElement.length) { 5691 if ($targetElement.length === 2) { 5692 if ( 5693 $targetElement.get(0).tagName.toLowerCase() === 'select' && 5694 $targetElement.get(1).tagName.toLowerCase() === 'input' 5695 ) { 5696 $targetElement.get(1).focus(); 5697 MultiStepForm.scrollToErrorElement($targetElement.get(1)); 5698 } 5699 } else { 5700 MultiStepForm.scrollToErrorElement($targetElement.get(0)); 5701 } 5702 } 5703 } 5704 }; 5705 5706 AvailableValidator.getFieldWrapper = function (fieldName) { 5707 var field = doc.querySelector('[name="' + fieldName + '"]'); 5708 5709 if (!field || win.kpi_siteSettings.siteId !== MultiStepForm.siteData.KA.id) { 5710 return null; 5711 } 5712 5713 if (field.classList.contains(this.targetClass.emailAddress)) { 5714 return field.closest('.' + this.targetWrapperClass.email); 5715 } else if (field.classList.contains(this.targetClass.mobileNumber)) { 5716 return field.closest('.' + this.targetWrapperClass.mobile); 5717 } else if (field.classList.contains(this.targetClass.phoneNumber)) { 5718 return field.closest('.' + this.targetWrapperClass.phone); 5719 } else { 5720 return null; 5721 } 5722 }; 5723 5724 AvailableValidator.hasTargetClass = function (field) { 5725 if (field.classList.contains(this.targetClass.emailAddress) 5726 || field.classList.contains(this.targetClass.mobileNumber) 5727 || field.classList.contains(this.targetClass.phoneNumber)) { 5728 return true; 5729 } 5730 5731 return false; 5732 }; 5733 5734 AvailableValidator.isProgressStatus = function ($targetArea) { 5735 var $errorElements = $targetArea.find('.' + MultiStepForm.classNames.isError); 5736 5737 if ($errorElements.length) { 5738 return true; 5739 } 5740 5741 if ($targetArea.find('.' + this.targetClass.status).length) { 5742 return false; 5743 } 5744 5745 return true; 5746 }; 5747 5748 AvailableValidator.updatePreFormBlockStatus = function (formType, formFilter, preFormObject, event) { 5749 if (this.config.isRunningVerification || this.config.isReturnFirstTimeRegister) { 5750 if (formType === formFilter.General.FORM_TYPE.MOBILE_NUMBER) { 5751 if (!this.processingUnblocked.signInMobile 5752 && !this.config.isReturnFirstTimePreForm) { 5753 this.setPreFormContinueDate(preFormObject.$root, event); 5754 this.config.isPreFormContinueBlocked = true; 5755 5756 return; 5757 } 5758 } else { 5759 if (!this.processingUnblocked.email 5760 && !this.config.isReturnFirstTimePreForm) { 5761 this.setPreFormContinueDate(preFormObject.$root, event); 5762 this.config.isPreFormContinueBlocked = true; 5763 5764 return; 5765 } 5766 } 5767 } else { 5768 if (!this.isProgressStatus(preFormObject.$root)) { 5769 if (formType === formFilter.General.FORM_TYPE.MOBILE_NUMBER) { 5770 if (!this.processingUnblocked.signInMobile 5771 && preFormObject.$formCheckMobileNumber.val() !== '') { 5772 this.processingUnblocked.signInMobile = true; 5773 this.config.isPreFormContinueBlocked = true; 5774 5775 return; 5776 } 5777 } else { 5778 if (!this.processingUnblocked.email 5779 && preFormObject.$formCheckEmail.val() !== '') { 5780 this.processingUnblocked.email = true; 5781 this.config.isPreFormContinueBlocked = true; 5782 5783 return; 5784 } 5785 } 5786 } 5787 } 5788 5789 this.config.isReturnFirstTimePreForm = false; 5790 this.config.isPreFormContinueBlocked = false; 5791 }; 5792 5793 AvailableValidator.setPreFormContinueDate = function ($root, event) { 5794 this.config.currentArea = $root; 5795 this.config.preFormProcessingEventObject = event; 5796 this.config.isReturnFirstTimePreForm = true; 5797 }; 5798 5799 AvailableValidator.updateRegisterBlockStatus = function ($currentPanel, event, currentPanel) {
5800 if (this.checkRegisterTargetElements($currentPanel)) { 5801 this.config.isRegisterContinueBlocked = false; 5802 5803 return; 5804 } 5805 5806 if (this.isBlankRequiredField($currentPanel)) { 5807 this.config.isRegisterContinueBlocked = false; 5808 5809 if (typeof this.processingUnblocked.mobile !== 'undefined') { 5810 if (this.isVerificationTarget('mobile', this.targetElements.mobileNumber)) { 5811 this.processingUnblocked.mobile = true; 5812 } 5813 } 5814 5815 if (typeof this.processingUnblocked.phone !== 'undefined') { 5816 if (this.isVerificationTarget('phone', this.targetElements.phoneNumber)) { 5817 this.processingUnblocked.phone = true; 5818 } 5819 } 5820 5821 return; 5822 } 5823 5824 if (this.config.currentTarget) { 5825 this.changeDuringValificationStatus(event); 5826 this.config.isRegisterContinueBlocked = true; 5827 5828 return; 5829 } 5830 5831 if (this.config.isRunningVerification || this.config.isReturnFirstTimeRegister) { 5832 if (this.config.registerTargetsLength === 2) { 5833 if ((this.isVerificationTarget('mobile', this.targetElements.mobileNumber) 5834 || this.isVerificationTarget('phone', this.targetElements.phoneNumber)) 5835 && !this.config.isReturnFirstTimeRegister) { 5836 this.setRegisterContinueDate($currentPanel, event, currentPanel); 5837 this.config.isRegisterContinueBlocked = true; 5838 5839 return; 5840 } 5841 } else { 5842 if (typeof this.processingUnblocked.mobile !== 'undefined') { 5843 if (!this.processingUnblocked.mobile && !this.config.isReturnFirstTimeRegister) { 5844 this.setRegisterContinueDate($currentPanel, event, currentPanel); 5845 this.config.isRegisterContinueBlocked = true; 5846 5847 return; 5848 } 5849 } 5850 5851 if (typeof this.processingUnblocked.phone !== 'undefined') { 5852 if (!this.processingUnblocked.phone && !this.config.isReturnFirstTimeRegister) { 5853 this.setRegisterContinueDate($currentPanel, event, currentPanel); 5854 this.config.isRegisterContinueBlocked = true; 5855 5856 return; 5857 } 5858 } 5859 } 5860 } else { 5861 if (!this.isProgressStatus($currentPanel)) { 5862 if (this.config.registerTargetsLength === 2) { 5863 if (this.isVerificationTarget('mobile', this.targetElements.mobileNumber) 5864 || this.isVerificationTarget('phone', this.targetElements.phoneNumber)) { 5865 if (this.isVerificationTarget('mobile', this.targetElements.mobileNumber)) { 5866 this.processingUnblocked.mobile = true; 5867 } 5868 5869 if (this.isVerificationTarget('phone', this.targetElements.phoneNumber)) { 5870 this.processingUnblocked.phone = true; 5871 } 5872 5873 this.config.isRegisterContinueBlocked = true; 5874 5875 return; 5876 } 5877 } else { 5878 if (typeof this.processingUnblocked.mobile !== 'undefined') { 5879 if (this.isVerificationTarget('mobile', this.targetElements.mobileNumber)) { 5880 this.processingUnblocked.mobile = true; 5881 this.config.isRegisterContinueBlocked = true; 5882 5883 return; 5884 } 5885 } 5886 5887 if (typeof this.processingUnblocked.phone !== 'undefined') { 5888 if (this.isVerificationTarget('phone', this.targetElements.phoneNumber)) { 5889 this.processingUnblocked.phone = true; 5890 this.config.isRegisterContinueBlocked = true; 5891 5892 return; 5893 } 5894 } 5895 } 5896 } 5897 } 5898 5899 this.config.isReturnFirstTimeRegister = false; 5900 this.config.isRegisterContinueBlocked = false; 5901 }; 5902
5903 AvailableValidator.checkRegisterTargetElements = function ($targetArea) { 5904 var $targetElements = null; 5905 5906 $targetElements = $targetArea.find('.' + this.targetWrapperClass.mobile + ', .' + this.targetWrapperClass.phone); 5907 5908 if (!$targetElements.length) { 5909 return true; 5910 } 5911 5912 return false; 5913 }; 5914 5915 AvailableValidator.isVerificationTarget = function (keyName, field) { 5916 if (!this.processingUnblocked[keyName] && !BlankFieldValidator.isBlank(field)) { 5917 return true; 5918 } 5919 5920 return false; 5921 }; 5922 5923 AvailableValidator.setRegisterContinueDate = function ($currentPanel, event, currentPanel) { 5924 this.config.currentArea = $currentPanel; 5925 this.config.registerProcessingEventObject = event; 5926 this.config.registerCurrentPanelType = currentPanel; 5927 this.config.isReturnFirstTimeRegister = true; 5928 }; 5929 5930 AvailableValidator.changeDuringValificationStatus = function (event) { 5931 var blurEvent = new Event('blur'); 5932 5933 this.config.registerProcessingEventObject = event; 5934 this.config.currentTarget.dispatchEvent(blurEvent); 5935 }; 5936 5937 AvailableValidator.isBlankRequiredField = function ($currentPanel) { 5938 var $RequiredFields = $currentPanel.find('.' + MultiStepForm.Register.classNames.required); 5939 var isBlank = false; 5940 5941 if (!$RequiredFields.length) { 5942 return isBlank; 5943 } 5944 5945 $RequiredFields.each(function () { 5946 if (BlankFieldValidator.isBlank(this)) { 5947 isBlank = true; 5948 5949 return false 5950 } 5951 }); 5952 5953 return isBlank; 5954 }; 5955 5956 AvailableValidator.runRegisterVerification = function () { 5957 if (this.config.currentTarget && this.config.registerProcessingEventObject) { 5958 this.config.currentTarget = null; 5959 5960 if (this.config.registerCurrentPanelType === 'lastPanel') { 5961 MultiStepForm.Register.onSubmitForm(); 5962 } else { 5963 if (this.config.registerProcessingEventObject.handleObj.type === 'mousedown') { 5964 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject, true); 5965 } else { 5966 MultiStepForm.Register.showNext(this.config.registerProcessingEventObject); 5967 } 5968 } 5969 } 5970 }; 5971 5972 return AvailableValidator; 5973 }()); 5974 5975 KEYENCE.Form.filledFieldValidator = (function () { 5976 var MultiStepForm = null; 5977 5978 var idNames = { 5979 countryField: 'suz_countryID', 5980 companyWrapper: 'suz_div_companyName', 5981 } 5982 5983 var classNames = { 5984 trigger: 'js-validateValue-root', 5985 target: 'js-validateValue-target', 5986 isFieldValid: 'is-field-valid', 5987 required: 'js-form-required', 5988 }; 5989 5990 var config = { 5991 country: '', 5992 notMultiStepForm: false, 5993 isFirstFocus: false, 5994 isFirstPointerDown: false, 5995 }; 5996 5997 var formNames = { 5998 passwordAssistanceActionForm: 'user_passwordAssistanceActionForm', 5999 withdrawActionForm: 'user_profile_withdrawActionForm', 6000 reloginActionForm: 'user_reloginActionForm', 6001 } 6002 6003 var filledFieldValidator = { 6004 targetForm: null, 6005 registerForm: null, 6006 screenSelector: '#' + window.MultiStepForm.PreForm.idNames.root + ', ' + 6007 '#' + window.MultiStepForm.SignIn.idNames.signinForm, 6008 countryField: null, 6009 classNames: classNames, 6010 config: config, 6011 formNames: formNames, 6012 formSelector: 'form[name="' + formNames.passwordAssistanceActionForm + '"], ' + 6013 'form[name="' + formNames.withdrawActionForm + '"], ' + 6014 'form[name="' + formNames.reloginActionForm + '"]', 6015 }; 6016 6017 filledFieldValidator.init = function () { 6018 var fields = document.querySelectorAll('.' + classNames.target); 6019 var multiStepScreens = document.querySelectorAll(this.screenSelector); 6020 var forms = document.querySelectorAll(this.formSelector); 6021 6022 MultiStepForm = window.MultiStepForm; 6023 this.targetForm = multiStepScreens.length ? multiStepScreens : forms; 6024 this.registerForm = document.querySelector('#' + MultiStepForm.Register.idNames.suzRegArea); 6025 this.multiStepForm = document.querySelector('#' + MultiStepForm.idNames.trigger); 6026 6027 if (!fields.length) { 6028 return; 6029 } 6030 6031 if (this.multiStepForm || this.registerForm) { 6032 if (multiStepScreens.length) { 6033 this.initCorrectItem(); 6034 this.attachBlurTargetFormEvent(); 6035 } 6036 6037 if (this.registerForm) { 6038 this.checkCountry(); 6039 this.initRegisterItem(); 6040 this.attachBlurResisterFormEvent(); 6041 this.setMutationObserverRegArea(); 6042 } 6043 6044 if (config.country === 'JP') { 6045 this.setMutationObserverCompany(); 6046 } 6047 } else if (forms.length) { 6048 this.config.notMultiStepForm = true; 6049 6050 this.attachPointerDownTargetFormEvent(); 6051 this.focusFirstElement(forms); 6052 this.attachBlurTargetFormEvent(); 6053 } 6054 }; 6055 6056 filledFieldValidator.initCorrectItem = function () { 6057 var loginUserName = document.getElementById(MultiStepForm.SignIn.idNames.loginUserName); 6058 6059 if (loginUserName) { 6060 this.changeFieldStatus($(loginUserName), true); 6061 } 6062 }; 6063 6064 filledFieldValidator.attachBlurTargetFormEvent = function () { 6065 this.targetForm.forEach(function (form) { 6066 var targetItems = form.querySelectorAll('.' + classNames.target); 6067 6068 if (!targetItems.length) { 6069 return; 6070 } 6071
6072 targetItems.forEach(function (item) { 6073 if (item.classList.contains(classNames.required)) { 6074 item.addEventListener('blur', filledFieldValidator.runPatternValidator); 6075 } else { 6076 item.addEventListener('blur', filledFieldValidator.runBlankValidator.bind(this)); 6077 } 6078 }); 6079 }); 6080 }; 6081 6082 filledFieldValidator.checkCountry = function () { 6083 this.countryField = document.getElementById(idNames.countryField); 6084 6085 if (this.countryField) { 6086 config.country = this.countryField.options[this.countryField.selectedIndex].value; 6087 } 6088 } 6089 6090 filledFieldValidator.initRegisterItem = function () { 6091 var targetItems = null; 6092 var requiredItemsArray = []; 6093 var notRequiredItemsArray = []; 6094 6095 targetItems = this.registerForm.querySelectorAll('.' + classNames.target); 6096 6097 if (targetItems.length) { 6098 requiredItemsArray = Array.prototype.filter.call(targetItems, function (item) { 6099 return ( 6100 item.classList.contains(classNames.required) 6101 && ((item.id !== 'suz_stateID' && item.value !== '') 6102 || (item.id === 'suz_stateID' && item.value !== '00')) 6103 ); 6104 }); 6105 6106 notRequiredItemsArray = Array.prototype.filter.call(targetItems, function (item) { 6107 return (!item.classList.contains(classNames.required)); 6108 }); 6109 } 6110 6111 if (requiredItemsArray.length) { 6112 requiredItemsArray.forEach(function (item) { 6113 window.suz_callRegValidator($(item), item.value); 6114 }); 6115 } 6116 6117 if (notRequiredItemsArray.length) { 6118 notRequiredItemsArray.forEach(function (item) { 6119 filledFieldValidator.runBlankValidator(item); 6120 }); 6121 } 6122 }; 6123 6124 filledFieldValidator.attachBlurResisterFormEvent = function () { 6125 var optionalItems = this.registerForm.querySelectorAll('.' + classNames.target + ':not(.' + classNames.required + ')'); 6126 6127 if (optionalItems.length) { 6128 optionalItems.forEach(function (item) { 6129 item.addEventListener('blur', filledFieldValidator.runBlankValidator.bind(this)); 6130 }); 6131 } 6132 }; 6133 6134 filledFieldValidator.setMutationObserverRegArea = function () { 6135 var target = this.registerForm; 6136 var observer = null; 6137 var observerConfig = { 6138 attributeFilter: ['id'], 6139 childList: true 6140 }; 6141 6142 if (!target) { 6143 return; 6144 } 6145 6146 observer = new MutationObserver(function (record) { 6147 if (record[0].target.id === 'suz_regArea') { 6148 filledFieldValidator.initRegisterItem(); 6149 filledFieldValidator.attachBlurResisterFormEvent(); 6150 filledFieldValidator.checkCountry(); 6151 6152 if (config.country === 'JP') { 6153 filledFieldValidator.setMutationObserverCompany(); 6154 } 6155 } 6156 }); 6157 6158 observer.observe(target, observerConfig); 6159 }; 6160 6161 filledFieldValidator.runBlankValidator = function (item) { 6162 var field = null; 6163 6164 if (typeof item !== 'object' || !item) { 6165 return; 6166 } 6167 6168 if (item.currentTarget) { 6169 field = item.currentTarget; 6170 } else { 6171 field = item; 6172 } 6173 6174 if (!KeyenceForm.ControlErrorDisplay.isTriggerClicked(field)) { 6175 return; 6176 } 6177 6178 if (filledFieldValidator.isBlank(field)) { 6179 filledFieldValidator.changeFieldStatus($(field), false); 6180 } else { 6181 filledFieldValidator.changeFieldStatus($(field), true); 6182 } 6183 }; 6184 6185 filledFieldValidator.runPatternValidator = function () { 6186 if (!KeyenceForm.ControlErrorDisplay.isTriggerClicked(this)) { 6187 return; 6188 } 6189 6190 if (filledFieldValidator.isBlank(this)) { 6191 filledFieldValidator.changeFieldStatus($(this), false); 6192 } else { 6193 filledFieldValidator.updatePatternCheckFieldStatus(this, true); 6194 } 6195 }; 6196 6197 filledFieldValidator.isBlank = function (field) { 6198 if (field.value === '') { 6199 return true; 6200 } 6201 6202 return false; 6203 }; 6204 6205 filledFieldValidator.updatePatternCheckFieldStatus = function (field) { 6206 var formatPattern = ''; 6207 6208 if (typeof field !== 'object' || !field) { 6209 return; 6210 } 6211 6212 formatPattern = field.dataset.formatPattern; 6213 6214 switch (formatPattern) { 6215 case 'email': 6216 this.updateMailField(field); 6217 break; 6218 default: 6219 break; 6220 } 6221 }; 6222 6223 filledFieldValidator.updateMailField = function (field) { 6224 if (/^[a-zA-Z0-9\.!#$%&'*+\/=?^_`{|}~\-]+@[a-zA-Z0-9\-]+(\.[A-Za-z0-9\-]+)+$/.test(field.value)) { 6225 this.changeFieldStatus($(field), true); 6226 MultiStepForm.clearInputError(field.name); 6227 } else { 6228 this.changeFieldStatus($(field), false); 6229 } 6230 }; 6231 6232 filledFieldValidator.changeFieldStatus = function ($field, isValid) { 6233 var $target = $field.closest('.' + classNames.trigger); 6234 var isOptionalField = false; 6235 var fieldValue = $field.val(); 6236 6237 if (!$target.length) { 6238 return; 6239 } 6240 6241 if (!$field.hasClass(classNames.required)) { 6242 isOptionalField = true; 6243 } 6244 6245 if ((isOptionalField && fieldValue === '') 6246 || (isOptionalField && $field[0].tagName === 'SELECT' && Number(fieldValue) === 0) 6247 || $target.hasClass(win.MultiStepForm.Register.classNames.isError)) { 6248 isValid = false; 6249 } 6250 6251 if (isValid) { 6252 $target.addClass(classNames.isFieldValid); 6253 } else { 6254 $target.removeClass(classNames.isFieldValid); 6255 } 6256 } 6257 6258 filledFieldValidator.setMutationObserverCompany = function () { 6259 var target = document.getElementById(idNames.companyWrapper); 6260 var observer = null; 6261 var observerConfig = { 6262 childList: true, 6263 subtree: true 6264 }; 6265 var suggestItems = null; 6266 6267 if (!target) { 6268 return; 6269 } 6270 6271 observer = new MutationObserver(function (record) { 6272 record.forEach(function (data) { 6273 if (!data.addedNodes[0]) { 6274 return; 6275 } 6276 6277 if ((data.addedNodes[0].nodeType === 1)
6278 && (data.target.className === 'StandeStyle-companyList')) { 6279 suggestItems = data.target.querySelectorAll('.StandeStyle-companyItem'); 6280 6281 if (!suggestItems.length) { 6282 return; 6283 } 6284 6285 suggestItems.forEach(function (item) { 6286 item.addEventListener('click', function () { 6287 window.setTimeout(function () { 6288 filledFieldValidator.runSuggestValidator(); 6289 }, 0); 6290 }); 6291 }); 6292 } 6293 }); 6294 }); 6295 6296 observer.observe(target, observerConfig); 6297 }; 6298 6299 filledFieldValidator.runSuggestValidator = function () { 6300 var suggestTargetIdArray = ['suz_zipCode', 'suz_stateID', 'city', 'address']; 6301 6302 suggestTargetIdArray.forEach(function (id) { 6303 var target = filledFieldValidator.registerForm.querySelector('#' + id); 6304 6305 if (target) { 6306 if (target.classList.contains(classNames.required)) { 6307 window.suz_callRegValidator($(target), target.value); 6308 } else { 6309 filledFieldValidator.runBlankValidator(target); 6310 } 6311 } 6312 }); 6313 }; 6314 6315 filledFieldValidator.validateOptionalField = function ($targetArea) { 6316 var $optionalFilledFieldValidatorTargets = null; 6317 6318 if (!$targetArea.length) { 6319 return; 6320 } 6321 6322 $optionalFilledFieldValidatorTargets = $targetArea.find('.' + this.classNames.target + ':not(.' + MultiStepForm.Register.classNames.required + ')').filter(':visible'); 6323 6324 if ($optionalFilledFieldValidatorTargets.length) { 6325 $optionalFilledFieldValidatorTargets.each(function () { 6326 win.suz_callRegValidator($(this), this.value); 6327 }); 6328 } 6329 } 6330 6331 filledFieldValidator.focusFirstElement = function (forms) { 6332 var self = this; 6333 var focusableElements = null; 6334 var element = null; 6335 var BlankFieldValidator = win.KeyenceForm.BlankFieldValidator; 6336 6337 forms.forEach(function (form) { 6338 focusableElements = form.querySelectorAll(MultiStepForm.selectors.focusbleInputElements); 6339 }); 6340 6341 if (focusableElements.length) { 6342 for (element of focusableElements) { 6343 var style = getComputedStyle(element); 6344 6345 if (style && 6346 style.display !== 'none' && 6347 style.visibility !== 'hidden' && 6348 style.opacity !== '0' && 6349 !element.closest('.is-hide') 6350 ) { 6351 requestAnimationFrame(function () { 6352 setTimeout(function () { 6353 element.focus(); 6354 self.config.isFirstFocus = true; 6355 }, 50); 6356 }); 6357 6358 if (!BlankFieldValidator.isBlank(element)) { 6359 self.config.isFirstPointerDown = true; 6360 } 6361 6362 break; 6363 } 6364 } 6365 } 6366 }; 6367 6368 filledFieldValidator.attachPointerDownTargetFormEvent = function () { 6369 window.addEventListener('pointerdown', this.changeFirstPointerDownStatus, false); 6370 }; 6371 6372 filledFieldValidator.changeFirstPointerDownStatus = function () { 6373 var self = filledFieldValidator; 6374 6375 self.config.isFirstPointerDown = true; 6376 window.removeEventListener('pointerdown', self.changeFirstPointerDownStatus, false); 6377 }; 6378 6379 return filledFieldValidator; 6380 }()); 6381 6382 KEYENCE.Form.ControlErrorDisplay = (function () { 6383 var MultiStepForm = null; 6384 6385 var targetFormName = { 6386 passwordAssistanceActionForm: 'user_passwordAssistanceActionForm', 6387 passwordAssistanceResetForm: 'user_passwordAssistance_resetPasswordActionForm', 6388 withdrawActionForm: 'user_profile_withdrawActionForm', 6389 reloginActionForm: 'user_reloginActionForm', 6390 loginActionForm: 'user_loginActionForm', 6391 }; 6392 6393 var ControlErrorDisplay = { 6394 inactiveFlag: true, 6395 idNames: { 6396 multiStepForm: 'js-multiStepForm', 6397 }, 6398 classNames: { 6399 target: 'js-multiStep-targetWrapper', 6400 }, 6401 config: { 6402 isRegisterFlatForm: false,
6403 isEmailRegisterFlatFormSubmitClicked: false, 6404 }, 6405 formSelector: 'form[name="' + targetFormName.passwordAssistanceActionForm + '"], ' + 6406 'form[name="' + targetFormName.passwordAssistanceResetForm + '"], ' + 6407 'form[name="' + targetFormName.withdrawActionForm + '"], ' + 6408 'form[name="' + targetFormName.reloginActionForm + '"], ' + 6409 'form[name="' + targetFormName.loginActionForm + '"]', 6410 targetForm: null, 6411 browserValidatorTarget: null, 6412 }; 6413 6414 ControlErrorDisplay.init = function () { 6415 var multiStepForm = null; 6416 var targetForms = null; 6417 var errorItems = null; 6418 var visibleErrorItem = null; 6419 var isError = false; 6420 6421 MultiStepForm = win.MultiStepForm; 6422 multiStepForm = doc.getElementById(this.idNames.multiStepForm); 6423 6424 if (multiStepForm) { 6425 this.targetForm = multiStepForm.querySelector('form'); 6426 6427 if (!this.targetForm) { 6428 this.targetForm = multiStepForm.closest('form'); 6429 } 6430 } else { 6431 targetForms = doc.querySelectorAll(this.formSelector); 6432 6433 if (targetForms.length) { 6434 this.targetForm = targetForms[0]; 6435 } 6436 } 6437 6438 if (!MultiStepForm || !this.targetForm) { 6439 return; 6440 } 6441 6442 this.config.isRegisterFlatForm = MultiStepForm.Register.isRegFlat(); 6443 this.addInvalidEvent(); 6444 6445 if (this.inactiveFlag) { 6446 this.setInitialStatus(); 6447 } 6448 6449 errorItems = this.targetForm.querySelectorAll('.is-error[id^="suz_div_"]'); 6450 6451 if (errorItems.length) { 6452 errorItems.forEach(function (errorItem) { 6453 var style = null; 6454 6455 if (isError) { 6456 return; 6457 } 6458 6459 style = getComputedStyle(errorItem); 6460 6461 if (style && 6462 style.display !== 'none' && 6463 style.visibility !== 'hidden' && 6464 style.opacity !== '0' && 6465 !errorItem.closest('.is-hide') 6466 ) { 6467 visibleErrorItem = errorItem; 6468 isError = true; 6469 } 6470 }); 6471 } 6472 6473 if (isError) { 6474 this.setTriggerClickedData(visibleErrorItem, MultiStepForm.isShow(MultiStepForm.Register.$root) ? 'register' : ''); 6475 } 6476 }; 6477 6478 ControlErrorDisplay.addInvalidEvent = function () { 6479 var formValidatorTargets = this.targetForm.querySelectorAll('input[type="email"], input[pattern]'); 6480 6481 if (formValidatorTargets.length) { 6482 formValidatorTargets.forEach(function (target) { 6483 target.addEventListener('invalid', ControlErrorDisplay.cancelBrowserValidation.bind(ControlErrorDisplay)); 6484 }); 6485 } 6486 }; 6487 6488 ControlErrorDisplay.cancelBrowserValidation = function (event) { 6489 var target = event.currentTarget; 6490 var isVisible = false; 6491 var submitEvent = new Event('submit', {cancelable: true}); 6492 6493 if (target && 6494 target.checkVisibility({ 6495 opacityProperty: true, 6496 contentVisibilityAuto: true, 6497 })) { 6498 this.browserValidatorTarget = target; 6499 isVisible = true; 6500 } 6501 6502 if (!isVisible) { 6503 this.browserValidatorTarget = null; 6504 6505 return; 6506 } 6507 6508 if (!this.isTriggerClicked(target) && 6509 this.config.isRegisterFlatForm && 6510 MultiStepForm.isShow(MultiStepForm.Register.$root) 6511 ) { 6512 event.preventDefault(); 6513 MultiStepForm.Register.onSubmitForm(event); 6514 } else if (!this.isTriggerClicked(target)) { 6515 event.preventDefault(); 6516 this.targetForm.dispatchEvent(submitEvent); 6517 } 6518 }; 6519 6520 ControlErrorDisplay.setTriggerClickedData = function (trigger,
6520currentScreen) { 6521 var target = null; 6522 6523 if (this.inactiveFlag) { 6524 return; 6525 } 6526 6527 if (typeof trigger !== 'object' || !trigger) { 6528 return; 6529 } 6530 6531 target = trigger.closest('.' + this.classNames.target); 6532 6533 if (currentScreen === 'register' && this.config.isRegisterFlatForm) { 6534 this.config.isEmailRegisterFlatFormSubmitClicked = true; 6535 6536 return; 6537 } else if (!target) { 6538 return; 6539 } 6540 6541 if (currentScreen === 'register') { 6542 target.dataset.emailTriggerButtonClicked = this.getPanelProgressData(trigger); 6543 } else { 6544 target.dataset.emailTriggerButtonClicked = 'true'; 6545 } 6546 }; 6547 6548 ControlErrorDisplay.getPanelProgressData = function (trigger) { 6549 var currentPanel = null; 6550 var currentPanelIndex = ''; 6551 var panelIndexDataArray = []; 6552 6553 currentPanel = trigger.closest('[data-panel-index]'); 6554 6555 if (!currentPanel) { 6556 return ''; 6557 } 6558 6559 currentPanelIndex = currentPanel.dataset.panelIndex; 6560 6561 if (currentPanelIndex) { 6562 panelIndexDataArray = this.getPanelProgressDataArray(Number(currentPanelIndex)); 6563 6564 return panelIndexDataArray.join(); 6565 } 6566 6567 return ''; 6568 }; 6569 6570 ControlErrorDisplay.getPanelProgressDataArray = function (currentPanelIndex) { 6571 var panelIndexDataArray = []; 6572 var i = 0; 6573 6574 if (currentPanelIndex) { 6575 for (i = 0; i < currentPanelIndex; i++) { 6576 panelIndexDataArray.push('panel' + (i + 1)); 6577 } 6578 } 6579 6580 return panelIndexDataArray; 6581 }; 6582 6583 ControlErrorDisplay.resetPanelProgressData = function (triggerId) { 6584 var trigger = null; 6585 var currentPanel = null; 6586 var currentPanelIndex = ''; 6587 var triggerWrapper = null; 6588 var triggerClickedData = ''; 6589 var panelIndexDataArray = []; 6590 6591 if (this.config.isRegisterFlatForm || this.inactiveFlag) { 6592 return; 6593 } 6594 6595 trigger = doc.getElementById(triggerId); 6596 6597 if (!trigger) { 6598 return; 6599 } 6600 6601 currentPanel = trigger.closest('[data-panel-index]'); 6602 6603 if (!currentPanel) { 6604 return; 6605 } 6606 6607 currentPanelIndex = currentPanel.dataset.panelIndex; 6608 triggerWrapper = trigger.closest('.' + this.classNames.target); 6609 6610 if (triggerWrapper) { 6611 triggerClickedData = triggerWrapper.dataset.emailTriggerButtonClicked; 6612 } 6613 6614 if (!triggerClickedData) { 6615 return; 6616 } 6617 6618 if (triggerClickedData.includes('panel' + currentPanelIndex)) { 6619 panelIndexDataArray = this.getPanelProgressDataArray(Number(currentPanelIndex)); 6620 } else { 6621 panelIndexDataArray = this.getPanelProgressDataArray(Number(currentPanelIndex) - 1); 6622 } 6623 6624 if (panelIndexDataArray.length) { 6625 triggerWrapper.dataset.emailTriggerButtonClicked = panelIndexDataArray.join(); 6626 } 6627 }; 6628 6629 ControlErrorDisplay.isTriggerClicked = function (trigger) { 6630 var isClicked = false; 6631 6632 if (typeof trigger !== 'object' || !trigger) { 6633 return isClicked; 6634 } 6635 6636 if (MultiStepForm.isShow(MultiStepForm.Register.$root)) { 6637 if (this.isFlatFormTriggerClicked() || this.matchClickedData(trigger) || this.isInactiveData(trigger, 'register')) { 6638 isClicked = true; 6639 } 6640 } else { 6641 if (trigger.closest('[data-email-trigger-button-clicked="true"]') || this.isInactiveData(trigger)) { 6642 isClicked = true; 6643 } 6644 } 6645 6646 return isClicked; 6647 }; 6648 6649 ControlErrorDisplay.isFlatFormTriggerClicked = function () { 6650 if (!this.config.isRegisterFlatForm) { 6651 return false; 6652 } 6653 6654 if (this.config.isEmailRegisterFlatFormSubmitClicked) { 6655 return true; 6656 } 6657 6658 return false; 6659 }; 6660 6661 ControlErrorDisplay.matchClickedData = function (trigger) { 6662 var target = null;
6663 var isClicked = false; 6664 var currentPanel = null; 6665 var currentPanelIndex = ''; 6666 var clickedDataValue = ''; 6667 6668 if (typeof trigger !== 'object' || !trigger) { 6669 return isClicked; 6670 } 6671 6672 target = trigger.closest('.' + this.classNames.target); 6673 currentPanel = trigger.closest('[data-panel-index]'); 6674 6675 if (!target || !currentPanel) { 6676 return isClicked; 6677 } 6678 6679 clickedDataValue = target.dataset.emailTriggerButtonClicked; 6680 currentPanelIndex = currentPanel.dataset.panelIndex; 6681 6682 if (!clickedDataValue || !currentPanelIndex) { 6683 return isClicked; 6684 } 6685 6686 if (clickedDataValue.includes('panel' + currentPanelIndex)) { 6687 isClicked = true; 6688 } 6689 6690 return isClicked; 6691 }; 6692 6693 ControlErrorDisplay.validateInactivePanel = function (triggerId) { 6694 var trigger = null; 6695 var registerFormWrapper = null; 6696 var currentPanel = null; 6697 var currentPanelIndex = ''; 6698 var inactivePanels = null; 6699 var validateTargets = null; 6700 6701 if (typeof triggerId !== 'string' || !triggerId || !this.config.isRegisterFlatForm) { 6702 return; 6703 } 6704 6705 trigger = doc.getElementById(triggerId); 6706 6707 if (!trigger) { 6708 return; 6709 } 6710 6711 if (MultiStepForm.isEditProfileForm()) { 6712 registerFormWrapper = this.targetForm; 6713 } else { 6714 registerFormWrapper = trigger.closest('.' + this.classNames.target); 6715 } 6716 6717 currentPanel = trigger.closest('[data-panel-index]'); 6718 6719 if (!registerFormWrapper || !currentPanel) { 6720 return; 6721 } 6722 6723 currentPanelIndex = currentPanel.dataset.panelIndex; 6724 6725 if (!currentPanelIndex) { 6726 return; 6727 } 6728 6729 inactivePanels = registerFormWrapper.querySelectorAll('[data-panel-index]:not([data-panel-index="'+ currentPanelIndex +'"])'); 6730 6731 if (inactivePanels.length) { 6732 inactivePanels.forEach(function (panel) { 6733 validateTargets = panel.querySelectorAll('.suz_rr'); 6734 6735 if (validateTargets.length) { 6736 validateTargets.forEach(function (target) { 6737 suz_checkEntryItem($(target)); 6738 }); 6739 } 6740 }); 6741 } 6742 }; 6743 6744 ControlErrorDisplay.setInitialStatus = function () { 6745 var targets = doc.querySelectorAll('.' + this.classNames.target); 6746 6747 if (this.config.isRegisterFlatForm) { 6748 this.config.isErrorDisplayControlInactive = true; 6749 } 6750 6751 if (!targets.length) { 6752 return; 6753 } 6754 6755 targets.forEach(function (target) { 6756 if (ControlErrorDisplay.config.isRegisterFlatForm && 6757 target.querySelectorAll('[data-panel-index]').length 6758 ) { 6759 return; 6760 } 6761 6762 target.dataset.errorDisplayControl = 'inactive'; 6763 }); 6764 }; 6765 6766 ControlErrorDisplay.isInactiveData = function (target, screen) { 6767 var isInactive = false; 6768 6769 if (screen === 'register' && 6770 this.config.isRegisterFlatForm && 6771 this.config.isErrorDisplayControlInactive 6772 ) { 6773 return true; 6774 } 6775 6776 if (!target || typeof target !== 'object') { 6777 return false; 6778 } 6779 6780 if (target.closest('[data-error-display-control="inactive"]')) { 6781 isInactive = true; 6782 } 6783 6784 return isInactive; 6785 }; 6786 6787 return ControlErrorDisplay; 6788 }()); 6789 6790 win.KeyenceForm = KEYENCE.Form; 6791 6792 KEYENCE.Form.OTPControl = (function () { 6793 var OTPControl = {}; 6794 6795 OTPControl.init = function () { 6796 if ('OTPCredential' in window) { 6797 var input = document.querySelector('input[autocomplete="one-time-code"]'); 6798 var ac; 6799 var form; 6800 6801 if (!input) return; 6802 6803 ac = new AbortController(); 6804 form = input.closest('form'); 6805 6806 if (ac && form) { 6807 form.addEventListener('submit', function() { 6808 ac.abort(); 6809 }); 6810 } 6811 6812 navigator.credentials.get({ 6813 otp: {transport:['sms']} 6814 }).then(function(otp){ 6815 var $otpInput = $(form).find('input[autocomplete="one-time-code"]:visible'); 6816 6817 if ($otpInput.length === 1) { 6818 $otpInput.val(otp.code); 6819 $otpInput.get(0).dispatchEvent(new Event('change'));
6820 } 6821 }).catch(function(err){ 6822 console.log(err); 6823 }); 6824 } 6825 }; 6826 6827 return OTPControl; 6828 }()); 6829 6830 KEYENCE.Form.ToggleDisabled = (function () { 6831 var ToggleDisabled = {}; 6832 6833 var classNames = { 6834 root: 'js-toggleDisabled-root', 6835 trigger: 'js-toggleDisabled-trigger', 6836 target: 'js-toggleDisabled-target' 6837 }; 6838 6839 ToggleDisabled.init = function () { 6840 var self = this; 6841 var roots = doc.querySelectorAll('.' + classNames.root); 6842 6843 if (!roots.length) { 6844 return; 6845 } 6846 6847 roots.forEach(function (root) { 6848 var trigger = root.querySelector('.' + classNames.trigger); 6849 var target = root.querySelector('.' + classNames.target); 6850 6851 if (!trigger || !target) { 6852 return; 6853 } 6854 6855 self.default(target); 6856 self.onClick(root, trigger, target); 6857 self.onChange(trigger, target); 6858 }); 6859 }; 6860 6861 ToggleDisabled.default = function (target) { 6862 if (target) { 6863 target.disabled = true; 6864 target.style.pointerEvents = 'none'; 6865 } 6866 }; 6867 6868 ToggleDisabled.onClick = function (root, trigger, target) { 6869 root.addEventListener('click', function () { 6870 if (trigger.checked === false) { 6871 trigger.checked = true; 6872 target.style.pointerEvents = 'auto'; 6873 target.disabled = false; 6874 win.setTimeout(function() { 6875 target.focus(); 6876 }, 0); 6877 } 6878 }); 6879 6880 trigger.addEventListener('focus', function () { 6881 if (trigger.checked === false) { 6882 trigger.checked = true; 6883 target.disabled = false; 6884 } 6885 }); 6886 }; 6887 6888 ToggleDisabled.onChange = function (trigger, target) { 6889 var triggerName = trigger.name; 6890 var radioElements = doc.querySelectorAll(`[name="${triggerName}"]`); 6891 6892 if (!triggerName) { 6893 return; 6894 } 6895 6896 radioElements.forEach(function (radioElement) { 6897 radioElement.addEventListener('change', function (event) { 6898 if (!event.target.classList.contains('.' + classNames.trigger)) { 6899 target.disabled = true; 6900 target.style.pointerEvents = 'none'; 6901 } 6902 }); 6903 }); 6904 }; 6905 6906 return ToggleDisabled; 6907 })(); 6908 KEYENCE.Form.MultiFactorAuthentication = (function () { 6909 var MultiFactorAuthentication = {}; 6910 var MultiStepForm = null; 6911 6912 var classNames = { 6913 isHide: 'is-hide', 6914 root: 'js-controlVerificationTargetValue', 6915 mobileNumber: 'js-controlVerificationTargetValue-mobileNumber', 6916 countryId: 'js-controlVerificationTargetValue-countryId', 6917 sendCode: 'js-controlVerificationTargetValue-sendCode', 6918 sendCodeTrigger: 'js-controlVerificationTargetValue-sendCodeTrigger', 6919 edit: 'js-controlVerificationTargetValue-edit', 6920 editTrigger: 'js-controlVerificationTargetValue-editTrigger', 6921 deleteDialog: 'js-controlVerificationTargetValue-deleteDialog', 6922 deleteDialogTrigger: 'js-controlVerificationTargetValue-deleteDialogTrigger', 6923 editEnded: 'js-controlVerificationTargetValue-editEnded', 6924 editEndedTrigger: 'js-controlVerificationTargetValue-editEndedTrigger', 6925 email: 'js-controlVerificationTargetValue-email', 6926 dialogCloseButton: 'js-dialog__closeButton', 6927 checkSMSCodeValidTrigger: 'js-checkSMSCodeValid-trigger', 6928 checkSMSCodeValidTarget: 'js-checkSMSCodeValid-target', 6929 checkSMSCodeValidLoadingIndicator: 'js-checkSMSCodeValid-loadingIndicator', 6930 formSuccessTextOuter: 'js-form-successTextOuter', 6931 formErrText: 'js-formErrText',
6932 isError: 'is-error', 6933 }; 6934 6935 var idNames = { 6936 verificationEmailCodeDiv: 'suz_div_verificationEmailCode', 6937 verificationCodeDiv: 'suz_div_verificationCode', 6938 editProfileSubmitButton: 'submit2' 6939 }; 6940 6941 var elements = { 6942 roots: [], 6943 editProfileSubmitButton: doc.getElementById(idNames.editProfileSubmitButton) 6944 }; 6945 6946 var selectors = { 6947 dialogCancelButton: '#js-controlVerificationTargetValue-emailCancel, #js-controlVerificationTargetValue-mobileNumberCancel', 6948 dialogDeleteButton: '#js-controlVerificationTargetValue-emailDelete, #js-controlVerificationTargetValue-mobileNumberDelete', 6949 deleteDialogTriggerFallback: '.js-controlVerificationTargetValue-deleteDialog a[href^="#"], .js-controlVerificationTargetValue-deleteDialog [aria-controls]' 6950 }; 6951 6952 var rootStates = new WeakMap(); 6953 var dialogButtonsWithEvents = new WeakSet(); 6954 var attachedRoots = new WeakSet(); 6955 // Managed with string keys separately from WeakMap to persist the deleted state even when DOM nodes are recreated 6956 var deletedRootKeys = new Set(); 6957 // String key management to persist the editing state across full DOM node replacements 6958 var editingRootKeys = new Set(); 6959 // Stores confirmed values at the time editing began, keyed by string (managed separately from WeakMap) 6960 var savedValuesByKey = new Map(); 6961 // Key management to restore confirmed values even when the framework restores the DOM after editEndedTrigger (cancel) is clicked 6962 var cancelledRootKeys = new Set(); 6963 6964 var urls = { 6965 createVerificationCode: '/ajax/registrationAjax/createVerificationCode/', 6966 createVerificationCodeForEmail: '/ajax/registrationAjax/createVerificationCodeForEmail/', 6967 checkVerificationCode: '/ajax/registrationAjax/checkVerificationCode/', 6968 checkVerificationCodeForEmail: '/ajax/registrationAjax/checkVerificationCodeForEmail/' 6969 }; 6970 6971 MultiFactorAuthentication = { 6972 initialClickedEditButtonArray: [], 6973 initialErrorItemRootArray: [] 6974 } 6975 6976 /** 6977 * Returns a stable string key based on the input type of the root element. 6978 * The same key is maintained even when the DOM node is replaced. 6979 */ 6980 function getRootKey(root) { 6981 if (root.querySelector('.' + classNames.email)) { 6982 return 'email'; 6983 } 6984 if (root.querySelector('.' + classNames.mobileNumber)) { 6985 return 'mobileNumber'; 6986 } 6987 // If neither of the above, fall back to the order of appearance in the DOM 6988 var allRoots = doc.querySelectorAll('.' + classNames.root); 6989 return 'index-' + Array.prototype.indexOf.call(allRoots, root); 6990 } 6991 6992 MultiFactorAuthentication.init = function () { 6993 elements.roots = doc.querySelectorAll('.' + classNames.root); 6994 6995 if (!elements.roots.length) { 6996 return; 6997 } 6998 6999 // Turn off the SMSCodeButton event to avoid duplicate firing with click.formSMSCodeButton when root elements exist 7000 $(doc).off('click.formSMSCodeButton'); 7001 7002 MultiStepForm = win.MultiStepForm; 7003 7004 this.setupRoots(); 7005 this.restoreErrorState(); 7006 7007 // Register events if dialog buttons are already in the DOM (applies to all roots) 7008 this.attachDialogButtonEvents(); 7009 7010 // Start MutationObserver only once on the first init() call 7011 if (!MultiFactorAuthentication._observer) { 7012 MultiFactorAuthentication._observer = this.observe(); 7013 } 7014 }; 7015 7016 MultiFactorAuthentication.setupRoots = function () { 7017 var self = this; 7018 7019 elements.roots.forEach(function (root) { 7020 var scope = self.getRootScope(root); 7021 var state = self.getRootState(root); 7022 var rootKey = getRootKey(root); 7023 7024 if (state.isDeleted || deletedRootKeys.has(rootKey)) { 7025 // If deleted, cancel the framework's DOM value restoration and save the state 7026 self.clearValues(scope); 7027 state.isDeleted = true; 7028 } else if (editingRootKeys.has(rootKey)) { 7029 // If a markup change occurs during editing: write back the confirmed values from before editing started and cancel the editing state 7030 var preEditValues = savedValuesByKey.get(rootKey); 7031 if (preEditValues) { 7032 if (scope.emailInput) scope.emailInput.value = preEditValues.email; 7033 if (scope.mobileNumberInput) scope.mobileNumberInput.value = preEditValues.mobileNumber; 7034 if (scope.countryId) scope.countryId.value = preEditValues.countryId; 7035 } 7036 editingRootKeys.delete(rootKey); 7037 savedValuesByKey.delete(rootKey);
7038 cancelledRootKeys.delete(rootKey); 7039 // Restore the UI to the display state before editing 7040 self.setDefaultDisplay(scope); 7041 } else if (cancelledRootKeys.has(rootKey)) { 7042 // If the framework restores unverified values to the DOM after editEndedTrigger (cancel): write back the confirmed values 7043 // Since the framework may keep injecting the same unverified value through multiple re-renders, 7044 // do not remove the key until the user takes the next action (re-edit, verification success, or deletion) 7045 var cancelledValues = savedValuesByKey.get(rootKey); 7046 if (cancelledValues) { 7047 if (scope.emailInput) scope.emailInput.value = cancelledValues.email; 7048 if (scope.mobileNumberInput) scope.mobileNumberInput.value = cancelledValues.mobileNumber; 7049 if (scope.countryId) scope.countryId.value = cancelledValues.countryId; 7050 } 7051 } 7052 7053 self.saveCurrentValues(root, scope); 7054 self.saveConfirmedValues(root, scope); 7055 self.disableInputs(scope); 7056 self.initCheckSMSCodeValidButton(scope); 7057 self.initDeleteDialogTrigger(scope); 7058 7059 if (!attachedRoots.has(root)) { 7060 attachedRoots.add(root); 7061 self.attachEvents(root, scope); 7062 } 7063 }); 7064 }; 7065 7066 /** 7067 * Restores the UI state for elements that have validation errors on init. 7068 * - If a root element (.js-controlVerificationTargetValue) has is-error, 7069 * click its editTrigger to re-enter editing mode. 7070 * - If the phone number verification code div (#suz_div_verificationCode) has is-error, 7071 * show the div and enable the verification code input. 7072 * - If the email verification code div (#suz_div_verificationEmailCode) has is-error, 7073 * show the div and enable the verification code input. 7074 */ 7075 MultiFactorAuthentication.restoreErrorState = function () { 7076 var self = this; 7077 7078 // Click editTrigger for any root that has an error state 7079 elements.roots.forEach(function (root) { 7080 if (root.classList.contains(classNames.isError)) { 7081 var editTrigger = root.querySelector('button.' + classNames.editTrigger); 7082 self.initialErrorItemRootArray.push(root); 7083 if (editTrigger) { 7084 self.initialClickedEditButtonArray.push(editTrigger); 7085 editTrigger.click(); 7086 } 7087 } 7088 }); 7089 7090 // For each verification code div with is-error: 7091 // show the div, enable the input, click editTrigger if not already clicked, attach events, and update the submit button state 7092 [idNames.verificationCodeDiv, idNames.verificationEmailCodeDiv].forEach(function (divId) { 7093 var div = doc.getElementById(divId); 7094 if (!div || !div.classList.contains(classNames.isError)) { 7095 return; 7096 } 7097 7098 div.classList.remove(classNames.isHide); 7099 7100 var input = div.querySelector('input.' + classNames.checkSMSCodeValidTarget); 7101 if (input) { 7102 input.removeAttribute('disabled'); 7103 } 7104 7105 // Find the root whose scope is associated with this div, then attach events 7106 elements.roots.forEach(function (root) { 7107 var scope = self.getRootScope(root); 7108 if (scope.verificationCodeDiv !== div) { 7109 return; 7110 } 7111 // Click editTrigger if the root itself does not have is-error (already handled above) 7112 if (!root.classList.contains(classNames.isError)) { 7113 var editTrigger = root.querySelector('button.' + classNames.editTrigger); 7114 if (editTrigger) { 7115 self.initialClickedEditButtonArray.push(editTrigger); 7116 editTrigger.click(); 7117 } 7118 } 7119 // Attach input/click events to checkSMSCodeValidTarget and checkSMSCodeValidTrigger 7120 // (attachSMSCodeValidEvents uses handler tracking to prevent duplicate registration) 7121 self.attachSMSCodeValidEvents(root, scope); 7122 // Reflect the current input value in the submit button's disabled state 7123 if (scope.checkSMSCodeValidTrigger && scope.checkSMSCodeValidTarget) { 7124 scope.checkSMSCodeValidTrigger.disabled = scope.checkSMSCodeValidTarget.value.length === 0; 7125 } 7126 }); 7127 }); 7128 }; 7129 7130 MultiFactorAuthentication.resolveDialogFromTrigger = function (trigger) { 7131 var dialogId = trigger.getAttribute('aria-controls') || ''; 7132 var href = trigger.href || ''; 7133 7134 if (!dialogId && href.indexOf('#') === 0) { 7135 dialogId = href.replace('#', ''); 7136 } 7137 7138 return dialogId ? doc.getElementById(dialogId) : null; 7139 }; 7140 7141 MultiFactorAuthentication.getRootScope = function (root) { 7142 var deleteDialogTrigger = root.querySelector('.' + classNames.deleteDialogTrigger); 7143 var dialog = null; 7144 var verificationCodeDiv = null; 7145 7146 if (!deleteDialogTrigger) { 7147 deleteDialogTrigger = root.querySelector(selectors.deleteDialogTriggerFallback); 7148 } 7149 7150 if (deleteDialogTrigger) { 7151 dialog = MultiFactorAuthentication.resolveDialogFromTrigger(deleteDialogTrigger); 7152 } 7153 7154 if (!dialog) { 7155 dialog = root.querySelector('dialog'); 7156 } 7157 7158 if (root.querySelector('.' + classNames.email)) { 7159 verificationCodeDiv = doc.getElementById(idNames.verificationEmailCodeDiv); 7160 } else { 7161 verificationCodeDiv = doc.getElementById(idNames.verificationCodeDiv); 7162 } 7163 7164 return { 7165 root: root, 7166 emailInput: root.querySelector('.' + classNames.email), 7167 mobileNumberInput: root.querySelector('.' + classNames.mobileNumber), 7168 countryId: root.querySelector('.' + classNames.c
7168ountryId), 7169 sendCode: root.querySelector('.' + classNames.sendCode), 7170 sendCodeTrigger: root.querySelector('.' + classNames.sendCodeTrigger), 7171 edit: root.querySelector('.' + classNames.edit), 7172 editTrigger: root.querySelector('.' + classNames.editTrigger), 7173 deleteDialog: root.querySelector('.' + classNames.deleteDialog), 7174 deleteDialogTrigger: deleteDialogTrigger, 7175 editEnded: root.querySelector('.' + classNames.editEnded), 7176 editEndedTrigger: root.querySelector('.' + classNames.editEndedTrigger), 7177 dialog: dialog, 7178 dialogCloseButton: dialog?.querySelector('.' + classNames.dialogCloseButton), 7179 dialogCancelButton: dialog?.querySelector(selectors.dialogCancelButton), 7180 dialogDeleteButton: dialog?.querySelector(selectors.dialogDeleteButton), 7181 verificationCodeDiv: verificationCodeDiv, 7182 checkSMSCodeValidTrigger: verificationCodeDiv?.querySelector('.' + classNames.checkSMSCodeValidTrigger), 7183 checkSMSCodeValidTarget: verificationCodeDiv?.querySelector('.' + classNames.checkSMSCodeValidTarget), 7184 checkSMSCodeValidLoadingIndicator: verificationCodeDiv?.querySelector('.' + classNames.checkSMSCodeValidLoadingIndicator), 7185 }; 7186 }; 7187 7188 MultiFactorAuthentication.getRootState = function (root) { 7189 if (!rootStates.has(root)) { 7190 rootStates.set(root, { 7191 savedValues: { 7192 email: '', 7193 mobileNumber: '', 7194 countryId: '' 7195 }, 7196 confirmedValues: { 7197 email: '', 7198 mobileNumber: '' 7199 }, 7200 isVerified: false, 7201 isDeleted: false 7202 }); 7203 } 7204 7205 return rootStates.get(root); 7206 }; 7207 7208 MultiFactorAuthentication.saveCurrentValues = function (root, scope) { 7209 var state = this.getRootState(root); 7210 7211 state.savedValues.email = scope.emailInput?.value ?? ''; 7212 state.savedValues.mobileNumber = scope.mobileNumberInput?.value ?? ''; 7213 state.savedValues.countryId = scope.countryId?.value ?? ''; 7214 }; 7215 7216 MultiFactorAuthentication.saveConfirmedValues = function (root, scope) { 7217 var state = this.getRootState(root); 7218 state.confirmedValues.email = scope.emailInput?.value ?? ''; 7219 state.confirmedValues.mobileNumber = scope.mobileNumberInput?.value ?? ''; 7220 }; 7221 7222 MultiFactorAuthentication.disableInputs = function (scope) { 7223 if (scope.emailInput) { 7224 scope.emailInput.disabled = true; 7225 } 7226 if (scope.mobileNumberInput) { 7227 scope.mobileNumberInput.disabled = true; 7228 } 7229 if (scope.countryId) { 7230 scope.countryId.disabled = true; 7231 } 7232 }; 7233 7234 MultiFactorAuthentication.enableInputs = function (scope) { 7235 if (scope.emailInput) { 7236 scope.emailInput.disabled = false; 7237 } 7238 if (scope.mobileNumberInput) { 7239 scope.mobileNumberInput.disabled = false; 7240 } 7241 if (scope.countryId) { 7242 scope.countryId.disabled = false; 7243 } 7244 }; 7245 7246 MultiFactorAuthentication.enableAllInputs = function () { 7247 var self = this; 7248 elements.roots.forEach(function (root) { 7249 var scope = self.getRootScope(root); 7250 self.enableInputs(scope); 7251 }); 7252 }; 7253 7254 MultiFactorAuthentication.attachEvents = function (root, scope) { 7255 var self = this; 7256 7257 if (scope.editTrigger) { 7258 scope.editTrigger.addEventListener('click', function (event) { 7259 self.onClickEditTrigger(event, root, scope); 7260 }); 7261 } 7262 7263 if (scope.editEndedTrigger) { 7264 scope.editEndedTrigger.addEventListener('click', function (event) { 7265 self.onClickEditEndedTrigger(event, root, scope); 7266 }); 7267 } 7268 7269 if (scope.sendCodeTrigger) { 7270 scope.sendCodeTrigger.addEventListener('click', function (event) { 7271 self.onClickSendCodeTrigger(event, root, scope); 7272 }); 7273 } 7274 7275 if (scope.deleteDialogTrigger) { 7276 scope.deleteDialogTrigger.addEventListener('click', function (event) { 7277 self.onClickDeleteDialogTrigger(event, root, scope); 7278 }); 7279 } 7280 7281 self.attachSMSCodeValidEvents(root, scope); 7282 7283 var attachVerifiedBlurEvent = function (input, savedValueKey) { 7284 input.addEventListener('blur', function () { 7285 var state = self.getRootState(root); 7286 if (state.isVerified && input.value !== state.savedValues[savedValueKey]) { 7287 root.querySelectorAll('.' + classNames.formSuccessTextOuter).forEach(function (el) { 7288 el.classList.add(classNames.isHide); 7289 }); 7290 } 7291 }); 7292 }; 7293 7294 if (scope.emailInput) { 7295 scope.emailInput.addEventListener('change', function () { 7296 self.updateDeleteDialogTriggerState(scope); 7297 }); 7298 attachVerifiedBlurEvent(scope.emailInput, 'email'); 7299 } 7300 7301 if (scope.mobileNumberInput) { 7302 scope.mobileNumberInput.addEventListener('change', function () { 7303 self.updateDeleteDialogTriggerState(scope); 7304 }); 7305 attachVerifiedBlurEvent(scope.mobileNumberInput, 'mobileNumber'); 7306 } 7307 }; 7308 7309 /** 7310 * Attaches input and click events to the SMS/email verification code input and submit button. 7311 * Stores handlers on the element to prevent duplicate attachment across multiple calls 7312 * (e.g., from attachEvents during init and from restoreErrorState on error page reload). 7313 */ 7314 MultiFactorAuthentication.attachSMSCodeValidEvents = function (root, scope) { 7315 var self = this; 7316 7317 if (scope.checkSMSCodeValidTarget && !scope.checkSMSCodeValidTarget._mfaInputHandler) { 7318 scope.checkSMSCodeValidTarget._mfaInputHandler = function () { 7319 self.onInputCheckSMSCodeValid(scope); 7320 }; 7321 scope.checkSMSCodeValidTarget.addEventListener('input', scope.checkSMSCodeValidTarget._mfaInputHandler); 7322 } 7323 7324 if (scope.checkSMSCodeValidTrigger && !scope.checkSMSCodeValidTrigger._mfaClickHandler) { 7325 scope.checkSMSCodeValidTrigger._mfaClickHandler = function (event) { 7326 self.onClickCheckSMSCodeValid(event, root, scope); 7327 }; 7328 scope.checkSMSCodeValidTrigger.addEventListener('click', scope.checkSMSCodeValidTrigger._mfaClickHandler); 7329 } 7330 }; 7331 7332 MultiFactorAuthentication.initCheckSMSCodeValidButton = function (scope) { 7333 if (!scope.checkSMSCodeValidTrigger) { 7334 return; 7335 } 7336 scope.checkSMSCodeValidTrigger.disabled = true; 7337 }; 7338 7339 MultiFactorAuthentication.onInputCheckSMSCodeValid = function (scope) { 7340 if (!scope.checkSMSCodeValidTrigger || !scope.checkSMSCodeValidTarget) { 7341 return; 7342 } 7343 scope.checkSMSCodeValidTrigger.disabled = scope.checkSMSCodeValidTarget.value.length === 0; 7344 }; 7345 7346 MultiFactorAuthentication.onClickCheckSMSCodeValid = function (event, root, scope) { 7347 var self = this; 7348 var MultiStepForm = win.MultiStepForm; 7349 var verificationCode = scope.checkSMSCodeValidTarget?.value ?? ''; 7350 var inputName = scope.checkSMSCodeValidTarget?.name ?? ''; 7351 7352 if (!verificationCode) { 7353 return; 7354 } 7355 7356 if (scope.checkSMSCodeValidTrigger) { 7357 scope.checkSMSCodeValidTrigger.disabled = true; 7358 } 7359 if (scope.checkSMSCodeValidLoadingIndicator) { 7360 scope.checkSMSCodeValidLoadingIndicator.classList.remove(classNames.isHide); 7361 } 7362 7363 var restoreUI = function () { 7364 if (scope.checkSMSCodeValidTrigger) { 7365 scope.checkSMSCodeValidTrigger.disabled = false; 7366 } 7367 if (scope.checkSMSCodeValidLoadingIndicator) { 7368 scope.checkSMSCodeValidLoadingIndicator.classList.add(classNames.isHide); 7369 } 7370 }; 7371 7372 if (scope.emailInput) { 7373 var emailAddress = scope.emailInput.value; 7374 7375 self.checkVerificationCodeForEmail(emailAddress, verificationCode).done(function (data) { 7376 if (data?.message) { 7377 if (MultiStepForm?.insertErrorText) { 7378 MultiStepForm.insertErrorText(inputName, data.message); 7379 } 7380 } else { 7381 if (MultiStepForm?.clearInputError) { 7382 MultiStepForm.clearInputError(inputName, true); 7383 } 7384 self.onVerificationSuccess(root, scope); 7385 } 7386 }).fail(function (jqXHR, textStatus) { 7387 if (jqXHR && jqXHR.status !== 200) { 7388 if (MultiStepForm?.insertErrorText) { 7389 MultiStepForm.insertErrorText(inputName, kpi_translation.ServerConnectErrorMessage); 7390 } 7391 return; 7392 } 7393 if (MultiStepForm?.asyncErrorHundler) { 7394 MultiStepForm.asyncErrorHundler(jqXHR?.status ?? 0, textStatus); 7395 } 7396 }).always(function () { 7397 restoreUI(); 7398 }); 7399 } else if (scope.mobileNumberInput && scope.countryId) { 7400 var mobileNumber = scope.mobileNumberInput.value; 7401 var mobileCountryId = scope.countryId.value; 7402 7403 self.checkVerificationCodeForPhone(mobileCountryId, mobileNumber, verificationCode).done(function (data) { 7404 if (data?.message) { 7405 if (MultiStepForm?.insertErrorText) { 7406 MultiStepForm.insertErrorText(inputName, data.message); 7407 } 7408 } else { 7409 if (MultiStepForm?.clearInputError) { 7410 MultiStepForm.clearInputError(inputName, true); 7411 } 7412 self.onVerificationSuccess(root, scope); 7413 } 7414 }).fail(function (jqXHR, textStatus) { 7415 if (jqXHR && jqXHR.status !== 200) { 7416 if (MultiStepForm?.insertErrorText) { 7417 MultiStepForm.insertErrorText(inputName, kpi_translation.ServerConnectErrorMessage); 7418 } 7419 return; 7420 } 7421 if (MultiStepForm?.asyncErrorHundler) { 7422 MultiStepForm.asyncErrorHundler(jqXHR?.status ?? 0, textStatus); 7423 } 7424 }).always(function () { 7425 restoreUI(); 7426 }); 7427 } 7428 }; 7429 7430 MultiFactorAuthentication.onVerificationSuccess = function (root, scope) { 7431 var state = this.getRootState(root); 7432 state.isVerified = true; 7433 state.isDeleted = false; 7434 deletedRootKeys.delete(getRootKey(root)); 7435 editingRootKeys.delete(getRootKey(root));
7436 cancelledRootKeys.delete(getRootKey(root)); 7437 savedValuesByKey.delete(getRootKey(root)); 7438 root.querySelectorAll('.' + classNames.formSuccessTextOuter).forEach(function (el) { 7439 el.classList.remove(classNames.isHide); 7440 }); 7441 this.saveConfirmedValues(root, scope); 7442 this.disableInputs(scope); 7443 this.setDefaultDisplay(scope); 7444 this.updateDeleteDialogTriggerState(); 7445 if (MultiStepForm.isEditProfileForm()) { 7446 this.removeSubmitTriggerDisabled(); 7447 } 7448 }; 7449 7450 MultiFactorAuthentication.initDeleteDialogTrigger = function (scope) { 7451 this.updateDeleteDialogTriggerState(scope); 7452 }; 7453 7454 MultiFactorAuthentication.updateDeleteDialogTriggerState = function () { 7455 var self = this; 7456 7457 // Check the values of all scopes 7458 var allScopeData = []; 7459 elements.roots.forEach(function (root) { 7460 var scope = self.getRootScope(root); 7461 var state = self.getRootState(root); 7462 var emailValue = scope.emailInput?.value ?? ''; 7463 var mobileValue = scope.mobileNumberInput?.value ?? ''; 7464 var hasValue = emailValue.length > 0 || mobileValue.length > 0; 7465 7466 // Consider a scope confirmed only if the current input value matches confirmedValues (the correct registered or verified value) 7467 var isConfirmed = hasValue && 7468 emailValue === state.confirmedValues.email && 7469 mobileValue === state.confirmedValues.mobileNumber; 7470 7471 allScopeData.push({ 7472 scope: scope, 7473 hasValue: hasValue, 7474 isConfirmed: isConfirmed 7475 }); 7476 }); 7477 7478 // Number of confirmed scopes 7479 var confirmedScopesCount = allScopeData.filter(function (item) { 7480 return item.isConfirmed; 7481 }).length; 7482 7483 // Whether any scope has a value 7484 var anyHasValue = allScopeData.some(function (item) { 7485 return item.hasValue; 7486 }); 7487 7488 // Always disable the delete button when there is only one root 7489 var isSingleRoot = allScopeData.length <= 1; 7490 7491 // Enable only when all scopes are confirmed and at least one has a value (disable otherwise) 7492 allScopeData.forEach(function (item) { 7493 if (!item.scope.deleteDialogTrigger) { 7494 return; 7495 } 7496 var shouldDisable = isSingleRoot || confirmedScopesCount !== allScopeData.length || !anyHasValue; 7497 item.scope.deleteDialogTrigger.disabled = shouldDisable; 7498 item.scope.deleteDialogTrigger.setAttribute('aria-disabled', shouldDisable ? 'true' : 'false'); 7499 item.scope.deleteDialogTrigger.setAttribute('tabindex', shouldDisable ? '-1' : '0'); 7500 }); 7501 }; 7502 7503 MultiFactorAuthentication.createVerificationCodeForPhone = function (mobileCountryId, mobileNumber) { 7504 var deferred = new $.Deferred(); 7505 7506 if (typeof mobileCountryId !== 'string' || 7507 typeof mobileNumber !== 'string' 7508 ) { 7509 return deferred.reject(); 7510 } 7511 7512 $.ajax({
7513 url: win.suz_getCurrentDomain() + urls.createVerificationCode, 7514 data: { 7515 mobileCountryId: mobileCountryId, 7516 mobileNumber: mobileNumber 7517 }, 7518 dataType: 'jsonp', 7519 jsonp: 'callback', 7520 scriptCharset: 'UTF-8' 7521 }).done(function (data) { 7522 deferred.resolve(data); 7523 }).fail(function (jqXHR, textStatus, errorThrown) { 7524 deferred.reject(jqXHR, textStatus, errorThrown); 7525 }); 7526 7527 return deferred.promise(); 7528 }; 7529 7530 MultiFactorAuthentication.createVerificationCodeForEmail = function (emailAddress) { 7531 var deferred = new $.Deferred(); 7532 7533 if (typeof emailAddress !== 'string') { 7534 return deferred.reject(); 7535 } 7536 7537 $.ajax({ 7538 url: win.suz_getCurrentDomain() + urls.createVerificationCodeForEmail, 7539 data: { 7540 emailAddress: emailAddress 7541 }, 7542 dataType: 'jsonp', 7543 jsonp: 'callback', 7544 scriptCharset: 'UTF-8' 7545 }).done(function (data) { 7546 deferred.resolve(data); 7547 }).fail(function (jqXHR, textStatus, errorThrown) { 7548 deferred.reject(jqXHR, textStatus, errorThrown); 7549 }); 7550 7551 return deferred.promise(); 7552 }; 7553 7554 MultiFactorAuthentication.checkVerificationCodeForPhone = function (mobileCountryId, mobileNumber, verificationCode) { 7555 var deferred = new $.Deferred(); 7556 7557 if (typeof mobileCountryId !== 'string' || 7558 typeof mobileNumber !== 'string' || 7559 typeof verificationCode !== 'string' 7560 ) { 7561 return deferred.reject(); 7562 } 7563 7564 $.ajax({
7565 url: win.suz_getCurrentDomain() + urls.checkVerificationCode, 7566 data: { 7567 mobileCountryId: mobileCountryId, 7568 mobileNumber: mobileNumber, 7569 verificationCode: verificationCode 7570 }, 7571 dataType: 'jsonp', 7572 jsonp: 'callback', 7573 scriptCharset: 'UTF-8' 7574 }).done(function (data) { 7575 deferred.resolve(data); 7576 }).fail(function (jqXHR, textStatus, errorThrown) { 7577 deferred.reject(jqXHR, textStatus, errorThrown); 7578 }); 7579 7580 return deferred.promise(); 7581 }; 7582 7583 MultiFactorAuthentication.checkVerificationCodeForEmail = function (emailAddress, verificationCode) { 7584 var deferred = new $.Deferred(); 7585 7586 if (typeof emailAddress !== 'string' || 7587 typeof verificationCode !== 'string' 7588 ) { 7589 return deferred.reject(); 7590 } 7591 7592 $.ajax({
7593 url: win.suz_getCurrentDomain() + urls.checkVerificationCodeForEmail, 7594 data: { 7595 emailAddress: emailAddress, 7596 verificationCode: verificationCode 7597 }, 7598 dataType: 'jsonp', 7599 jsonp: 'callback', 7600 scriptCharset: 'UTF-8' 7601 }).done(function (data) { 7602 deferred.resolve(data); 7603 }).fail(function (jqXHR, textStatus, errorThrown) { 7604 deferred.reject(jqXHR, textStatus, errorThrown); 7605 }); 7606 7607 return deferred.promise(); 7608 }; 7609 7610 MultiFactorAuthentication.onClickSendCodeTrigger = function (event, root, scope) { 7611 var SMSCodeButton = win.KeyenceForm.SMSCodeButton; 7612 var MultiStepForm = win.MultiStepForm; 7613 var button = event.currentTarget; 7614 var self = this; 7615 7616 // Defer SMSCodeButton UI updates until after the async response so that GTM event tracking runs first 7617 var activateSMSCodeButton = function () { 7618 // Clear any existing timer first to prevent a stale timer from mistakenly clearing the new timer 7619 if (SMSCodeButton.timeIds[button.id] && typeof SMSCodeButton.timeIds[button.id].timeId === 'number') { 7620 win.clearInterval(SMSCodeButton.timeIds[button.id].timeId); 7621 delete SMSCodeButton.timeIds[button.id]; 7622 } 7623 SMSCodeButton.disableButton(button); 7624 SMSCodeButton.replaceButtonText(button, button.getAttribute('data-resend-text'));
7625 SMSCodeButton.toggleResendCount(button, 'show'); 7626 SMSCodeButton.countResendTime(button); 7627 }; 7628 7629 if (scope.emailInput) { 7630 var emailAddress = scope.emailInput.value; 7631 7632 win.suz_callRegValidator($(scope.emailInput)).done(function (result) { 7633 if (!result['message']) { 7634 self.createVerificationCodeForEmail(emailAddress).done(function (status) { 7635 if (status.message && MultiStepForm?.insertErrorText) { 7636 MultiStepForm.insertErrorText(scope.emailInput.name, status.message); 7637 } else { 7638 if (MultiStepForm?.clearInputError) { 7639 MultiStepForm.clearInputError(scope.emailInput.name, true); 7640 } 7641 if (scope.verificationCodeDiv) { 7642 scope.verificationCodeDiv.classList.remove(classNames.isHide); 7643 } 7644 if (scope.checkSMSCodeValidTarget) { 7645 scope.checkSMSCodeValidTarget.focus(); 7646 } 7647 activateSMSCodeButton(); 7648 } 7649 }).fail(function (jqXHR, textStatus, errorThrown) { 7650 if (jqXHR && jqXHR.status !== 200) { 7651 if (MultiStepForm?.insertErrorText) { 7652 MultiStepForm.insertErrorText(scope.emailInput.name, kpi_translation.ServerConnectErrorMessage); 7653 } 7654 return; 7655 } 7656 if (MultiStepForm?.asyncErrorHundler) { 7657 MultiStepForm.asyncErrorHundler(jqXHR?.status ?? 0, textStatus); 7658 } 7659 }); 7660 } 7661 }).fail(function () { 7662 console.error('Reg validator error'); 7663 }); 7664 } else if (scope.mobileNumberInput && scope.countryId) { 7665 var mobileNumber = scope.mobileNumberInput.value; 7666 var mobileCountryId = scope.countryId.value; 7667 7668 win.suz_callRegValidator($('scope.mobileNumberInput')).done(function (result) { 7669 if (!result['message']) { 7670 self.createVerificationCodeForPhone(mobileCountryId, mobileNumber).done(function (status) { 7671 if (status.message && MultiStepForm?.insertErrorText) { 7672 MultiStepForm.insertErrorText(scope.mobileNumberInput.name, status.message); 7673 } else { 7674 if (MultiStepForm?.clearInputError) { 7675 MultiStepForm.clearInputError(scope.mobileNumberInput.name, true); 7676 } 7677 if (scope.verificationCodeDiv) { 7678 scope.verificationCodeDiv.classList.remove(classNames.isHide); 7679 } 7680 if (scope.checkSMSCodeValidTarget) { 7681 scope.checkSMSCodeValidTarget.focus(); 7682 } 7683 activateSMSCodeButton(); 7684 } 7685 }).fail(function (jqXHR, textStatus, errorThrown) { 7686 if (jqXHR && jqXHR.status !== 200) { 7687 if (MultiStepForm?.insertErrorText) { 7688 MultiStepForm.insertErrorText(scope.mobileNumberInput.name, kpi_translation.ServerConnectErrorMessage); 7689 } 7690 return; 7691 } 7692 if (MultiStepForm?.asyncErrorHundler) { 7693 MultiStepForm.asyncErrorHundler(jqXHR?.status ?? 0, textStatus); 7694 } 7695 }); 7696 } 7697 }).fail(function () { 7698 console.error('Reg validator error'); 7699 }); 7700 } 7701 }; 7702 7703 MultiFactorAuthentication.onClickEditTrigger = function (event, root, scope) { 7704 var trigger = event.currentTarget; 7705 var autoClickTriggerIndex = 0; 7706 var targetField = scope.emailInput ? scope.emailInput : scope.mobileNumberInput; 7707 var errorFieldWrapper = null; 7708 7709 event.preventDefault(); 7710 this.saveCurrentValues(root, scope); 7711 7712 // Persistently store the confirmed values at the time editing starts with a string key (to restore after DOM replacement) 7713 var rootKey = getRootKey(root); 7714 var state = this.getRootState(root); 7715 editingRootKeys.add(rootKey);
7716 cancelledRootKeys.delete(rootKey); // Clear the cancel-pending state when re-editing begins 7717 savedValuesByKey.set(rootKey, { 7718 email: state.savedValues.email, 7719 mobileNumber: state.savedValues.mobileNumber, 7720 countryId: state.savedValues.countryId 7721 }); 7722 7723 this.enableInputs(scope); 7724 7725 if (scope.deleteDialog) { 7726 scope.deleteDialog.classList.add(classNames.isHide); 7727 } 7728 if (scope.editEnded) { 7729 scope.editEnded.classList.remove(classNames.isHide); 7730 } 7731 if (scope.edit) { 7732 scope.edit.classList.add(classNames.isHide); 7733 } 7734 if (scope.sendCode) { 7735 scope.sendCode.classList.remove(classNames.isHide); 7736 if (scope.sendCodeTrigger) { 7737 var SMSCodeButton = win.KeyenceForm.SMSCodeButton; 7738 var isCountingDown = SMSCodeButton?.timeIds?.[scope.sendCodeTrigger.id]; 7739 if (!isCountingDown) { 7740 scope.sendCodeTrigger.removeAttribute('disabled'); 7741 scope.sendCodeTrigger.setAttribute('aria-disabled', 'false'); 7742 } 7743 } 7744 } 7745 7746 if (MultiStepForm.isEditProfileForm()) { 7747 this.addSubmitTriggerDisabled(); 7748 } 7749 7750 if (this.initialClickedEditButtonArray.length) { 7751 autoClickTriggerIndex = this.initialClickedEditButtonArray.indexOf(trigger); 7752 7753 if (autoClickTriggerIndex !== -1) { 7754 this.initialClickedEditButtonArray.splice(autoClickTriggerIndex, 1); 7755 7756 return; 7757 } 7758 } 7759 7760 if (this.initialErrorItemRootArray.length) { 7761 errorFieldWrapper = targetField.closest(`.${classNames.root}`); 7762 7763 if (this.isMatchedInitialErrorField(errorFieldWrapper)) { 7764 this.removeInitialErrorArray(errorFieldWrapper); 7765 } 7766 } 7767 7768 if (scope.emailInput) { 7769 scope.emailInput.focus(); 7770 } else if (scope.mobileNumberInput) { 7771 scope.mobileNumberInput.focus(); 7772 } 7773 }; 7774 7775 MultiFactorAuthentication.restoreValues = function (root, scope) { 7776 var state = this.getRootState(root); 7777 7778 if (scope.emailInput) { 7779 scope.emailInput.value = state.savedValues.email; 7780 } 7781 if (scope.mobileNumberInput) { 7782 scope.mobileNumberInput.value = state.savedValues.mobileNumber; 7783 } 7784 if (scope.countryId) { 7785 scope.countryId.value = state.savedValues.countryId; 7786 } 7787 }; 7788 7789 MultiFactorAuthentication.clearValues = function (scope) { 7790 if (scope.emailInput) { 7791 scope.emailInput.value = ''; 7792 } 7793 if (scope.mobileNumberInput) { 7794 scope.mobileNumberInput.value = ''; 7795 } 7796 }; 7797 7798 MultiFactorAuthentication.setDefaultDisplay = function (scope) { 7799 if (scope.edit) { 7800 scope.edit.classList.remove(classNames.isHide); 7801 } 7802 if (scope.deleteDialog) { 7803 scope.deleteDialog.classList.remove(classNames.isHide); 7804 } 7805 if (scope.editEnded) { 7806 scope.editEnded.classList.add(classNames.isHide); 7807 } 7808 if (scope.sendCode) { 7809 scope.sendCode.classList.add(classNames.isHide); 7810 } 7811 if (scope.verificationCodeDiv) { 7812 scope.verificationCodeDiv.classList.add(classNames.isHide); 7813 } 7814 }; 7815 7816 MultiFactorAuthentication.closeDialog = function (scope, event) { 7817 if (scope.dialogCloseButton) { 7818 scope.dialogCloseButton.click(); 7819 7820 return; 7821 } 7822 7823 if (scope.dialog && typeof scope.dialog.close === 'function') { 7824 scope.dialog.close(); 7825 7826 return; 7827 } 7828 7829 // prd-modalDialog pattern: traverse up from the clicked element to .prd-modalDialog-container and click .prd-modalDialog-closeButton 7830 var clickedElement = event?.currentTarget ?? null; 7831 var modalContainer = clickedElement ? clickedElement.closest('.prd-modalDialog-container') : null; 7832 var prdCloseButton = modalContainer ? modalContainer.querySelector('.prd-modalDialog-closeButton') : null; 7833 7834 if (prdCloseButton) { 7835 prdCloseButton.click(); 7836 } 7837 }; 7838 7839 MultiFactorAuthentication.onClickEditEndedTrigger = function (event, root, scope) { 7840 var self = this; 7841 var state = this.getRootState(root); 7842 var rootKey = getRootKey(root); 7843 var targetField = scope.emailInput ? scope.emailInput : scope.mobileNumberInput; 7844 event.preventDefault(); 7845 editingRootKeys.delete(rootKey);
7846 // Do not delete savedValuesByKey here: 7847 // It is managed via cancelledRootKeys so that setupRoots() can write back 7848 // the confirmed values if the framework re-renders the DOM and restores unverified values 7849 cancelledRootKeys.add(rootKey); 7850 7851 this.restoreValues(root, scope); 7852 7853 win.suz_callRegValidator($(targetField)).done(function (result) { 7854 MultiStepForm?.clearInputError(targetField?.name, true); 7855 self.disableInputs(scope); 7856 self.setDefaultDisplay(scope); 7857 if (state.isVerified) { 7858 root.querySelectorAll('.' + classNames.formSuccessTextOuter).forEach(function (el) { 7859 el.classList.remove(classNames.isHide); 7860 }); 7861 } 7862 self.updateDeleteDialogTriggerState(); 7863 if (MultiStepForm?.isEditProfileForm()) { 7864 self.removeSubmitTriggerDisabled(); 7865 } 7866 self.deleteVerificationErrorCode(scope); 7867 }).fail(function () { 7868 console.error('Reg validator error'); 7869 }); 7870 }; 7871 7872 MultiFactorAuthentication.onClickDeleteDialogTrigger = function (event, root, scope) { 7873 // Do not call event.preventDefault() because the Stimulus modal-dialog-opener controller 7874 // also opens the dialog on the same click event. 7875 // Only prevent Stimulus from processing when aria-disabled is set. 7876 if (scope.deleteDialogTrigger?.getAttribute('aria-disabled') === 'true') { 7877 event.preventDefault(); 7878 return; 7879 } 7880 7881 this.saveCurrentValues(root, scope); 7882 7883 if (scope.verificationCodeDiv) { 7884 scope.verificationCodeDiv.classList.add(classNames.isHide); 7885 } 7886 7887 // Keep DialogOpenEvent as it is required on other pages (no-op on this page) 7888 const open = new CustomEvent('DialogOpenEvent', { 7889 detail: { 7890 href: '#js-verificationTargetValue-dialogEmailValueDelete', 7891 }, 7892 }); 7893 window.dispatchEvent(open); 7894 7895 // On this page, the Stimulus modal-dialog-opener controller responds to the same click event 7896 // and generates the dialog DOM from a template. 7897 // Since the Stimulus handler runs after this handler, 7898 // defer event registration on the dialog buttons to the next task. 7899 // The global MutationObserver inside observe() also serves as an additional fallback. 7900 var self = this; 7901 setTimeout(function () { 7902 self.attachDialogButtonEvents(root, scope); 7903 7904 // Remove dialogs that remain with aria-hidden="true" after being closed via the Esc key. 7905 // Target cancel buttons for both email and mobileNumber 7906 // so that whichever dialog is opened, the one left from the previous Esc close can be removed. 7907 // Only do this when there are two or more buttons with the same ID (if only one exists, it is the first open, so leave it alone) 7908 var allCancelBtns = doc.querySelectorAll( 7909 '#js-controlVerificationTargetValue-emailCancel, ' + 7910 '#js-controlVerificationTargetValue-mobileNumberCancel' 7911 ); 7912 if (allCancelBtns.length >= 2) { 7913 for (var i = 0; i < allCancelBtns.length; i++) { 7914 var dialog = allCancelBtns[i].closest('.prd-modalDialog'); 7915 if (dialog && dialog.getAttribute('aria-hidden') === 'true') { 7916 dialog.remove(); 7917 break; 7918 } 7919 } 7920 } 7921 }, 0); 7922 }; 7923 7924 MultiFactorAuthentication.attachDialogButtonEvents = function (root, scope) { 7925 var self = this; 7926 7927 // If root is not specified, execute for all roots (used when called from init()) 7928 if (!root) {
7929 elements.roots.forEach(function (r) { 7930 var s = self.getRootScope(r); 7931 self.attachDialogButtonEvents(r, s); 7932 }); 7933 return; 7934 } 7935 7936 // Determine the unique button ID based on the root type (email / mobileNumber) 7937 // and retrieve only the correct button directly via doc.getElementById. 7938 var isEmailRoot = !!root.querySelector('.' + classNames.email); 7939 var cancelButtonId = isEmailRoot 7940 ? 'js-controlVerificationTargetValue-emailCancel' 7941 : 'js-controlVerificationTargetValue-mobileNumberCancel'; 7942 var deleteButtonId = isEmailRoot 7943 ? 'js-controlVerificationTargetValue-emailDelete' 7944 : 'js-controlVerificationTargetValue-mobileNumberDelete'; 7945 7946 // When the dialog is closed with the Esc key, DOM elements with aria-hidden="true" may remain, 7947 // resulting in multiple buttons with the same ID when the dialog is opened again. 7948 // Since getElementById returns the first (old) element, use querySelectorAll 7949 // to get the last (newest = visible) element. 7950 var cancelButtons = doc.querySelectorAll('#' + cancelButtonId); 7951 var dialogCancelButton = cancelButtons.length ? cancelButtons[cancelButtons.length - 1] : null; 7952 var deleteButtons = doc.querySelectorAll('#' + deleteButtonId); 7953 var dialogDeleteButton = deleteButtons.length ? deleteButtons[deleteButtons.length - 1] : null; 7954 7955 // Re-attach events every time using remove â add. 7956 // If the node has been replaced due to DOM reconstruction, the old handler no longer exists, 7957 // so addEventListener runs directly. For the same node, remove first before re-registering. 7958 if (dialogCancelButton) { 7959 if (dialogCancelButton._mfaCancelHandler) { 7960 dialogCancelButton.removeEventListener('click', dialogCancelButton._mfaCancelHandler); 7961 } 7962 dialogCancelButton._mfaCancelHandler = function (event) { 7963 self.onClickDialogCancel(event, root, scope); 7964 }; 7965 dialogCancelButton.addEventListener('click', dialogCancelButton._mfaCancelHandler); 7966 } 7967 7968 if (dialogDeleteButton) { 7969 if (dialogDeleteButton._mfaDeleteHandler) { 7970 dialogDeleteButton.removeEventListener('click', dialogDeleteButton._mfaDeleteHandler); 7971 } 7972 dialogDeleteButton._mfaDeleteHandler = function (event) { 7973 self.onClickDialogDelete(event, root, scope); 7974 }; 7975 dialogDeleteButton.addEventListener('click', dialogDeleteButton._mfaDeleteHandler); 7976 } 7977 }; 7978 7979 MultiFactorAuthentication.onClickDialogCancel = function (event, root, scope) { 7980 event.preventDefault(); 7981 this.restoreValues(root, scope); 7982 this.disableInputs(scope); 7983 this.setDefaultDisplay(scope); 7984 this.closeDialog(scope, event); 7985 this.updateDeleteDialogTriggerState(scope); 7986 }; 7987 7988 MultiFactorAuthentication.onClickDialogDelete = function (event, root, scope) { 7989 var state = this.getRootState(root); 7990 event.preventDefault(); 7991 this.disableInputs(scope); 7992 this.setDefaultDisplay(scope); 7993 this.closeDialog(scope, event); 7994 this.updateDeleteDialogTriggerState(scope); 7995 this.clearValues(scope); 7996 this.saveCurrentValues(root, scope); 7997 this.saveConfirmedValues(root, scope); 7998 state.isVerified = false; 7999 state.isDeleted = true; 8000 deletedRootKeys.add(getRootKey(root)); 8001 root.querySelectorAll('.' + classNames.formSuccessTextOuter).forEach(function (el) { 8002 el.classList.add(classNames.isHide); 8003 }); 8004 this.removeValidClass(scope); 8005 }; 8006 8007 /** 8008 * Monitors dynamic DOM changes using MutationObserver.
8009 * - When a new root element is added: re-run init() to set up the new root 8010 * - When a dialog button is newly added or replaced: re-run attachDialogButtonEvents() to 8011 * re-attach events to the new button element (duplicates are prevented by the dialogButtonsWithEvents WeakSet) 8012 * @returns {MutationObserver} 8013 */ 8014 MultiFactorAuthentication.observe = function () { 8015 var self = this; 8016 var observerTimer = null; 8017 8018 var observer = new MutationObserver(function (mutations) { 8019 var hasNewRoots = false; 8020 var hasNewDialogButtons = false; 8021 8022 mutations.forEach(function (mutation) { 8023 mutation.addedNodes.forEach(function (node) { 8024 if (node.nodeType !== 1) { 8025 return; 8026 } 8027 // Detect addition of new root elements 8028 if ( 8029 (node.classList && node.classList.contains(classNames.root)) || 8030 (node.querySelector && node.querySelector('.' + classNames.root)) 8031 ) { 8032 hasNewRoots = true; 8033 } 8034 // Detect addition or replacement of dialog buttons 8035 if ( 8036 (node.matches && ( 8037 node.matches(selectors.dialogCancelButton) || 8038 node.matches(selectors.dialogDeleteButton) 8039 )) || 8040 (node.querySelector && ( 8041 node.querySelector(selectors.dialogCancelButton) || 8042 node.querySelector(selectors.dialogDeleteButton) 8043 )) 8044 ) { 8045 hasNewDialogButtons = true; 8046 } 8047 }); 8048 }); 8049 8050 if (!hasNewRoots && !hasNewDialogButtons) { 8051 return; 8052 } 8053 8054 // Batch processing when fired consecutively within a short interval 8055 clearTimeout(observerTimer); 8056 observerTimer = setTimeout(function () { 8057 if (hasNewRoots) { 8058 // Re-initialize including the new root (duplicate registration to existing roots is prevented by the attachedRoots WeakSet) 8059 self.init(); 8060 } 8061 if (hasNewDialogButtons) { 8062 // When dialog buttons have been replaced, re-attach events for all scopes 8063 // (only new elements receive events due to the dialogButtonsWithEvents WeakSet) 8064 elements.roots.forEach(function (root) { 8065 var scope = self.getRootScope(root); 8066 self.attachDialogButtonEvents(root, scope); 8067 }); 8068 } 8069 }, 50); 8070 }); 8071 8072 observer.observe(doc.body, { 8073 childList: true, 8074 subtree: true 8075 }); 8076 8077 return observer; 8078 }; 8079 8080 MultiFactorAuthentication.getInitialInputValue = function (target) { 8081 var self = this; 8082 var inputValue = ''; 8083 8084 if (typeof target !== 'object' || !target) { 8085 return; 8086 } 8087 8088 elements.roots.forEach(function (root) { 8089 var scope = self.getRootScope(root); 8090 var state = self.getRootState(root); 8091 8092 if (scope.emailInput === target) { 8093 inputValue = state.savedValues.email; 8094 } else if (scope.mobileNumberInput === target) { 8095 inputValue = state.savedValues.mobileNumber; 8096 } 8097 }); 8098 8099 return inputValue; 8100 }; 8101 8102 MultiFactorAuthentication.isMatchedInitialErrorField = function (target) { 8103 var isInitialError = false; 8104 8105 if (typeof target !== 'object' || !target) { 8106 return false; 8107 } 8108 8109 if (this.initialErrorItemRootArray.length) { 8110 this.initialErrorItemRootArray.forEach(function (root) { 8111 if (target === root) { 8112 isInitialError = true; 8113 } 8114 }); 8115 } 8116 8117 return isInitialError; 8118 }; 8119 8120 MultiFactorAuthentication.removeInitialErrorArray = function (target) { 8121 var errorFieldWrapperIndex = 0; 8122 8123 if (typeof target !== 'object' || !target) { 8124 return; 8125 } 8126 8127 errorFieldWrapperIndex = this.initialErrorItemRootArray.indexOf(target); 8128 if (errorFieldWrapperIndex !== -1) { 8129 this.initialErrorItemRootArray.splice(errorFieldWrapperIndex, 1); 8130 } 8131 }; 8132 8133 MultiFactorAuthentication.isDisabledTarget = function (target) { 8134 var self = this; 8135 var isDisabled = false; 8136 8137 if (typeof target !== 'object' || !target) { 8138 return isDisabled; 8139 } 8140 8141 if (!elements.roots.length) { 8142 return isDisabled; 8143 } 8144
8145 elements.roots.forEach(function (root) { 8146 var scope = self.getRootScope(root); 8147 var state = self.getRootState(root); 8148 8149 if ((scope.root === target && 8150 scope.emailInput?.disabled) || 8151 (scope.root === target && 8152 scope.mobileNumberInput?.disabled) 8153 ) { 8154 isDisabled = true; 8155 } 8156 }); 8157 8158 return isDisabled; 8159 }; 8160 8161 MultiFactorAuthentication.addSubmitTriggerDisabled = function () { 8162 if (elements.editProfileSubmitButton) { 8163 elements.editProfileSubmitButton.disabled = true; 8164 } 8165 }; 8166 8167 MultiFactorAuthentication.removeSubmitTriggerDisabled = function () { 8168 var isEditing = false; 8169 8170 if (elements.editProfileSubmitButton) { 8171 elements.roots.forEach(function (root) { 8172 var rootKey = getRootKey(root); 8173 8174 if (editingRootKeys.has(rootKey)) { 8175 isEditing = true; 8176 } 8177 }); 8178 8179 if (!isEditing) { 8180 elements.editProfileSubmitButton.disabled = false; 8181 } 8182 } 8183 }; 8184 8185 MultiFactorAuthentication.removeValidClass = function (scope) { 8186 var FilledFieldValidator = win.KeyenceForm.filledFieldValidator; 8187 var wrapper = null; 8188 8189 if (!FilledFieldValidator) { 8190 return; 8191 } 8192 8193 if (scope.emailInput) { 8194 wrapper = scope.emailInput.closest(`.${FilledFieldValidator.classNames.isFieldValid}`); 8195 } 8196 8197 if (scope.mobileNumberInput) { 8198 wrapper = scope.mobileNumberInput.closest(`.${FilledFieldValidator.classNames.isFieldValid}`); 8199 } 8200 8201 wrapper?.classList.remove(FilledFieldValidator.classNames.isFieldValid); 8202 } 8203 8204 MultiFactorAuthentication.deleteVerificationErrorCode = function (scope) { 8205 if (scope.checkSMSCodeValidTarget && 8206 !/^[0-9]+$/.test(scope.checkSMSCodeValidTarget.value) 8207 ) { 8208 scope.checkSMSCodeValidTarget.value = ''; 8209 MultiStepForm.clearInputError(scope.checkSMSCodeValidTarget.name, true); 8210 } 8211 }; 8212 8213 return MultiFactorAuthentication; 8214 })(); 8215 8216 $(function () { 8217 KEYENCE.setMultiStepForm(); 8218 KEYENCE.Form.FormFilter.init(); 8219 KEYENCE.Form.InputInterlock.init(); 8220 KEYENCE.Form.SMSCodeButton.init(); 8221 KEYENCE.Form.MobileNumberEdit.init(); 8222 KEYENCE.Form.BlankFieldValidator.init(); 8223 KEYENCE.Form.PatternMatchValidator.init(); 8224 KEYENCE.Form.MobileNumberValidator.init(); 8225 KEYENCE.Form.CommonSubmitValidator.init(); 8226 KEYENCE.Form.AvailableValidator.init(); 8227 KEYENCE.Form.ControlErrorDisplay.init(); 8228 KEYENCE.Form.filledFieldValidator.init(); 8229 KEYENCE.Form.OTPControl.init(); 8230 KEYENCE.Form.ToggleDisabled.init(); 8231 KEYENCE.Form.MultiFactorAuthentication.init(); 8232 }); 8233}(window, window.document, window.jQuery)); 8234 8235(function (win, doc, $) { 8236 'use strict'; 8237 8238 var ENQUETE = {}; 8239 8240 var idNames = { 8241 form: 'suz_registrationForm', 8242 enqueteId: 'enqueteId', 8243 extendSurvey: 'js-setEnqueteWithForm', 8244 }; 8245 8246 var validateBtnIdNames = { 8247 btnSendEmail: 'js-form-btnCheckSendMail', 8248 btnSendAutoSignupMail: 'js-form-btnCheckSendAutoSignupMail' 8249 } 8250 8251 var classNames = { 8252 isRequired: 'IsRequired', 8253 isHide: 'IsHide', 8254 errorMessage: 'ErrorMessage', 8255 isError: 'is-error', 8256 inputGroup: 'js-setEnqueteWithForm-question', 8257 target: 'js-setEnqueteWithForm-question', 8258 trimTarget: 'js-setEnqueteWithForm-trimTarget', 8259 errorWrapper: 'js-setEnqueteWithForm-errorWrapper', 8260 switchContentByChangingCategoriesTrigger: 'js-switchContentByChangingCategories-trigger', 8261 switchPhoneNumberTargetArea: 'js-switchPhoneNumber-targetArea', 8262 switchPhoneNumberTargetHref: 'js-switchPhoneNumber-targetHref', 8263 switchPhoneNumberTargetText: 'js-switchPhoneNumber-targetText',
8264 askKeyence: 'askKeyence', 8265 priceInquiry: 'priceInquiry', 8266 requestFreeTrial: 'requestFreeTrial', 8267 alternativeMachineService: 'alternativeMachineService', 8268 changeActiveStatusQuestion: 'js-changeActiveStatus-question', 8269 changeActiveStatusHook: 'js-changeActiveStatus-hook', 8270 changeActiveStatusTarget: 'js-changeActiveStatus-target', 8271 controlListItemVisibility: 'js-controlListItemVisibility', 8272 controlListItemVisibilityTarget: 'js-controlListItemVisibility-target', 8273 controlListItemVisibilityRemoveButton: 'js-controlListItemVisibility-removeButton', 8274 controlListItemVisibilityAddButton: 'js-controlListItemVisibility-addButton', 8275 noDecidedCheckbox: 'js-noDecidedCheckbox', 8276 errorMessagePrimary: 'js-setErrorMessage-primary', 8277 errorMessageSecondary: 'js-setErrorMessage-secondary', 8278 toggleDisplayOptionsTrigger: 'js-toggleDisplayOptions-trigger', 8279 toggleDisplayOptionsTargetRoot: 'js-toggleDisplayOptions-targetRoot', 8280 toggleDisplayOptionsTargetGroup: 'js-toggleDisplayOptions-targetGroup', 8281 toggleDisplayOptionsTarget: 'js-toggleDisplayOptions-target' 8282 }; 8283 8284 var options = { 8285 errorText: '<strong class="m-form-errorText ErrorMessage">{0}</strong>' 8286 }; 8287 8288 var visibilityListItemArray = []; 8289 8290 if ($ === undefined) { 8291 return; 8292 } 8293 8294 ENQUETE = (function (enquate) { 8295 enquate.VERSION = { 8296 NONE: -1, 8297 SURVEY_2014: 0, 8298 }; 8299 8300 enquate.init = function () { 8301 if (win.enqueteMessage) { 8302 options.errorText = options.errorText.replace(/\{0\}/g, win.enqueteMessage.required); 8303 } 8304 8305 enquate.extendIdNames(win.enqueteIdNames); 8306 enquate.extendClassNames(win.enqueteClassNames); 8307 enquate.extendOptions(win.enqueteOptions); 8308 8309 if (this.hasError()) { 8310 this.scrollToEnquateTop(); 8311 } 8312 }; 8313 8314 enquate.extendIdNames = function (obj) { 8315 if (obj) { 8316 $.extend(idNames, obj); 8317 } 8318 }; 8319 8320 enquate.extendClassNames = function (obj) { 8321 if (obj) { 8322 $.extend(classNames, obj); 8323 } 8324 }; 8325 8326 enquate.extendOptions = function (obj) { 8327 if (obj) { 8328 $.extend(options, obj); 8329 } 8330 }; 8331 8332 enquate.checkbox = { 8333 disable: function ($checkbox) { 8334 $checkbox.prop('disabled', true); 8335 }, 8336 enable: function ($checkbox) { 8337 $checkbox.prop('disabled', false); 8338 } 8339 }; 8340 8341 enquate.textbox = { 8342 disable: function ($textbox) { 8343 $textbox.prop('disabled', true); 8344 }, 8345 enable: function ($textbox) { 8346 $textbox.prop('disabled', false); 8347 } 8348 }; 8349 8350 enquate.textarea = { 8351 disable: function ($textarea) { 8352 $textarea.prop('disabled', true); 8353 }, 8354 enable: function ($textarea) { 8355 $textarea.prop('disabled', false); 8356 } 8357 }; 8358 8359 enquate.getVersion = function () { 8360 var version = this.VERSION.NONE; 8361 8362 if (doc.getElementById(idNames.enqueteId)) { 8363 if (doc.getElementById(idNames.extendSurvey)) { 8364 version = this.VERSION.SURVEY_2014; 8365 } 8366 } 8367 8368 return version; 8369 }; 8370 8371 enquate.hasError = function () { 8372 var version = this.getVersion(); 8373 var errorMessage; 8374 8375 if (version === this.VERSION.SURVEY_2014) { 8376 errorMessage = doc.querySelectorAll('#' + idNames.form + ' .' + classNames.errorMessage); 8377 8378 if (errorMessage.length) { 8379 return true; 8380 } 8381 } 8382 8383 return false; 8384 }; 8385 8386 enquate.scrollToEnquateTop = function () { 8387 var target = document.querySelector('a[name="enqueteTop"]'); 8388 var position = 0; 8389 8390 if (target) { 8391 position = (target.getBoundingClientRect().top + window.scrollY); 8392 8393 window.scrollTo(0, position); 8394 } 8395 }; 8396 8397 return enquate; 8398 }(ENQUETE)); 8399 8400 ENQUETE.toggleDisplay = (function () { 8401 var _prevTarget = ''; 8402 var _prevName = ''; 8403 8404 var ToggleDisplay = function () { 8405 this.data = []; 8406 }; 8407 8408 ToggleDisplay.prototype.init = function (data) { 8409 this.data = data || []; 8410 this._rebuildConnectingData(); 8411 this._bindEvents(); 8412 }; 8413 8414 ToggleDisplay.prototype._rebuildConnectingData = function () { 8415 var self = this; 8416 var data = self.data; 8417 var i; 8418 var len = data.length; 8419 var lastIndex = len - 1; 8420 var prevName; 8421 var prevSource; 8422 var prevTarget; 8423 var list = []; 8424 8425 for (i = 0; i < len; i++) { 8426 $(data[i].source).attr('data-target', data[i].target); 8427 8428 if (i === 0) { 8429 prevName = data[i].name; 8430 prevSource = data[i].source; 8431 prevTarget = data[i].target; 8432 } else if (data[i].name === prevName && data[i].target === prevTarget) { 8433 prevSource += ', ' + data[i].source; 8434 8435 if (i === lastIndex) { 8436 list.push({ 8437 name: data[i].name, 8438 source: prevSource, 8439 target: data[i].target 8440 }); 8441 } 8442 } else { 8443 list.push({ 8444 name: prevName, 8445 source: prevSource, 8446 target: prevTarget 8447 }); 8448 8449 if (i === lastIndex) { 8450 list.push({ 8451 name: data[i].name, 8452 source: data[i].source, 8453 target: data[i].target 8454 }); 8455 } else { 8456 prevName = data[i].name; 8457 prevSource = data[i].source; 8458 prevTarget = data[i].target; 8459 } 8460 } 8461 } 8462 8463 this.data = list.reverse(); 8464 }; 8465 8466 ToggleDisplay.prototype._bindEvents = function () { 8467 this._onChange(); 8468 }; 8469 8470 ToggleDisplay.prototype._onChange = function () { 8471 var self = this; 8472 var data = self.data; 8473 var i; 8474 var j; 8475 var len = data.length; 8476 var $input; 8477 var $source; 8478 var $target; 8479 var list = []; 8480 8481 for (i = 0; i < len; i++) { 8482 $input = $(data[i].name); 8483 $source = $(data[i].source); 8484 $target = $('.' + data[i].target); 8485 8486 $input.on( 8487 'change', 8488 { 8489 $input: $input, 8490 $source: $source, 8491 $target: $target, 8492 $checked: $(this).filter(':checked'), 8493 selector: data[i].target 8494 }, 8495 self._toggle 8496 ); 8497 8498 $target.addClass(classNames.isHide); 8499 8500 if ($source.is(':checked')) { 8501 list.push({ 8502 name: data[i].name, 8503 source: data[i].source, 8504 target: data[i].target 8505 }); 8506 } 8507 } 8508 8509 for (j = 0; j < list.length; j++) { 8510 $('.' + list[j].target).removeClass(classNames.isHide); 8511 } 8512 }; 8513 8514 ToggleDisplay.prototype._toggle = function (e) { 8515 var self = this; 8516 var $source = e.data.$source; 8517 var $target = e.data.$target; 8518 var selector = e.data.selector; 8519 var promise = Promise.resolve(); 8520 8521 var setHidden = function () { 8522 if (!$source.is(':checked')) { 8523 if (self.name !== _prevName) { 8524 _prevTarget = ''; 8525 } 8526 _prevName = self.name; 8527 $target.addClass(classNames.isHide); 8528 8529 $target.find('textarea, :text, select, checkbox, radio'). 8530 val(''). 8531 end(). 8532 find(':checked'). 8533 prop('checked', false). 8534 filter(function () { 8535 return $(this).attr('data-target') !== _prevTarget; 8536 }). 8537 trigger('change'); 8538 } 8539 }; 8540 8541 var setVisible = function () { 8542 if ($source.is(':checked')) { 8543 _prevName = self.name; 8544 _prevTarget = selector; 8545 $target.removeClass(classNames.isHide); 8546 } 8547 }; 8548 8549 promise.then(function () { 8550 setHidden(); 8551 }).then(function () { 8552 setVisible(); 8553 }); 8554 }; 8555 8556 return new ToggleDisplay(); 8557 }()); 8558 8559 ENQUETE.ctrlTxtBox = (function (enquete) { 8560 var CtrlTxtBox = function () { 8561 this.data = []; 8562 }; 8563 8564 CtrlTxtBox.prototype.init = function (data) { 8565 this.data = data || []; 8566 this._bindEvents(); 8567 }; 8568 8569 CtrlTxtBox.prototype._bindEvents = function () { 8570 this._onChange(); 8571 }; 8572 8573 CtrlTxtBox.prototype._onChange = function () { 8574 var self = this; 8575 var data = self.data; 8576 var i; 8577 var len = data.length; 8578 var $input; 8579 var $source; 8580 var $target; 8581 8582 for (i = 0; i < len; i++) { 8583 $input = $(data[i].name); 8584 $source = $(data[i].source); 8585 $target = $(data[i].target); 8586 8587 $input.on( 8588 'change', 8589 { 8590 $input: $input, 8591 $source: $source, 8592 $target: $target 8593 }, 8594 self._toggle 8595 ); 8596 8597 $input.trigger('change'); 8598 } 8599 }; 8600 8601 CtrlTxtBox.prototype._toggle = function (e) { 8602 var $source = e.data.$source; 8603 var $target = e.data.$target; 8604 8605 if ($source.is(':checked')) { 8606 enquete.textbox.enable($target); 8607 } else { 8608 enquete.textbox.disable($target); 8609 } 8610 }; 8611 8612 return new CtrlTxtBox(); 8613 }(ENQUETE)); 8614 8615 ENQUETE.checkMaxLimit = (function (enquete) { 8616 var CheckMaxLimit = function () { 8617 this.data = []; 8618 }; 8619 8620 CheckMaxLimit.prototype.init = function (data) { 8621 this.data = data || []; 8622 this._bindEvents(); 8623 }; 8624 8625 CheckMaxLimit.prototype._bindEvents = function () { 8626 this._onChange(); 8627 }; 8628 8629 CheckMaxLimit.prototype._onChange = function () { 8630 var self = this; 8631 var data = self.data; 8632 var i; 8633 var len = data.length; 8634 var $checkbox; 8635 8636 for (i = 0; i < len; i++) { 8637 $checkbox = $(data[i].name); 8638 $checkbox.on( 8639 'change', 8640 { 8641 $checkbox: $checkbox, 8642 max: data[i].max 8643 }, 8644 self._toggle 8645 ); 8646 8647 $checkbox.trigger('change'); 8648 } 8649 }; 8650 8651 CheckMaxLimit.prototype._toggle = function (e) { 8652 var $checkbox = e.data.$checkbox; 8653 var $notChecked = $checkbox.not(':checked'); 8654 var max = e.data.max;
8655 var count = $checkbox.filter(':checked').length; 8656 8657 if (count === max) { 8658 enquete.checkbox.disable($notChecked); 8659 } else { 8660 enquete.checkbox.enable($checkbox); 8661 } 8662 }; 8663 8664 return new CheckMaxLimit(); 8665 }(ENQUETE)); 8666 8667 ENQUETE.required = (function () { 8668 var Required = function () { 8669 this.data = []; 8670 }; 8671 8672 Required.prototype.init = function (data) { 8673 this.data = data || []; 8674 this._rebuildRequiredData(this.data); 8675 }; 8676 8677 Required.prototype._rebuildRequiredData = function (data) { 8678 var i; 8679 var len = data.length; 8680 var list = []; 8681 8682 for (i = 0; i < len; i++) { 8683 list.push(data[i].name); 8684 } 8685 8686 this.data = list; 8687 }; 8688 8689 Required.prototype.getItemList = function () { 8690 var self = this; 8691 var data = self.data; 8692 var i; 8693 var len; 8694 var $input; 8695 var itemList = []; 8696 8697 len = data.length; 8698 8699 for (i = 0; i < len; i++) { 8700 $input = $(data[i]); 8701 8702 if ($input.length && $input.is(':visible')) { 8703 itemList.push($input); 8704 } 8705 } 8706 8707 itemList = self._supplementItemList(itemList); 8708 8709 return itemList; 8710 }; 8711 8712 Required.prototype._supplementItemList = function (itemList) { 8713 var self = this; 8714 var $extra = $('.' + classNames.isRequired); 8715 8716 if ($extra.length) { 8717 $extra.each(function () { 8718 var $this = $(this); 8719 var name = $this.prop('name'); 8720 var tagName = $this.prop('tagName').toLowerCase(); 8721 8722 if (name === '' || tagName !== 'input') { 8723 return; 8724 } 8725 8726 if ($this.is(':visible') && $this.prop('disabled') === false) { 8727 itemList = self.addToItemList($this, itemList); 8728 } 8729 }); 8730 } 8731 8732 return itemList; 8733 }; 8734 8735 8736 Required.prototype.addToItemList = function (value, itemList) { 8737 var i; 8738 var len; 8739 var arrAdd; 8740 8741 if (Array.isArray(value)) { 8742 arrAdd = value; 8743 } else { 8744 arrAdd = [value]; 8745 } 8746 8747 len = arrAdd.length; 8748 8749 for (i = 0; i < len; i++) { 8750 if (this._getIndexOfTargtItem(arrAdd[i], itemList) < 0) { 8751 itemList.push(arrAdd[i]); 8752 } 8753 } 8754 8755 return itemList; 8756 }; 8757 8758 Required.prototype._getIndexOfTargtItem = function ($input, itemList) { 8759 var i; 8760 var len = itemList.length; 8761 var index = -1; 8762 8763 for (i = 0; i < len; i++) { 8764 if (itemList[i].prop('name') === $input.prop('name')) { 8765 index = i; 8766 break; 8767 } 8768 } 8769 8770 return index; 8771 }; 8772 8773 return new Required(); 8774 }()); 8775 8776 ENQUETE.form = (function (enquete) { 8777 var Form = function () { 8778 this.data = []; 8779 }; 8780 8781 Form.prototype.init = function (data) { 8782 this.data = data || []; 8783 this._bindEvents(); 8784 }; 8785 8786 Form.prototype._bindEvents = function () { 8787 this._onBlurFromTextInput(); 8788 this._onSubmit(); 8789 this._onClickContinueButton(); 8790 this._onBlurFromTextboxAndTextarea(); 8791 this._onChangeInput(); 8792 this._onKeydowntextboxAndTextarea(); 8793 this._blurOtherPlusText(); 8794 this._validateChangeSelect(); 8795 this._onChangeSelect(); 8796 this._controlListItemVisibility(); 8797 this._changeFieldInactive(); 8798 this._initPhoneNumberArea(); 8799 this._checkRestoreObject(); 8800 }; 8801 8802 Form.prototype._onSubmit = function () { 8803 var self = this; 8804 8805 $('#' + idNames.form).on('submit', function () { 8806 var list = enquete.required.getItemList(); 8807 8808 if (win.MultiStepForm.Register.isActionPwdAssistance()) { 8809 return true; 8810 } 8811 8812 if (win.MultiStepForm.isShow(win.MultiStepForm.PreForm.$root)) { 8813 return false; 8814 } 8815 8816 $('.' + classNames.errorMessage).remove(); 8817 8818 if (self._validateForm(list)) { 8819 self._clearHideValues();
8820 8821 return true; 8822 } 8823 8824 return false; 8825 }); 8826 }; 8827 8828 Form.prototype._onClickContinueButton = function () { 8829 var self = this; 8830 var selectors = Object.values(validateBtnIdNames).map(id => '#' + id).join(', '); 8831 var $elements = $(selectors); 8832 8833 $elements.on('click', self._validateEnqueteWithProceedButton.bind(this)); 8834 }; 8835 8836 Form.prototype._validateEnqueteWithProceedButton = function () { 8837 var self = this; 8838 var list = enquete.required.getItemList(); 8839 8840 if (!list.length) { 8841 return true; 8842 } 8843 8844 $('.' + classNames.errorMessage).remove(); 8845 8846 if (self._validateForm(list)) { 8847 self._clearHideValues(); 8848 8849 return true; 8850 } 8851 return false; 8852 }; 8853 8854 Form.prototype._onBlurFromTextboxAndTextarea = function () { 8855 var errText = options.errorText; 8856 var requiredList = enquete.required.getItemList(); 8857 var $question = null; 8858 var $errorWrapper = null; 8859 var isEntered = false; 8860 8861 $.each(requiredList, function (idx, $el) { 8862 if ($el.filter(':checkbox, :radio, select').length > 0) { 8863 return; 8864 } 8865 8866 $el.on('blur', function (e) { 8867 var $currentTarget = $(e.currentTarget); 8868 8869 $el.each(function () { 8870 isEntered = $(this).val() !== ''; 8871 }); 8872 8873 // ãµã¼ãã¤ã®ã¨ã©ã¼ããã¹ãã䏿¸ãããæ©è½ 8874 if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessagePrimary)) { 8875 errText = win.enqueteMessage.requiredProductsName; 8876 } else if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessageSecondary)) { 8877 errText = win.enqueteMessage.requiredUnitNumber; 8878 } else { 8879 errText = options.errorText; 8880 } 8881 8882 $question = $currentTarget.closest('.' + classNames.target); 8883 8884 if (!$question.length) { 8885 return; 8886 } 8887 8888 $errorWrapper = $question.find('.' + classNames.errorWrapper); 8889 8890 if (!$errorWrapper.length) { 8891 return; 8892 } 8893 8894 if (!isEntered) { 8895 if ($question.hasClass(classNames.inputGroup)) { 8896 $errorWrapper.find('.' + classNames.errorMessage).remove(); 8897 $question.addClass(classNames.isError); 8898 $errorWrapper.append(errText); 8899 } 8900 } else { 8901 if ($question.hasClass(classNames.inputGroup)) { 8902 $question.removeClass(classNames.isError); 8903 $errorWrapper.find('.' + classNames.errorMessage).remove(); 8904 } 8905 } 8906 }); 8907 }); 8908 }; 8909 8910 Form.prototype._onChangeInput = function () { 8911 var self = this; 8912 var data = self.data; 8913 var errText = options.errorText; 8914 var requiredList = enquete.required.getItemList(); 8915 var $question = null; 8916 var $errorWrapper = null; 8917 var $otherPlusTextPairElm; 8918 var $otherPlusTextElm; 8919 var isEntered = true; 8920 8921 $.each(requiredList, function (idx, $el) { 8922 $el.on('change', function (e) { 8923 var $currentTarget = $(e.currentTarget); 8924 if ($el.filter(':checkbox, :radio').length > 0) { 8925 isEntered = $el.filter(':checked').length > 0; 8926 } else { 8927 return; 8928 } 8929 8930 // ãµã¼ãã¤ã®ã¨ã©ã¼ããã¹ãã䏿¸ãããæ©è½ 8931 if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessagePrimary)) { 8932 errText = win.enqueteMessage.requiredProductsName; 8933 } else if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessageSecondary)) { 8934 errText = win.enqueteMessage.requiredUnitNumber; 8935 } else { 8936 errText = options.errorText; 8937 } 8938 8939 $question = $(e.currentTarget).closest('.' + classNames.target); 8940 8941 if (!$question.length) { 8942 return; 8943 } 8944 8945 $errorWrapper = $question.find('.' + classNames.errorWrapper); 8946 8947 if (!$errorWrapper.length) { 8948 return; 8949 } 8950 8951 if (data.length) { 8952 $otherPlusTextElm = $question.find(data[0].target); 8953 $otherPlusTextPairElm = $question.find(data[0].source); 8954 } 8955 8956 if (!isEntered) { 8957 if ($question.hasClass(classNames.inputGroup)) { 8958 $errorWrapper.find('.' + classNames.errorMessage).remove(); 8959 $question.addClass(classNames.isError); 8960 $errorWrapper.append(errText); 8961 } 8962 } else { 8963 if ($question.hasClass(classNames.inputGroup)) { 8964 if (($otherPlusTextElm && $otherPlusTextElm.val() === '') && ($otherPlusTextPairElm && $otherPlusTextPairElm.is(':checked'))) { 8965 return; 8966 } 8967 8968 $question.removeClass(classNames.isError); 8969 $errorWrapper.find('.' + classNames.errorMessage).remove(); 8970 } 8971 } 8972 }); 8973 }); 8974 }; 8975 8976 Form.prototype._blurOtherPlusText = function () { 8977 var self = this; 8978 var data = self.data; 8979 var i; 8980 var len = data.length; 8981 var errText = options.errorText; 8982 var $target = null; 8983 var $question = null; 8984 var $errorWrapper = null; 8985 var isEntered = false; 8986 8987 for (i = 0; i < len; i++) { 8988 $(data[i].target).on('blur', function (e) { 8989 $target = $(e.currentTarget); 8990 $question = $target.closest('.' + classNames.target); 8991 8992 $target.each(function () { 8993 isEntered = $(this).val() !== ''; 8994 }); 8995 8996 $errorWrapper = $question.find('.' + classNames.errorWrapper); 8997 8998 if (!$errorWrapper.length) { 8999 return; 9000 } 9001 9002 if (!isEntered) { 9003 if ($question.hasClass(classNames.inputGroup)) { 9004 $errorWrapper.find('.' + classNames.errorMessage).remove(); 9005 $question.addClass(classNames.isError); 9006 $errorWrapper.append(errText); 9007 } 9008 } else { 9009 if ($question.hasClass(classNames.inputGroup)) { 9010 $question.removeClass(classNames.isError); 9011 $errorWrapper.find('.' + classNames.errorMessage).remove(); 9012 } 9013 } 9014 }); 9015 } 9016 }; 9017 9018 Form.prototype._onKeydowntextboxAndTextarea = function () { 9019 var $enquete = $('#' + idNames.extendSurvey); 9020 var $targetFields = null; 9021 var multiStepForm = win.MultiStepForm; 9022 var $preForm = null; 9023 var $registerForm = null; 9024 9025 if (!$enquete.length || !multiStepForm) { 9026 return; 9027 } 9028 9029 $targetFields = $enquete.find(':text'); 9030 9031 $targetFields.each(function () { 9032 $(this).on('keydown', function (e) { 9033 if (e.key !== 'Enter') { 9034 return; 9035 } 9036 9037 $preForm = $('#' + win.MultiStepForm.PreForm.idNames.root); 9038 $registerForm = $('#' + win.MultiStepForm.Register.idNames.regForm); 9039 9040 if (!$preForm.hasClass('is-hide')) { 9041 multiStepForm.PreForm.onKeydownEmailForm(e); 9042 } else if (!$registerForm.hasClass('is-hide')) { 9043 multiStepForm.Register.onKeydownFormInput(e, true); 9044 } 9045 }); 9046 }); 9047 }; 9048 9049 Form.prototype._onChangeSelect = function () { 9050 var self = this; 9051 var $trigger = $('.' + classNames.switchContentByChangingCategoriesTrigger); 9052 9053 if (!$trigger.length) { 9054 return; 9055 } 9056 9057 $trigger.on('change', function() { 9058 var $this = $(this); 9059 var $selectedElement = $this.find('option:selected'); 9060 var redirectUrl = ''; 9061 9062 if (!$selectedElement.length) { 9063 return; 9064 } 9065 9066 redirectUrl = $selectedElement.data('redirectUrl'); 9067 self._switchPhoneNumber(); 9068 9069 if ($('body').hasClass(classNames.requestFreeTrial)) { 9070 self._redirect(redirectUrl); 9071 } 9072 }); 9073 }; 9074 9075 Form.prototype._redirect = function (redirectUrl) { 9076 if (!redirectUrl) { 9077 return; 9078 } 9079 9080 location.href = redirectUrl; 9081 }; 9082 9083 Form.prototype._makeQueryIntoDict = function () { 9084 var self = this; 9085 var query = location.search.substring(1).split('&'); 9086 var removeEmptyQueryArray = self._removeEmptyQuery(query); 9087 var arr = []; 9088 var dict = []; 9089 9090 if (removeEmptyQueryArray.length) { 9091 for (let i = 0; i < removeEmptyQueryArray.length; i++) { 9092 arr = removeEmptyQueryArray[i].split('='); 9093 if (arr[1]) { 9094 dict[arr[0]] = arr[1]; 9095 } else { 9096 dict[arr[0]] = ''; 9097 } 9098 } 9099 } 9100 9101 return dict; 9102 }; 9103 9104 Form.prototype._removeEmptyQuery = function (array) { 9105 return array.filter(function (x) { 9106 return !(x === null || x === undefined || x === ''); 9107 }); 9108 }; 9109 9110 Form.prototype._initPhoneNumberArea = function () { 9111 var self = this; 9112 var $trigger = $('.' + classNames.switchContentByChangingCategoriesTrigger); 9113 var $questionRoot = null; 9114 9115 $questionRoot = $trigger.closest('.js-hideQuestionWithGroupId'); 9116 9117 if ($questionRoot.length) { 9118 $questionRoot.hide(); 9119 } 9120 9121 self._switchPhoneNumber(); 9122 }; 9123 9124 Form.prototype._switchPhoneNumber = function () { 9125 var self = this; 9126 var dataNumber = self.dataNumber; 9127 var $trigger = $('.' + classNames.switchContentByChangingCategoriesTrigger); 9128 var $targetArea = $('.' + classNames.switchPhoneNumberTargetArea); 9129 var $targetText = $('.' + classNames.switchPhoneNumberTargetText); 9130 var selectValue = ''; 9131 var phoneNumber = ''; 9132 var groupListData = {}; 9133 9134 if (typeof groupListDataForContactPages === 'undefined' || 9135 !groupListDataForContactPages || 9136 !$trigger.length || 9137 !$targetArea.length || 9138 !$targetText.length) { 9139 return; 9140 } 9141 9142 groupListData = groupListDataForContactPages; 9143 selectValue = $trigger.val(); 9144 9145 if (groupListData.hasOwnProperty(selectValue)) { 9146 phoneNumber = groupListData[selectValue]; 9147 } 9148 9149 $.each($targetText, function () { 9150 var $this = $(this); 9151 var $targetHrefElement = null; 9152 9153 if (phoneNumber === '') { 9154 return; 9155 } 9156 9157 dataNumber = self._numberFormat(phoneNumber); 9158 9159 $this.text(phoneNumber); 9160 $targetHrefElement = $this.closest('.' + classNames.switchPhoneNumberTargetHref); 9161 9162 if (!$targetHrefElement.length) { 9163 return; 9164 } 9165 9166 $targetHrefElement.attr('data-href', `tel:${dataNumber}`); 9167 9168 if ($targetHrefElement.attr('href')) { 9169 $targetHrefElement.attr('href', $targetHrefElement.data('href')); 9170 } 9171 }); 9172 }; 9173 9174 Form.prototype._numberFormat = function (number) { 9175 var regex = /[^0-9]/g; 9176 var result = number.replace(regex, ''); 9177 9178 return result; 9179 }; 9180 9181 Form.prototype._validateChangeSelect = function () { 9182 var errText = options.errorText; 9183 var requiredList = enquete.required.getItemList(); 9184 var $question = null; 9185 var $errorWrapper = null; 9186 var isEntered = true; 9187 9188 $.each(requiredList, function (idx, $el) { 9189 if (!$el.filter('select').length) { 9190 return; 9191 } 9192 9193 $el.on('change', function (e) { 9194 var $currentTarget = $(e.currentTarget); 9195 if ($el.filter('select').length > 0) { 9196 isEntered = $el[0].value !== ''; 9197 } 9198 9199 // ãµã¼ãã¤ã®ã¨ã©ã¼ããã¹ãã䏿¸ãããæ©è½ 9200 if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessagePrimary)) { 9201 errText = win.enqueteMessage.requiredProductsName; 9202 } else if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessageSecondary)) { 9203 errText = win.enqueteMessage.requiredUnitNumber; 9204 } else { 9205 errText = options.errorText; 9206 } 9207 9208 $question = $(e.currentTarget).closest('.' + classNames.target); 9209 9210 if (!$question.length) { 9211 return; 9212 } 9213 9214 $errorWrapper = $question.find('.' + classNames.errorWrapper); 9215 9216 if (!$errorWrapper.length) { 9217 return; 9218 } 9219 9220 if (!isEntered) { 9221 if ($question.hasClass(classNames.inputGroup)) { 9222 $errorWrapper.find('.' + classNames.errorMessage).remove(); 9223 $question.addClass(classNames.isError); 9224 $errorWrapper.append(errText); 9225 } 9226 } else { 9227 if ($question.hasClass(classNames.inputGroup)) { 9228 $question.removeClass(classNames.isError); 9229 $errorWrapper.find('.' + classNames.errorMessage).remove(); 9230 } 9231 } 9232 }); 9233 }); 9234 }; 9235 9236 Form.prototype._onBlurFromTextInput = function () { 9237 var selector = '.' + classNames.trimTarget; 9238 9239 $(selector).on('blur', function () { 9240 this.value = this.value.trim(); 9241 }); 9242 }; 9243
9244 Form.prototype._controlListItemVisibility = function() { 9245 var self = this; 9246 var $root = $('.' + classNames.controlListItemVisibility); 9247 var $listItems = {}; 9248 var $activeListItems = {}; 9249 var $removeButtons = {}; 9250 var $addButton = $('.' + classNames.controlListItemVisibilityAddButton); 9251 var $firstInputItem = null; 9252 var firstAttrName = ''; 9253 var firstAttrNumber = ''; 9254 var $firstRemoveButton = null; 9255 9256 if (!$root.length || !$addButton.length) { 9257 return; 9258 } 9259 9260 $listItems = $root.find('.' + classNames.controlListItemVisibilityTarget); 9261 $removeButtons = $root.find('.' + classNames.controlListItemVisibilityRemoveButton); 9262 9263 if (!$listItems.length || 9264 !$removeButtons.length) { 9265 return; 9266 } 9267 9268 $firstRemoveButton = $listItems.eq(0).find('.' + classNames.controlListItemVisibilityRemoveButton); 9269 $firstRemoveButton.css('visibility', 'hidden').attr("aria-hidden", "true").attr("tabindex", "-1"); 9270 9271 $firstInputItem = $root.find('input:first'); 9272 firstAttrName = $firstInputItem.attr('name'); 9273 firstAttrNumber = Number(firstAttrName.replace('enq', '')); 9274 9275 $listItems.each(function() { 9276 var $this = $(this); 9277 if ($this.hasClass('is-hide')) { 9278 $this.hide(); 9279 } 9280 }); 9281 9282 $addButton.on('click', function () { 9283 $activeListItems = $listItems.filter('.is-show'); 9284 9285 if ($activeListItems.length !== $listItems.length) { 9286 self._addListItem(visibilityListItemArray); 9287 } 9288 }); 9289 9290 $removeButtons.each(function () { 9291 var $this = $(this); 9292 9293 $this.on('click', function () { 9294 $activeListItems = $listItems.filter('.is-show'); 9295 9296 if ($activeListItems.length > 1) { 9297 self._removeListItem($this, visibilityListItemArray); 9298 setTimeout(() => { 9299 self._resetAttribute($root, firstAttrNumber); 9300 }); 9301 } 9302 }); 9303 }); 9304 }; 9305 9306 Form.prototype._addListItem = function (visibilityListItemArray) { 9307 var self = this; 9308 var appendItem = visibilityListItemArray.shift(); 9309 var $appendItem = $(appendItem); 9310 var $appendItemInput = $appendItem.find('input'); 9311 var $root = $('.' + classNames.controlListItemVisibility); 9312 var $listItems = $root.find('.' + classNames.controlListItemVisibilityTarget); 9313 var $activeListItems = []; 9314 var $removeButtonOfActiveListItem = {}; 9315 9316 $appendItem.show(); 9317 $appendItem.addClass('is-show'); 9318 $appendItem.removeClass('is-hide'); 9319 $activeListItems = $listItems.filter('.is-show') 9320 9321 if ($activeListItems.length > 1) { 9322 $removeButtonOfActiveListItem = $activeListItems.find('.' + classNames.controlListItemVisibilityRemoveButton); 9323 $removeButtonOfActiveListItem.removeAttr("style").removeAttr("aria-hidden").removeAttr("tabindex"); 9324 } 9325 9326 self._toggleAddListButtonState(); 9327 self._addBlurEvent($appendItemInput); 9328 }; 9329 9330 Form.prototype._addBlurEvent = function ($appendItemInput) { 9331 var errText = options.errorText; 9332 var $question = null; 9333 var $errorWrapper = null; 9334 var isEntered = false; 9335 var $this = $appendItemInput; 9336 var $currentTarget = null; 9337 9338 $this.on('blur', function (e) { 9339 $currentTarget = $(e.currentTarget); 9340 9341 if (!$currentTarget.length) { 9342 return; 9343 } 9344 9345 e.currentTarget.value = e.currentTarget.value.trim(); 9346 9347 isEntered = $currentTarget.val() !== ''; 9348 9349 if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessagePrimary)) { 9350 errText = win.enqueteMessage.requiredProductsName; 9351 } else if (win.enqueteMessage && $currentTarget.hasClass(classNames.errorMessageSecondary)) { 9352 errText = win.enqueteMessage.requiredUnitNumber; 9353 } else { 9354 errText = options.errorText; 9355 } 9356 9357 $question = $currentTarget.closest('.' + classNames.target); 9358 9359 if (!$question.length) { 9360 return; 9361 } 9362 9363 $errorWrapper = $question.find('.' + classNames.errorWrapper); 9364 9365 if (!$errorWrapper.length) { 9366 return; 9367 } 9368 9369 if (!isEntered) { 9370 if ($question.hasClass(classNames.inputGroup)) { 9371 $errorWrapper.find('.' + classNames.errorMessage).remove(); 9372 $question.addClass(classNames.isError); 9373 $errorWrapper.append(errText); 9374 } 9375 } else { 9376 if ($question.hasClass(classNames.inputGroup)) { 9377 $errorWrapper.find('.' + classNames.errorMessage).remove(); 9378 $question.removeClass(classNames.isError); 9379 } 9380 } 9381 }); 9382 }; 9383 9384 Form.prototype._removeListItem = function ($removeButton, visibilityListItemArray) { 9385 var self = this;
9386 var $root = $('.' + classNames.controlListItemVisibility); 9387 var $currentListItem = $removeButton.closest('.' + classNames.controlListItemVisibilityTarget); 9388 var $currentListItemInput = $currentListItem.find('input'); 9389 var $listItems = $root.find('.' + classNames.controlListItemVisibilityTarget); 9390 var $activeListItems = []; 9391 var $removeButtonOfActiveListItem = {}; 9392 var $inputItems = $listItems.find('input'); 9393 var $noDecidedCheckbox = $('.' + classNames.noDecidedCheckbox); 9394 var inputWithValue = false; 9395 9396 $currentListItem.hide(); 9397 $currentListItem.addClass('is-hide'); 9398 $currentListItem.removeClass('is-show'); 9399 $currentListItemInput.val(''); 9400 $currentListItemInput.off('blur'); 9401 if ($currentListItem.find('.is-error').length > 0) { 9402 $currentListItem.find('.is-error').removeClass('is-error'); 9403 $currentListItem.find('.ErrorMessage').remove(); 9404 } 9405 visibilityListItemArray.push($currentListItem); 9406 $root.append($currentListItem); 9407 9408 $activeListItems = $listItems.filter('.is-show'); 9409 if ($activeListItems.length === 1) { 9410 $removeButtonOfActiveListItem = $activeListItems.find('.' + classNames.controlListItemVisibilityRemoveButton); 9411 $removeButtonOfActiveListItem.css("visibility", "hidden").attr("aria-hidden", "true").attr("tabindex", "-1"); 9412 } 9413 9414 $inputItems.each(function() { 9415 var $this = $(this); 9416 9417 if ($this.val() !== '') { 9418 inputWithValue = true; 9419 return; 9420 } 9421 9422 if (inputWithValue) { 9423 $noDecidedCheckbox.attr('disabled', true); 9424 } else { 9425 $noDecidedCheckbox.attr('disabled', false); 9426 } 9427 }); 9428 9429 self._toggleAddListButtonState(); 9430 }; 9431 9432 Form.prototype._resetAttribute = function ($root, firstAttrNumber) { 9433 var $listItems = $root.find('.' + classNames.controlListItemVisibilityTarget); 9434 var $inputItems = {}; 9435 9436 if (!$listItems.length) { 9437 return; 9438 } 9439 9440 $inputItems = $listItems.find('input'); 9441 9442 if (!$inputItems.length) { 9443 return; 9444 } 9445 9446 $inputItems.each(function (index) { 9447 var $this = $(this); 9448 var attrValue = index + firstAttrNumber; 9449 9450 $this.attr('name', `enq${attrValue}`); 9451 $this.attr('id', `enq${attrValue}`); 9452 }); 9453 }; 9454 9455 Form.prototype._changeFieldInactive = function () { 9456 var self = this; 9457 var $root = $('.' + classNames.controlListItemVisibility); 9458 var $noDecidedCheckbox = $('.' + classNames.noDecidedCheckbox); 9459 var $addButton = $('.' + classNames.controlListItemVisibilityAddButton); 9460 var $listItems = {}; 9461 var $removeButtons = {}; 9462 var $inputItems = {}; 9463 var $activeListItems = {}; 9464 9465 if (!$root.length || !$noDecidedCheckbox.length || !$addButton.length) { 9466 return; 9467 } 9468 9469 $listItems = $root.find('.' + classNames.controlListItemVisibilityTarget); 9470 $removeButtons = $root.find('.' + classNames.controlListItemVisibilityRemoveButton); 9471 9472 if (!$listItems.length || 9473 !$removeButtons.length) { 9474 return; 9475 } 9476 $inputItems = $listItems.find('input'); 9477 9478 if (!$inputItems.length) { 9479 return; 9480 } 9481 9482 $inputItems.on('input blur', function () { 9483 self._toggleNoDecidedCheckboxState($inputItems, $noDecidedCheckbox); 9484 }); 9485 9486 $noDecidedCheckbox.on('change', function () { 9487 var $this = $(this); 9488 9489 $activeListItems = $listItems.filter('.is-show'); 9490 9491 if ($this.filter(':checked').length > 0) { 9492 $inputItems.attr('disabled', true); 9493 $removeButtons.attr('disabled', true); 9494 9495 if ($listItems.find('.is-error').length > 0) { 9496 $listItems.find('.is-error').removeClass('is-error'); 9497 $listItems.find('.ErrorMessage').remove(); 9498 } 9499 9500 $addButton.attr('disabled', true); 9501 } else { 9502 $inputItems.attr('disabled', false); 9503 $removeButtons.attr('disabled', false); 9504 $addButton.attr('disabled', false); 9505 } 9506 }); 9507 }; 9508 9509 Form.prototype._toggleNoDecidedCheckboxState = function ($inputItems, $noDecidedCheckbox) { 9510 var inputWithValue = false; 9511 9512 $inputItems.each(function() { 9513 var $this = $(this); 9514 9515 if ($this.val() !== '') { 9516 inputWithValue = true; 9517 } 9518 9519 if (inputWithValue) { 9520 $noDecidedCheckbox.attr('disabled', true); 9521 } else { 9522 $noDecidedCheckbox.attr('disabled', false); 9523 } 9524 }); 9525 }; 9526 9527 Form.prototype._toggleAddListButtonState = function () {
9528 var $root = $('.' + classNames.controlListItemVisibility); 9529 var $listItems = $root.find('.' + classNames.controlListItemVisibilityTarget); 9530 var $activeListItems = $listItems.filter('.is-show'); 9531 var $addButton = $('.' + classNames.controlListItemVisibilityAddButton); 9532 9533 if ($activeListItems.length === $listItems.length) { 9534 $addButton.hide(); 9535 } else { 9536 $addButton.show(); 9537 } 9538 }; 9539 9540 Form.prototype._changeVisibilityStateControlList = function () { 9541 var $targetInputItems = []; 9542 var listItemCounter = 0; 9543 var $root = $('.' + classNames.controlListItemVisibility); 9544 var $listItems = $root.find('.' + classNames.controlListItemVisibilityTarget); 9545 var $hideListItems = []; 9546 var $activeListItems = {}; 9547 var $activeInputItems = {}; 9548 var $noDecidedCheckbox = $('.' + classNames.noDecidedCheckbox); 9549 var $removeButtons = $root.find('.' + classNames.controlListItemVisibilityRemoveButton); 9550 var $addButton = $('.' + classNames.controlListItemVisibilityAddButton); 9551 9552 visibilityListItemArray = []; 9553 9554 if ($noDecidedCheckbox.is(':checked')) { 9555 $activeListItems = $listItems.filter('.is-show'); 9556 $activeInputItems = $activeListItems.find('input'); 9557 9558 $addButton.attr('disabled', true); 9559 $activeInputItems.each(function () { 9560 var $this = $(this); 9561 9562 $this.attr('disabled', true); 9563 setTimeout(function () { 9564 $this.val(''); 9565 }, "500"); 9566 }); 9567 9568 $hideListItems = $listItems.filter('.is-hide'); 9569 for (var i = 0; i < $hideListItems.length; i++) { 9570 visibilityListItemArray.push($hideListItems[i]); 9571 } 9572 9573 return; 9574 } 9575 9576 $listItems.each(function() { 9577 var $this = $(this); 9578 9579 $targetInputItems = $this.find('input'); 9580 9581 if ($targetInputItems.val() !== '') { 9582 $this.show(); 9583 $this.addClass('is-show'); 9584 $this.removeClass('is-hide'); 9585 $noDecidedCheckbox.attr('disabled', true); 9586 listItemCounter++; 9587 } 9588 }); 9589 9590 $hideListItems = $listItems.filter('.is-hide'); 9591 for (var i = 0; i < $hideListItems.length; i++) { 9592 visibilityListItemArray.push($hideListItems[i]); 9593 } 9594 9595 if (1 < listItemCounter) { 9596 $removeButtons.eq(0).removeAttr("style").removeAttr("aria-hidden").removeAttr("tabindex"); 9597 } 9598 9599 if (listItemCounter === $listItems.length) { 9600 $addButton.hide(); 9601 } 9602 }; 9603 9604 Form.prototype._checkRestoreObject = function () { 9605 var self = this; 9606 var restoreValueArray = win.suz_restoreJson; 9607 var $triggers = $('.' + classNames.toggleDisplayOptionsTrigger); 9608 var $targetRoot = $('.' + classNames.toggleDisplayOptionsTargetRoot); 9609 var $targetGroup = $('.' + classNames.toggleDisplayOptionsTargetGroup); 9610 var $targetInputs = null; 9611 var targetGroupName = ''; 9612 var $checkedTrigger = null; 9613 var matchArray = []; 9614 9615 if (!$targetRoot.length || 9616 !$triggers.length || 9617 !$targetGroup.length) { 9618 return; 9619 } 9620 9621 if (!restoreValueArray.length) { 9622 self._toggleDisplayOptions(); 9623 } else { 9624 matchArray = restoreValueArray.filter(function (restoreObj) { 9625 return $triggers.toArray().find(function (trigger) { 9626 if (trigger.value === restoreObj.value) { 9627 return trigger; 9628 } 9629 }); 9630 }); 9631 9632 $checkedTrigger = $triggers.filter(function () { 9633 return $(this).val() === matchArray[0].value; 9634 }); 9635 9636 $checkedTrigger.prop('checked', true); 9637 targetGroupName = self._getActiveGroupName($checkedTrigger); 9638 $targetInputs = $targetGroup.find('[data-display-trigger-group-name]'); 9639 self._changeDisplayTarget($targetInputs, targetGroupName); 9640 $triggers.on('change', function () { 9641 var $this = $(this); 9642 9643 targetGroupName = self._getActiveGroupName($this); 9644 self._changeDisplayTarget($targetInputs, targetGroupName); 9645 }); 9646 } 9647 }; 9648 9649 Form.prototype._toggleDisplayOptions = function () { 9650 var self = this; 9651 var $triggers = $('.' + classNames.toggleDisplayOptionsTrigger); 9652 var $targetRoot = $('.' + classNames.toggleDisplayOptionsTargetRoot); 9653 var $targetGroup = $('.' + classNames.toggleDisplayOptionsTargetGroup); 9654 var $targetInputs = null; 9655 var targetGroupName = ''; 9656 9657 $targetRoot.hide(); 9658 $targetInputs = $targetGroup.find('[data-display-trigger-group-name]'); 9659 9660 if (!$targetInputs.length) { 9661 return; 9662 } 9663 9664 $triggers.on('change', function () { 9665 var $this = $(this); 9666 9667 $targetRoot.show(); 9668 targetGroupName = self._getActiveGroupName($this); 9669 9670 self._changeDisplayTarget($targetInputs, targetGroupName); 9671 }); 9672 }; 9673 9674 Form.prototype._getActiveGroupName = function ($triggers) { 9675 var displayTriggerGroupName = ''; 9676 9677 $triggers.each(function (index, trigger) { 9678 if ($(trigger).is(':checked')) { 9679 displayTriggerGroupName = $(trigger).data('display-trigger-group'); 9680 } 9681 }); 9682
9683 return displayTriggerGroupName; 9684 }; 9685 9686 Form.prototype._changeDisplayTarget = function ($targetInputs, targetGroupName) { 9687 var $targetRoot = null; 9688 9689 $targetInputs.each(function () { 9690 var $this = $(this); 9691 9692 $targetRoot = $this.closest('.' + classNames.toggleDisplayOptionsTarget); 9693 9694 if (!$targetRoot.length) { 9695 return; 9696 } 9697 9698 if ($this.data('display-trigger-group-name') === targetGroupName) { 9699 $targetRoot.show(); 9700 $this.prop('disabled', false); 9701 } else { 9702 $targetRoot.hide(); 9703 $this.prop('checked', false); 9704 $this.prop('disabled', true); 9705 } 9706 }); 9707 }; 9708 9709 Form.prototype._clearHideValues = function () { 9710 var $area = $('.' + classNames.target); 9711 9712 if ($area.length) { 9713 $area.each(function () { 9714 var $this = $(this); 9715 9716 if ($this.is(':hidden')) { 9717 if ($this.hasClass('js-hideQuestionWithGroupId')) { 9718 return; 9719 } 9720 9721 $this.find('textarea, :text, select, checkbox, radio'). 9722 val(''). 9723 end(). 9724 find(':checked'). 9725 prop('checked', false); 9726 } 9727 }); 9728 } 9729 }; 9730 9731 Form.prototype._validateForm = function (requiredList) { 9732 var result = true; 9733 var scrollPos = null; 9734 9735 $.each(requiredList, function (idx, $el) { 9736 var errText = options.errorText; 9737 var $errMsg; 9738 var isEntered = false; 9739 var currentPos = null; 9740 var $question; 9741 var $errorWrapper; 9742 9743 // ãµã¼ãã¤ã®ã¨ã©ã¼ããã¹ãã䏿¸ãããæ©è½ 9744 if (win.enqueteMessage && $el.hasClass(classNames.errorMessagePrimary)) { 9745 errText = win.enqueteMessage.requiredProductsName; 9746 } else if (win.enqueteMessage && $el.hasClass(classNames.errorMessageSecondary)) { 9747 errText = win.enqueteMessage.requiredUnitNumber; 9748 } else { 9749 errText = options.errorText; 9750 } 9751 9752 if ($el.filter(':checkbox, :radio').length > 0) { 9753 isEntered = $el.filter(':checked').length > 0; 9754 } else { 9755 $el.each(function () { 9756 if ($el.is(':disabled')) { 9757 return isEntered = true; 9758 } 9759 9760 isEntered = isEntered || ($(this).val() !== null && $(this).val() !== ''); 9761 }); 9762 } 9763 9764 $question = $el.eq(0).closest('.' + classNames.target); 9765 9766 if (!$question.length) { 9767 return; 9768 } 9769 9770 if (!isEntered) { 9771 result = false; 9772 9773 $errorWrapper = $question.find('.' + classNames.errorWrapper); 9774 9775 if (!$errorWrapper.length) { 9776 return; 9777 } 9778 9779 if ($question.hasClass(classNames.inputGroup)) { 9780 $question.addClass(classNames.isError); 9781 $errMsg = $errorWrapper.append(errText); 9782 currentPos = $errMsg.closest('.' + classNames.target).offset().top; 9783 } 9784 9785 if (scrollPos === null || scrollPos > currentPos) { 9786 scrollPos = currentPos; 9787 } 9788 } 9789 }); 9790 9791 if (scrollPos !== null) { 9792 $('html, body').animate({scrollTop: scrollPos}, 'fast', function () { 9793 return result; 9794 }); 9795 } else { 9796 return result; 9797 } 9798 }; 9799 9800 Form.prototype._restoreChangedState = function () { 9801 if (ENQUETE.ctrlTxtBox.data) { 9802 var data = ENQUETE.ctrlTxtBox.data; 9803 var i; 9804 var len = data.length; 9805 var $input = null; 9806 9807 for (i = 0; i < len; i++) { 9808 $input = $(data[i].source); 9809 if ($input.is(':checked')) { 9810 $input.trigger('change'); 9811 } 9812 } 9813 } 9814 9815 if (ENQUETE.checkboxGroup.data) { 9816 var data = ENQUETE.checkboxGroup.data; 9817 var i; 9818 var len = data.length; 9819 var $checkbox; 9820 var isChecked = false; 9821 9822 for (i = 0; i < len; i++) { 9823 $checkbox = $(data[i].name); 9824 isChecked = false; 9825 9826 if ($checkbox.length <= 0 || $checkbox.get(0).type !== 'checkbox') { 9827 continue; 9828 } 9829 9830 $checkbox.each(function (index, item) { 9831 if ($(item).is(':checked')) { 9832 isChecked = true; 9833 9834 return false; 9835 } 9836 }); 9837 9838 if (isChecked) { 9839 $checkbox.trigger('change'); 9840 } 9841 } 9842 } 9843
9844 if ($('.' + classNames.controlListItemVisibility).length) { 9845 this._changeVisibilityStateControlList(); 9846 } 9847 }; 9848 9849 return new Form(); 9850 }(ENQUETE)); 9851 9852 ENQUETE.checkboxGroup = (function (enquete) { 9853 var CheckboxGroup = function () { 9854 this.data = []; 9855 }; 9856 9857 CheckboxGroup.prototype.init = function (data) { 9858 this.data = data || []; 9859 this._bindEvents(); 9860 }; 9861 9862 9863 CheckboxGroup.prototype._bindEvents = function () { 9864 this._onChange(); 9865 }; 9866 9867 CheckboxGroup.prototype._onChange = function () { 9868 var self = this; 9869 var data = self.data; 9870 var i; 9871 var len = data.length; 9872 var $checkbox; 9873 9874 for (i = 0; i < len; i++) { 9875 $checkbox = $(data[i].name); 9876 9877 if ($checkbox.length <= 0 || $checkbox.get(0).type !== 'checkbox') { 9878 continue; 9879 } 9880 9881 $checkbox.on( 9882 'change', { 9883 $checkbox: $checkbox, 9884 outsiders: data[i].outsider 9885 }, 9886 self._toggle 9887 ); 9888 9889 $checkbox.trigger('change'); 9890 } 9891 }; 9892 9893 CheckboxGroup.prototype._toggle = function (e) { 9894 var outsiders = e.data.outsiders; 9895 var $checkbox = e.data.$checkbox; 9896 var $outsiders = $checkbox.filter(outsiders); 9897 var $base = $checkbox.not(outsiders); 9898 9899 if ($base.filter(':checked').length) { 9900 enquete.checkbox.disable($outsiders); 9901 } else if ($outsiders.filter(':checked').length) { 9902 enquete.checkbox.disable($base); 9903 } else { 9904 enquete.checkbox.enable($checkbox); 9905 } 9906 }; 9907 9908 return new CheckboxGroup(); 9909 }(ENQUETE)); 9910 9911 $(function () { 9912 var enqueteData = win.enqueteData || {}; 9913 9914 if (document.getElementById(idNames.form) && document.getElementById(idNames.extendSurvey)) { 9915 ENQUETE.init(); 9916 ENQUETE.required.init(enqueteData.required); 9917 ENQUETE.toggleDisplay.init(enqueteData.displaySwitch); 9918 ENQUETE.ctrlTxtBox.init(enqueteData.otherPlusText); 9919 ENQUETE.checkMaxLimit.init(enqueteData.maxChecked); 9920 ENQUETE.checkboxGroup.init(enqueteData.outsider); 9921 ENQUETE.form.init(enqueteData.otherPlusText); 9922 } else { 9923 return; 9924 } 9925 }); 9926 9927 $(win).on('load', function () { 9928 if (document.getElementById(idNames.form) && document.getElementById(idNames.extendSurvey)) { 9929 ENQUETE.form._restoreChangedState(); 9930 } 9931 }); 9932 9933 win.KeyenceEnquete = ENQUETE; 9934}(window, window.document, window.jQuery));
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.