1jQuery(document).ready(function($){ 2 3 window.xooEl = window.xooEl || {}; 4 5 function objectifyForm($form) { 6 var form = $form instanceof jQuery ? $form[0] : $form; 7 8 // Use FormData to handle all form inputs 9 var formData = new FormData(form); 10 var result = {}; 11 12 formData.forEach(function(value, name) { 13 // Skip File objects (they go into FormData directly for AJAX) 14 if (value instanceof File) return; 15 16 // Handle repeated fields by converting to arrays 17 if (result.hasOwnProperty(name)) { 18 if (!Array.isArray(result[name])) { 19 result[name] = [result[name]]; 20 } 21 result[name].push(value); 22 } else { 23 result[name] = value; 24 } 25 }); 26 27 return result; 28} 29 30 31 32 33 function parse_notice( message, type ){ 34 type = (typeof type !== 'undefined') ? type : 'error'; 35 return xoo_el_localize.html.notice[ type ].replace( '%s', message ); 36 } 37 38 var classReferral = { 39 'xoo-el-login-tgr': 'login', 40 'xoo-el-reg-tgr': 'register', 41 } 42 43 function getReferral(className){ 44 return classReferral[className] ? classReferral[className] : ''; 45 } 46 47 function getFormsTrigger( $container ){ 48 49 $container = $container || ''; 50 51 var isSingle = false; 52 53 if( $container.length && $container.find('.xoo-el-section[data-section="single"]').length ){ 54 isSingle = true; 55 } 56 57 var formsTrigger = { 58 'xoo-el-sing-tgr': 'single', 59 'xoo-el-login-tgr': isSingle ? 'single' : 'login', 60 'xoo-el-reg-tgr': isSingle ? 'single' : 'register', 61 'xoo-el-lostpw-tgr': 'lostpw', 62 'xoo-el-resetpw-tgr': 'resetpw', 63 'xoo-el-forcereg-tgr': 'register', 64 'xoo-el-forcelogin-tgr': 'login', 65 } 66 67 return formsTrigger; 68 } 69 70 71 class Container{ 72 73 constructor( $container ){ 74 this.$container = $container; 75 this.$tabs = $container.find('ul.xoo-el-tabs').length ? $container.find( 'ul.xoo-el-tabs' ) : null; 76 this.display = $container.hasClass('xoo-el-form-inline') ? 'inline' : 'popup'; 77 this.formRetries = 0; 78 79 if( this.$container.attr('data-active') ){ 80 this.toggleForm( this.$container.attr('data-active') ); 81 } 82 83 this.createFormsTriggerHTML(); 84 85 this.eventHandlers(); 86 } 87 88 createFormsTriggerHTML(){ 89 var HTML = '<div style="display: none!important;">'; 90 $.each( getFormsTrigger(this.$container), function( triggerClass, type ){ 91 HTML += '<span class="'+triggerClass+'"></span>'; 92 } ) 93 HTML += '</div>'; 94 this.$container.append(HTML); 95 } 96 97 eventHandlers(){ 98 99 this.$container.on( 'submit', '.xoo-el-action-form', this.submitForm.bind(this) ) ; 100 this.$container.on( 'click', '.xoo-el-edit-em', this.emailFieldEditClick.bind(this) ); 101 $( document.body ).on( 'xoo_el_form_submitted', this.singleFormProcess.bind(this) ); 102 this.formTriggerEvent(); 103 } 104 105 106 emailFieldEditClick(e){ 107 this.toggleForm('single'); 108 this.$container.find('input[name="xoo-el-sing-user"]').val( $(e.currentTarget).siblings('input').val() ).focus().trigger('keyup'); 109 } 110 111 112 formTriggerEvent(){ 113 114 var container = this, 115 formsTrigger = getFormsTrigger(container.$container); 116 117 $.each( formsTrigger, function( triggerClass, formType ){ 118 $( container.$container ).on( 'click', '.' + triggerClass, function(e){ 119 e.preventDefault(); 120 e.stopImmediatePropagation(); 121 container.toggleForm(formType, getReferral(triggerClass) ); 122 } ) 123 } ); 124 125 } 126 127 128 toggleForm( formType, referral ){ 129 130 referral = referral || ''; 131 132 this.$container.attr( 'data-active', formType ); 133 134 var $section = this.$container.find('.xoo-el-section[data-section="'+formType+'"]'), 135 activeClass = 'xoo-el-active'; 136 137 //Setting section 138 if( $section.length ){ 139 140 var $sectionForm = $section.find('form'); 141 142 this.$container.find('.xoo-el-section').removeClass( activeClass ); 143 $section.addClass( activeClass ); 144 $section.find('.xoo-el-notice').html('').hide(); 145 $section.find('.xoo-el-action-form').show(); 146 147 if( $sectionForm.length && referral && $sectionForm.find('input[name="_xoo_el_referral"]').length ){ 148 $sectionForm.find('input[name="_xoo_el_referral"]').val(referral); 149 } 150 151 } 152
153 //Setting Tab 154 if( this.$tabs ){ 155 this.$tabs.find('li').removeClass( activeClass ); 156 if( this.$tabs.find('li[data-tab="'+formType+'"]').length ){ 157 this.$tabs.find('li[data-tab="'+formType+'"]').addClass( activeClass ); 158 } 159 } 160 161 $(document.body).trigger( 'xoo_el_form_toggled', [ formType, this, referral ] ); //backward compat 162 this.$container.triggerHandler( 'xoo_el_form_toggled', [ formType, this, referral ] ); //backward compat 163 164 } 165 166 167 submitForm(e){ 168 169 e.preventDefault(); 170 171 var $form = $(e.currentTarget), 172 $button = $form.find('button[type="submit"]'), 173 $section = $form.parents('.xoo-el-section'), 174 buttonTxt = $button.text(), 175 $notice = $section.find('.xoo-el-notice'), 176 formType = $section.attr('data-section'), 177 container = this; 178 179 $notice.html(''); 180 181 $button.html( xoo_el_localize.html.spinner ).addClass('xoo-el-processing'); 182 183 var form_data = new FormData($form[0]); 184 185 form_data.append( 'action', 'xoo_el_form_action' ); 186 form_data.append( 'display', container.display ); 187 188 189 $.ajax({ 190 url: xoo_el_localize.adminurl, 191 type: 'POST', 192 processData: false, 193 contentType: false, 194 cache: false, 195 enctype: 'multipart/form-data', 196 data: form_data, 197 complete: function( xhr, status ){ 198 199 $button.removeClass('xoo-el-processing').html(buttonTxt); //cleanup 200 201 if( ( status !== 'success' || !xhr.responseJSON || xhr.responseJSON.error === undefined ) ){ 202 203 if( container.formRetries < 2 ){ 204 $form.submit(); 205 container.formRetries++; 206 return; 207 } 208 209 210 if( xoo_el_localize.errorLog === 'yes' ){ 211 $notice.html( parse_notice( "We could not process your request, please check console or try again later.", 'error' ) ).show(); 212 } 213 else if( status !== 'error' ){ 214 location.reload(); 215 } 216 217 } 218 }, 219 success: function(response){ 220 221 container.formRetries = 0; 222 223 //Unexpected response 224 if( response.error === undefined ){ 225 console.log(response); 226 //location.reload(); 227 return; 228 } 229 230 if( response.notice ){ 231 232 $notice.html(response.notice).show(); 233 234 //scrollbar position 235 if( container.display === 'inline' ){ 236 $('html, body').animate({ scrollTop: $notice.offset().top - 100}, 500); 237 } 238 239 } 240 241 if ( response.error === 0 ){ 242 243 if( response.redirect ){ 244 //Redirect 245 setTimeout(function(){ 246 window.location = response.redirect; 247 }, xoo_el_localize.redirectDelay ); 248 } 249 else{ 250 $form.hide(); 251 } 252 253 $form.trigger('reset'); 254 255 if( formType === 'resetpw' && xoo_el_localize.resetPwPattern === 'link' ){ 256 $form.add( '.xoo-el-resetpw-hnotice' ).remove(); 257 } 258 259 } 260 261 $( document.body ).trigger( 'xoo_el_form_submitted', [ response, $form, container ] ); //for backward compatibility 262 $form.triggerHandler( 'xoo_el_form_submitted', [ response, $form, container ] ); 263 264 } 265 }). 266 fail(function(jqXHR, textStatus, errorThrown){ 267 if( container.formRetries < 2 ) return; 268 $('body, .xoo-el-popup-notice').addClass('xoo-el-popup-notice-active'); 269 var iframe = $('.xoo-el-notice-wrap iframe').get(0); 270 iframe.contentWindow.document.open(); // Open the iframe's document 271 iframe.contentWindow.document.write(jqXHR.responseText); // Write the string 272 iframe.contentWindow.document.close(); // Close and render the iframe's document 273 274 var iframeDocument = iframe.contentWindow.document; 275 276 var style = iframeDocument.createElement("style"); 277 style.textContent = $('.xoo-el-notice-iframestyle').text(); 278 279 // Append the style element to the iframe's head 280 iframeDocument.head.appendChild(style); 281 }) 282 } 283 284 285 singleFormProcess( e, response, $form, container ){ 286 287 if( this !== container ) return; 288 289 if( response.field ){ 290 291 var $field = this.$container.find( response.field ); 292 293 if( $field.length ){ 294 295 this.toggleForm( $field.closest('.xoo-el-section').attr('data-section') ); 296 297 $field.closest('form').show(); 298 299 $field.val(response.fieldValue); 300 301 $field.closest('.xoo-el-section').find('.xoo-el-notice').html(response.notice).show(); 302 303 var $fieldCont = $field.closest('.xoo-aff-group'); 304 305 if( !$fieldCont.find('.xoo-el-edit-em').length ){ 306 $fieldCont.addClass('xoo-el-block-edit'); 307 $(xoo_el_localize.html.editField).insertAfter($field); 308 } 309 310 } 311 } 312 313 } 314 315 } 316 317 318 class Popup{ 319 320 constructor( $popup ){ 321 this.$popup = $popup; 322 this.eventHandlers(); 323 } 324 325 eventHandlers(){ 326 327 if( !xoo_el_localize.preventClosing ){ 328 this.$popup.on( 'click', '.xoo-el-close, .xoo-el-modal, .xoo-el-opac', this.closeOnClick.bind(this) ); 329 $(document.body).on( 'xoo_el_popup_toggled.xooEscEvent', this.onPopupToggled.bind(this) ); 330 } 331 332 $( document.body ).on( 'xoo_el_form_submitted', this.onFormSubmitSuccess.bind(this) ); 333 this.$popup.on( 'click', '.xoo-el-action-btn', this.setScrollBarOnSubmit.bind(this) ); 334 $(window).on('hashchange load', this.openViaHash.bind(this) ); 335 this.triggerPopupOnClick(); //Open popup using link 336 if( xoo_el_localize.checkout && xoo_el_localize.checkout.loginEnabled === 'yes' ){ 337 $('body').on( 'click', '.wc-block-checkout__login-prompt, .wc-block-must-login-prompt', this.checkoutPageLinkClick.bind(this) ); 338 } 339 340 } 341 342 onPopupToggled(e, type){ 343 if( $('body').hasClass('xoo-el-popup-active') ){ 344 $(document).on('keydown.xooEscClose', this.closeOnEscPress.bind(this) ); 345 } 346 else{ 347 $(document).off('keydown.xooEscClose' ); 348 } 349 } 350 351 352 closeOnEscPress(e){ 353 if(event.key === "Escape" || event.keyCode === 27 ){
354 popup.toggle('hide'); 355 } 356 } 357 358 checkoutPageLinkClick(e){ 359 e.preventDefault(); 360 $(e.currentTarget).attr('data-redirect', xoo_el_localize.checkout.loginRedirect).addClass('xoo-el-login-tgr').trigger('click'); 361 } 362 363 triggerPopupOnClick(){ 364 365 $.each( getFormsTrigger(this.$popup), function( triggerClass, formType ){ 366 367 $( document.body ).on( 'click', '.' + triggerClass, function(e){ 368 369 if( $(this).parents( '.xoo-el-form-container' ).length ) return true; //Let container class handle 370 371 e.preventDefault(); 372 e.stopImmediatePropagation(); 373 374 popup.toggle('show'); 375 376 if( $(this).attr( 'data-redirect' ) ){ 377 popup.$popup.find('input[name="xoo_el_redirect"]').val( $(this).attr('data-redirect') ); 378 } 379 380 popup.$popup.find( '.'+triggerClass ).trigger('click'); 381 382 return false; 383 384 }) 385 386 }) 387 388 } 389 390 toggle( type ){ 391 var $els = this.$popup.add( 'body' ), 392 activeClass = 'xoo-el-popup-active'; 393 394 if( type === 'show' ){ 395 $els.addClass(activeClass); 396 } 397 else if( type === 'hide' ){ 398 $els.removeClass(activeClass); 399 } 400 else{ 401 $els.toggleClass(activeClass); 402 } 403 404 $(document.body).trigger( 'xoo_el_popup_toggled', [ type ] ); 405 } 406 407 closeOnClick(e){ 408 var elClassList = e.target.classList; 409 if( elClassList.contains( 'xoo-el-close' ) || elClassList.contains('xoo-el-modal') || elClassList.contains('xoo-el-opac') ){ 410 this.toggle('hide'); 411 } 412 } 413 414 setScrollbarPosition( position ){ 415 this.$popup.find('.xoo-el-srcont').animate({ 416 scrollTop: position || 0 417 }, 300); 418 console.log(this.$popup.find('.xoo-el-srcont').scrollTop); 419 } 420 421 onFormSubmitSuccess( e, response, $form, container ){ 422 this.setScrollbarPosition(); 423 } 424 425 setScrollBarOnSubmit(e){ 426 427 var invalid_els = $(e.currentTarget).closest('form').find('input:invalid'); 428 if( invalid_els.length === 0 ) return; 429 this.setScrollbarPosition( invalid_els.filter(":first").closest('.xoo-aff-group').position().top ); 430 } 431 432 openViaHash(){ 433 434 var hash = $(location).attr('hash'); 435 436 if( hash === '#login' || hash === '#register' ){ 437 438 this.toggle('show'); 439 440 //Clear hash 441 var uri = window.location.toString(), 442 clean_uri = uri.substring( 0, uri.indexOf("#") ); 443 444 window.history.replaceState( 445 {}, 446 document.title, clean_uri 447 ); 448 } 449 450 if( hash === '#login' ){ 451 this.$popup.find('.xoo-el-login-tgr').trigger('click'); 452 } 453 else if( hash === '#register' ){ 454 this.$popup.find('.xoo-el-reg-tgr').trigger('click'); 455 } 456 457 } 458 459 460 } 461 462 class Form{ 463 464 constructor( $form ){ 465 this.$form = $form; 466 } 467 468 eventHandlers(){ 469 470 } 471 472 } 473 474 var popup = null; 475 476 //Popup 477 if( $('.xoo-el-container').length ){ 478 popup = new Popup( $('.xoo-el-container') ); 479 } 480 481 482 //Auto open popup 483 if( xoo_el_localize.isLoggedIn === "no" && xoo_el_localize.autoOpenPopup === 'yes' && localStorage.getItem( "xoo_el_popup_opened" ) !== "yes" ){ 484 485 if( xoo_el_localize.autoOpenPopupOnce === "yes" ){ 486 localStorage.setItem( "xoo_el_popup_opened", "yes" ); 487 } 488 489 setTimeout(function(){ 490 popup.toggle('show'); 491 }, xoo_el_localize.aoDelay); 492 } 493 494 495 $('.xoo-el-form-container').each(function( key, el ){ 496 new Container( $(el) ); 497 }) 498 499 //Trigger popup if reset field link is active 500 if( $('form.xoo-el-form-resetpw').length && xoo_el_localize.resetPwPattern === "link" ){ 501 if( $('.xoo-el-form-inline').length ){ 502 $([document.documentElement, document.body]).animate({ 503 scrollTop: $(".xoo-el-form-inline").offset().top 504 }, 500); 505 } 506 else{ 507 if( popup ){ 508 popup.toggle('show'); 509 } 510 } 511 } 512 513 514 if( $( 'body.woocommerce-checkout' ).length && $('.xoo-el-form-inline').length && $( 'a.showlogin' ).length ){ 515 var $inlineForm = $('.xoo-el-form-inline'); 516 $inlineForm.hide(); 517 $( document.body ).on( 'click', 'a.showlogin', function(){ 518 $inlineForm.slideToggle(); 519 $inlineForm.find('.xoo-el-login-tgr').trigger('click'); 520 } ); 521 } 522 523 524 if( popup && xoo_el_localize.loginClass && $( '.'+xoo_el_localize.loginClass ).length ){ 525 $( 'body:not(.logged-in) .'+xoo_el_localize.loginClass ).on( 'click', function(e){
526 e.preventDefault(); 527 e.stopImmediatePropagation(); 528 popup.toggle('show'); 529 popup.$popup.find( '.xoo-el-login-tgr' ).trigger('click'); 530 } ); 531 } 532 533 if( popup && xoo_el_localize.registerClass && $( '.'+xoo_el_localize.registerClass ).length ){ 534 $( 'body:not(.logged-in) .'+xoo_el_localize.registerClass ).on( 'click', function(e){ 535 e.preventDefault(); 536 e.stopImmediatePropagation(); 537 popup.toggle('show'); 538 popup.$popup.find( '.xoo-el-reg-tgr' ).trigger('click'); 539 } ); 540 } 541 542 543 $('.xoo-el-notice-close').on('click', function(){ 544 $('body, .xoo-el-popup-notice').removeClass('xoo-el-popup-notice-active'); 545 }) 546 547 548 549 class CodeFormHandler{ 550 551 constructor( $codeForm ){ 552 553 const existing = CodeFormHandler.instances.get($codeForm[0]); 554 555 if (existing) return existing; 556 557 this.$codeForm = $codeForm; 558 this.codeFormID = this.$codeForm.data('code'); 559 this.$parentForm = this.$codeForm.data('parentform') ? $(this.$codeForm.siblings(this.$codeForm.data('parentform')).get(0)) : $(); 560 561 this.CodePasted = false; 562 563 this.resendData = {}; 564 565 this.$noticeCont = this.$codeForm.find('.xoo-el-code-notice'); 566 567 this.$submitBtn = this.$codeForm.find('.xoo-el-code-submit-btn'); 568 this.submitBtnTxt = this.$submitBtn.html(); 569 this.$inputs = this.$codeForm.find('.xoo-el-code-input'); 570 this.$resendLink = this.$codeForm.find('.xoo-el-code-resend-link'); 571 this.noticeTimout = this.resendTimer = false; 572 this.parentFormValues = {} 573 this.codesent = false; 574 575 this.$container = this.$codeForm.closest('.xoo-el-form-container'); 576 577 this.events(); 578 579 CodeFormHandler.instances.set($codeForm[0], this); 580 } 581 582 583 events(){ 584 585 this.$resendLink.on( 'click', { _thisObj: this }, this.resendCode ); 586 this.$codeForm.find('.xoo-el-code-no-change').on( 'click', { _thisObj: this }, this.changeParentInput ); 587 this.$codeForm.on( 'submit', { _thisObj: this }, this.onSubmit ); 588 this.$inputs.on( 'paste', { _thisObj: this }, this.onCodeInputPaste ); 589 this.$inputs.on( 'input', { _thisObj: this }, this.onCodeInputChange ); 590 this.$inputs.on( 'keydown ', { _thisObj: this }, this.beforeCodeInputChange ); 591 592 this.$container.on( 'xoo_el_form_toggled', this.onParentFormToggled.bind(this) ) 593 594 595 } 596 597 598 onParentFormToggled( e, formType, containerObj, referral ){ 599 600 let _thisObj = this; 601 602 if( _thisObj.codesent ){ 603 _thisObj.$parentForm.hide(); 604 _thisObj.$codeForm.show(); 605 } 606 } 607 608 onCodeInputPaste(event){ 609 610 var _thisObj = event.data._thisObj, 611 _this = $(this); 612 613 _thisObj.CodePasted = true; 614 615 setTimeout(function(){ 616 617 var inputVal = _this.val().trim(), 618 inputValLength = inputVal.length; 619 620 _thisObj.$inputs.val(''); 621 622 for (var i = 0; i < inputValLength; ++i) { 623 624 var chr = inputVal.charAt(i), 625 $Codeinput = $(_thisObj.$inputs.get(i)); 626 627 if( $Codeinput.length ){ 628 $Codeinput.val(chr); 629 } 630 631 if( i === (inputValLength - 1) ){ 632 $Codeinput.focus(); 633 } 634 } 635 636 if( inputValLength === _thisObj.$inputs.length ){ 637 _thisObj.$codeForm.trigger('submit'); 638 } 639 640 _thisObj.CodePasted = false; 641 642 }, 10 ) 643 644 } 645 646 onCodeInputChange(event){ 647 648 var _thisObj = event.data._thisObj, 649 inputVal = $(this).val(), 650 inputValLength = inputVal.length; 651 652 if( inputValLength > 1 && !_thisObj.CodePasted ){ 653 $(this).trigger('paste'); 654 return; 655 } 656 657 if( _thisObj.CodePasted || _thisObj.processing ){ 658 return; 659 } 660 661 _thisObj.processing = true; 662 663 var $nextInput = $(this).next('input.xoo-el-code-input'), 664 $prevInput = $(this).prev('input.xoo-el-code-input'); 665 666 667 //Switch Input 668 if( inputValLength && $nextInput.length !== 0 ){ 669 $nextInput.focus(); 670 } 671 672 673 _thisObj.processing = false; 674 675 } 676 677 beforeCodeInputChange(event){ 678 679 var _thisObj = event.data._thisObj, 680 inputVal = $(this).val(), 681 inputValLength = inputVal.length; 682 683 684 var $nextInput = $(this).next('input.xoo-el-code-input'), 685 $prevInput = $(this).prev('input.xoo-el-code-input'); 686 687 688 if( inputVal.length && event.keyCode != 8 && event.keyCode !== 13 ){ 689 690 if( $nextInput.length && !$nextInput.val() ){ 691 $nextInput.focus(); 692 } 693 else{ 694 $(this).val(''); 695 } 696 697 } 698 699 //Backspace is pressed 700 if( !inputValLength && event.keyCode == 8 && $prevInput.length !== 0 ){ 701 $prevInput.focus(); 702 } 703 704 } 705 706 onSubmit(event){ 707 708 event.preventDefault(); 709 710 var _thisObj = event.data._thisObj; 711 712 if( !_thisObj.validateInputs() || !_thisObj.getCodeValue().length ) return false; 713 714 _thisObj.$submitBtn.html( xoo_el_localize.html.spinner ).addClass('xoo-el-processing'); 715 716 _thisObj.verifyCode(); 717 } 718 719 720 changeParentInput(event){ 721 var _thisObj = event.data._thisObj; 722 _thisObj.codesent = false; 723 _thisObj.$codeForm.hide(); 724 _thisObj.$parentForm.show();
725 _thisObj.$inputs.val(''); 726 } 727 728 729 resendCode(event){ 730 731 event.preventDefault(); 732 733 var _thisObj = event.data._thisObj; 734 735 _thisObj.startResendTimer(); 736 737 var form_data = { 738 action: 'xoo_el_resend_code', 739 'parentFormData': objectifyForm( _thisObj.$parentForm), 740 } 741 742 form_data = Object.assign({}, form_data, _thisObj.resendData); 743 744 _thisObj.$resendLink.addClass('xoo-el-processing'); 745 746 $.ajax({ 747 url: xoo_el_localize.adminurl, 748 type: 'POST', 749 data: form_data, 750 success: function(response){ 751 752 _thisObj.$resendLink.trigger( 'xoo_el_code_resent', [ response, _thisObj ] ); 753 754 _thisObj.$resendLink.removeClass('xoo-el-processing'); 755 756 if( response.notice ){ 757 _thisObj.showNotice( response.notice ); 758 } 759 760 }, 761 complete: function(){ 762 763 } 764 }); 765 } 766 767 768 validateInputs(){ 769 770 var passedValidation = true; 771 772 this.$inputs.each( function( index, input ){ 773 var $input = $(input); 774 if( $input.val().trim() === '' ){ 775 $input.focus(); 776 passedValidation = false; 777 return false; 778 } 779 } ); 780 781 782 return passedValidation; 783 784 } 785 786 onSuccess(response){ 787 this.$codeForm.removeAttr('data-processing'); 788 this.codesent = false; 789 this.$codeForm.hide(); 790 this.$inputs.val(''); 791 792 if( this.$parentForm.length ){ 793 if( response.notice ){ 794 this.$parentForm.closest('.xoo-el-section').find('.xoo-el-notice').html(response.notice).show(); 795 } 796 this.$parentForm.show(); 797 } 798 799 } 800 801 startResendTimer(){ 802 var _thisObj = this, 803 $cont = this.$codeForm.find('.xoo-el-code-resend'), 804 $resendLink = $cont.find('.xoo-el-code-resend-link'), 805 $timer = $cont.find('.xoo-el-code-resend-timer'), 806 resendTime = parseInt( xoo_el_localize.resend_wait ); 807 808 if( resendTime === 0 ) return; 809 810 $resendLink.addClass('xoo-el-disabled'); 811 812 clearInterval( this.resendTimer ); 813 814 this.resendTimer = setInterval(function(){ 815 $timer.html('('+resendTime+')'); 816 if( resendTime <= 0 ){ 817 clearInterval( _thisObj.resendTimer ); 818 $resendLink.removeClass('xoo-el-disabled'); 819 $timer.html(''); 820 } 821 resendTime--; 822 },1000) 823 } 824 825 showNotice(notice){ 826 var _thisObj = this; 827 clearTimeout(this.noticeTimout); 828 this.$noticeCont.html( notice ).show(); 829 this.noticeTimout = setTimeout(function(){ 830 _thisObj.$noticeCont.hide(); 831 },4000) 832 } 833 834 onCodeSent(response){ 835 836 var _thisObj = this; 837 838 if( response.error ) return; 839 840 _thisObj.codesent = true; 841 842 _thisObj.$codeForm.show(); 843 844 if( response.code_txt ){ 845 _thisObj.$codeForm.find('.xoo-el-code-no-txt').html( response.code_txt ); 846 } 847 848 setTimeout(function(){ 849 _thisObj.$inputs.first().trigger('click'); 850 _thisObj.$inputs.first().focus(); 851 _thisObj.$inputs.first().attr('autofocus', true); 852 }, 500) 853 854 _thisObj.startResendTimer(); 855 856 857 _thisObj.parentFormValues = _thisObj.$parentForm.serialize(); 858 859 _thisObj.$codeForm.attr('data-processing','yes'); 860 861 _thisObj.$parentForm.hide(); 862 863 } 864 865 verifyCode(data){ 866 867 var _thisObj = this; 868 869 var form_data = $.extend( { 870 'code': _thisObj.getCodeValue(), 871 'action': 'xoo_el_code_form_submit', 872 'xoo_el_code_ajax': _thisObj.codeFormID, 873 'parentFormData': objectifyForm( _thisObj.$parentForm ) 874 }, data ); 875 876 877 $.ajax({ 878 url: xoo_el_localize.adminurl, 879 type: 'POST', 880 data: form_data, 881 success: function(response){ 882 _thisObj.$submitBtn.removeClass('xoo-el-processing').html(_thisObj.submitBtnTxt); 883 884 if( response.notice ){ 885 _thisObj.showNotice( response.notice ); 886 } 887 888 if( response.error === 0 ){ 889 _thisObj.onSuccess(response); 890 _thisObj.$codeForm.trigger( 'xoo_el_on_code_success', [response] ); 891 } 892 } 893 }); 894 } 895 896 validateFormSubmit(){ 897 898 if( this.validateInputs() && this.getCodeValue().length ){ 899 this.$submitBtn.html( xoo_el_localize.html.spinner ).addClass('xoo-el-processing'); 900 return true; 901 } 902 } 903 904 getCodeValue(){ 905 var code = ''; 906 this.$inputs.each( function( index, input ){ 907 code += $(input).val(); 908 }); 909 return code; 910 } 911 912 } 913 914 CodeFormHandler.instances = new WeakMap(); 915 916 917 $('.xoo-el-code-form').each(function( index, codeForm ){ 918 919 new CodeFormHandler( $(codeForm) ); 920 921 }); 922 923 924 window.xooEl.CodeFormHandler = CodeFormHandler; //allow other plugins to acccess this 925 926 927 928 if( xoo_el_localize.resetPwPattern === "code" ){ 929 930 class lostPasswordFormHandler{ 931 932 constructor( $form ){ 933 this.$form = $form; 934 this.$section = this.$form.closest('.xoo-el-section'); 935 this.$resetPwSection = this.$section.siblings('[data-section="resetpw"]'); 936 this.$resetPwForm = this.$resetPwSection.find('.xoo-el-form-resetpw'); 937 this.$container = this.$section.closest('.xoo-el-form-container'); 938 this.codeFormHandler = new CodeFormHandler( $form.siblings('.xoo-el-code-form') ); 939 this.events(); 940 } 941 942 events(){ 943 this.$form.on( 'xoo_el_form_submitted', this.onFormSubmit.bind(this) ); 944 this.$resetPwForm.on( 'xoo_el_form_submitted', this.onResetPWFormSubmit.bind(this) ); 945 this.codeFormHandler.$codeForm.on( 'xoo_el_on_code_success', this.onCodeVerificationSuccess.bind(this) ); 946 this.$container.on( 'xoo_el_form_toggled', this.onLostPasswordFormToggle.bind(this) ); 947 } 948 949 950 onFormSubmit( e, response, $form, container ){ 951 let _thisObj = this; 952 _thisObj.codeFormHandler.onCodeSent(response); 953 _thisObj.$resetPwSection.removeAttr('data-verified','yes'); 954 } 955 956 onResetPWFormSubmit( e, response, $form, containerObj ){ 957 let _thisObj = this; 958 _thisObj.$resetPwSection.removeAttr('data-verified','yes'); 959 if( response.error ){ 960 _thisObj.$section.find('.xoo-el-notice').html(response.notice).show(); 961 if( response.error_code === 'code_reset' ){ 962 containerObj.toggleForm('lostpw'); 963 } 964 } 965 else{ 966 containerObj.toggleForm('login'); 967 this.$container.find('.xoo-el-section[data-section="login"]').find('.xoo-el-notice').html(response.notice).show(); 968 } 969 } 970 971 onCodeVerificationSuccess( e, response ){ 972 let _thisObj = this; 973 _thisObj.$container.find('.xoo-el-resetpw-tgr').trigger('click'); 974 _thisObj.$resetPwSection.attr('data-verified','yes'); 975 } 976 977 onLostPasswordFormToggle( e, formType, containerObj, referral ){ 978 979 let _thisObj = this; 980 981 if( formType !== 'lostpw' ) return; 982 983 if( _thisObj.$resetPwSection.attr('data-verified') === "yes" ){ 984 containerObj.toggleForm('resetpw'); 985 } 986 987 988 989 } 990 991 } 992 993 $('form.xoo-el-form-lostpw').each(function(index, el){ 994 new lostPasswordFormHandler($(el)); 995 }) 996 997 } 998 999 1000 $( 'body' ).on( 'submit', 'form.xoo-elpof-profile-update', function(e){
1001 1002 e.preventDefault(); 1003 1004 var $form = $(e.currentTarget), 1005 $button = $form.find('button[type="submit"]'), 1006 buttonTxt = $button.text(), 1007 $noticeCont = $form.find('.xoo-elpof-notices'); 1008 1009 $button.html( xoo_el_localize.html.spinner ).addClass('xoo-el-processing'); 1010 $noticeCont.html(''); 1011 1012 var form_data = new FormData($form[0]); 1013 form_data.append( 'action', 'xoo_elpof_update_profile' ); 1014 1015 $.ajax({ 1016 url: xoo_el_localize.adminurl, 1017 type: 'POST', 1018 processData: false, 1019 contentType: false, 1020 cache: false, 1021 enctype: 'multipart/form-data', 1022 data: form_data, 1023 success: function(response){ 1024 if( response.notice ){ 1025 $noticeCont.html(response.notice); 1026 $('html, body').animate({ scrollTop: $noticeCont.offset().top - 100}, 500); 1027 } 1028 1029 if( response.refreshPage ){ // if form has file field 1030 setTimeout(function(){ 1031 location.reload(); 1032 }, 1000) 1033 1034 } 1035 }, 1036 complete: function( xhr, status ){ 1037 $button.removeClass('xoo-el-processing').html(buttonTxt); 1038 } 1039 }); 1040 1041 } ) 1042 1043 1044})
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.