1 2 3(function ($) { 4 $(document).ready(function () { 5 6 /** 7 * Adjust cellphone messages 8 */ 9 const cellInput = document.getElementById('member-cellphone') 10 11 if(cellInput) { 12 cellInput.oninvalid = (e) => { 13 e.target.setCustomValidity('××ספר ××× × ×ª×§××') 14 } 15 16 cellInput.oninput = function (event) { 17 event.target.setCustomValidity(''); 18 } 19 20 cellInput.onpaste = function (event) { 21 event.target.setCustomValidity(''); 22 } 23 } 24 25 /** 26 * Missing fileds validation message 27 */ 28 const INVALID_MSG = '×ש ×××× ×¤×¨×××' 29 30 const resetValidity = eTarget => { 31 const isValid = eTarget.value && 0 < eTarget.value.length 32 eTarget.setCustomValidity(isValid ? '' : INVALID_MSG) 33 } 34 const $requiredFields = $('#simply-auth-popup [required]') 35 $requiredFields.each((_,el)=>{ 36 el.oninvalid = e=> { 37 e.target.setCustomValidity(INVALID_MSG) 38 } 39 el.oninput = e => { 40 resetValidity(e.target) 41 } 42 el.onpaste = e => { 43 resetValidity(e.target) 44 } 45 el.onBlur = e => { 46 resetValidity(e.target) 47 } 48 el.onChange = e => { 49 resetValidity(e.target) 50 } 51 }) 52 53 /** 54 * Open dialog on auth click 55 */ 56 $('body').on( 57 'click', 58 SimplyAuth.btn_selectors, 59 (e) => { 60 e.preventDefault(); 61 const $popup = $('#simply-auth-popup') 62 $popup.addClass('open'); 63 $(document.body).addClass('auth-popup-open') 64 } 65 ) 66 67 /** 68 * Close dialog 69 */ 70 $(document).on( 71 'click', 72 '.close-auth-popup', 73 (e) => { 74 e.preventDefault(); 75 $('#simply-auth-popup').removeClass('open') 76 $(document.body).removeClass('auth-popup-open') 77 $(".auth-stage.active").removeClass('active') 78 $(`.auth-stage.stage-phone`).addClass('active') 79 $('#simply-auth-popup input').val('') 80 } 81 ) 82 83 /** 84 * Go back 85 */ 86 $(document).on( 87 'click', 88 '#simply-auth-popup .auth-back', 89 (e) => { 90 e.preventDefault(); 91 $('#auth-error').text('').addClass('hidden') 92 93 $(".auth-stage.active").removeClass('active') 94 $(`.auth-stage.stage-phone`).addClass('active') 95 } 96 ) 97 98 /** 99 * Submit forms on "Enter" 100 */ 101 $(document.body).on( 102 'keydown', 103 '#simply-auth-popup form', 104 (e) => { 105 if (e.keyCode === 13) { 106 e.preventDefault() 107 $(e.currentTarget).submit() 108 } 109 } 110 ) 111 112 /** 113 * Check cellphone 114 */ 115 $(document.body).on( 116 'submit', 117 '#cellphone-form', 118 (e) => { 119 e.preventDefault(); 120 const form = document.getElementById('cellphone-form') 121 if (!form.checkValidity()) { 122 form.reportValidity(); 123 return; 124 } 125 126 $('#auth-error').text('').addClass('hidden') 127 128 const $btn = $('#check-cellphone') 129 const cellphone = $('#member-cellphone').val().replace(/\D/g, '') 130 $btn.attr('disabled', true) 131 132 $.post( 133 SimplyAuth.ajax_url, 134 { 135 action: "simply-check-member-cellphone", 136 cellphone: cellphone 137 }, 138 (r) => { 139 $(".auth-stage.active").removeClass('active') 140 $(`.auth-stage.stage-${r.stage}`).addClass('active') 141 $btn.attr('disabled', false) 142 143 if ('register' === r.stage) { 144 prepareRegistrationForm(cellphone) 145 $('#simply-registration-form').addClass('new-member') 146 147 } else if ('otp' === r.stage) { 148 $('#otp-form').append( 149 $('<input type="hidden" name="verify_otp" id="verify_otp" />').val(r.otp) 150 ) 151 } else if ('login' === r.stage) { 152 window.location.reload() 153 } 154 } 155 ) 156 } 157 ) 158 159 /** 160 * Register user 161 */ 162 $(document.body).on( 163 'submit', 164 '#simply-registration-form', 165 (e) => { 166 e.preventDefault(); 167 const form = document.getElementById('simply-registration-form') 168 if (!form.checkValidity()) { 169 form.reportValidity(); 170 return; 171 } 172 173 const $btn = $(e.currentTarget).find('#register-member') 174 const $form = $btn.closest('form') 175 const formData = new FormData($form.get(0)) 176 formData.append("billing_phone", $('#simply-registration-form #billing_phone').val().replace(/\D/g, '')) 177 let data = {} 178 formData.forEach((v,k)=>data[k] = v) 179 $btn.attr('disabled', true) 180 $('#auth-error').text('').addClass('hidden') 181 182 $.post( 183 SimplyAuth.ajax_url, 184 { 185 action: "simply-register-user", 186 ...data 187 }, 188 (r) => { 189 if (r.success) { 190 window.location.reload() 191 } 192 else { 193 $btn.attr('disabled', false) 194 $('#auth-error').text(r.data).removeClass('hidden').focus() 195 } 196 } 197 ) 198 } 199 ) 200 201 /** 202 * Check OTP 203 */ 204 $(document.body).on( 205 'submit', 206 '#otp-form', 207 (e) => { 208 e.preventDefault() 209 const form = document.getElementById('otp-form') 210 if (!form.checkValidity()) { 211 form.reportValidity(); 212 return; 213 } 214 215 const $form = $(e.currentTarget) 216 const $btn = $form.find('#check-otp') 217 const otpCode = $('#member-otp').val() 218 const cellphone = $('#member-cellphone').val().replace(/\D/g, '') 219 $btn.attr('disabled', true) 220 $('#auth-error').text('').addClass('hidden') 221 222 $.post( 223 SimplyAuth.ajax_url, 224 { 225 action: "simply-check-member-otp", 226 otp: otpCode, 227 verifyOtp: $('#verify_otp').val(), 228 cellphone: cellphone 229 }, 230 (r) => { 231 $btn.attr('disabled', false) 232 233 if ("register" === r.stage) { 234 $(".auth-stage.active").removeClass('active') 235 $(`.auth-stage.stage-register`).addClass('active') 236 $('#simply-registration-form').removeClass('new-member') 237 238 prepareRegistrationForm(cellphone) 239 return; 240 } 241 242 if (r.success) { 243 window.location.reload() 244 } 245 246 $('#auth-error').text(r.data).removeClass('hidden') 247 248 } 249 ) 250 } 251 ) 252 253 }) 254 255 /** 256 * Utility to prepare the registration form 257 */ 258 const prepareRegistrationForm = (cellphone) => { 259 const $dob = $('#sclub_date_of_birth'); 260 $dob.datepicker({ 261 dateFormat: "dd/mm/yy", 262 yearRange: "-100:+0", 263 changeYear: true, 264 changeMonth: true, 265 gotoCurrent: true, 266 defaultDate: "+0" 267 }) 268 269 $('#simply-registration-form #billing_phone').val(cellphone) 270 } 271 272})(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.