1(function($) 2{ 3 $(window).on('elementor/frontend/init', function() 4 { 5 elementorFrontend.hooks.addAction('frontend/element_ready/widget', function(scope) 6 { 7 if($(scope[0]).hasClass('elementor-widget-registration-form')) 8 { 9 new lidmaatschapBlock(scope[0]); 10 } 11 12 var userProfileForms = $(scope[0]).find('form.userprofile'); 13 for(var a=0; a<userProfileForms.length; a++) 14 { 15 new userProfileForm(userProfileForms[a]); 16 } 17 18 19 }.bind(this)); 20 }.bind(this)); 21 22 23 function lidmaatschapBlock(el) 24 { 25 this.el = el; 26 this.desc = $(el).find('.lidmaatschap-description')[0]; 27 this.select = $(this.el).find('select[name=lidmaatschap]')[0]; 28 this.form = $(this.el).find('form'); 29 30 this.init = function() 31 { 32 this.form[0].removeAttribute('onsubmit'); 33 this.form[0].onsubmit = function() 34 { 35 // Lock form 36 this.lock(true); 37 this.wait(true); 38 39 var isValid = this.validateForm(); 40 if(isValid) 41 { 42 this.postForm(function() 43 { 44 this.lock(false); 45 this.wait(false); 46 }.bind(this)); 47 }else 48 { 49 this.lock(false); 50 this.wait(false); 51 } 52 53 return false; 54 }.bind(this); 55 56 this.form[0].addEventListener('change', function(e) 57 { 58 this.validateInput(e.target); 59 }.bind(this)); 60 61 this.select.addEventListener('change', function() 62 { 63 this.updateDescription(); 64 this.updatePresents(); 65 }.bind(this)); 66 67 this.updateDescription(); 68 this.updatePresents(); 69 } 70 71 this.wait = function(state) 72 { 73 if(state) 74 { 75 this.form.addClass('wait'); 76 77 if(this.activityIndicator && this.activityIndicator.parentNode) 78 this.activityIndicator.parentNode.removeChild(this.activityIndicator); 79 80 this.activityIndicator = document.createElement('i'); 81 this.activityIndicator.className = 'fal fa-sync fa-spin activityIndicator'; 82 this.form.find('[type=submit] span span')[0].appendChild(this.activityIndicator); 83 }else 84 { 85 this.form.removeClass('wait'); 86 87 if(this.activityIndicator && this.activityIndicator.parentNode) 88 this.activityIndicator.parentNode.removeChild(this.activityIndicator); 89 } 90 } 91 92 this.lock = function(state) 93 { 94 if(state) 95 { 96 this.form.addClass('lock'); 97 this.form.find(':input').attr('readonly', 'readonly'); 98 }else 99 { 100 this.form.find(':input').removeAttr('readonly'); 101 this.form.removeClass('lock'); 102 } 103 } 104 105 this.postForm = function(onReady) 106 { 107 this.form.find('.row.error').removeClass('error'); 108 109 $.ajax( 110 { 111 type: "POST", 112 url: MyAjax.ajaxurl, 113 data: { 114 action: 'createLidmaatschap', 115 fields: this.form.serializeArray() 116 }, 117 success: function(data) 118 { 119 if(data.errors) 120 { 121 for(var i=0; i<data.errors.length; i++) 122 { 123 var fieldname = data.errors[i]; 124 fieldname = fieldname.replace('[', '\\['); 125 fieldname = fieldname.replace(']', '\\]'); 126 127 var row = $('[name='+fieldname+']').parents('.row'); 128 row.addClass('error'); 129 } 130 } 131 132 if(data.success && data.redirect) 133 { 134 window.location = data.redirect; 135 return; 136 } 137 138 onReady(); 139 }, 140 error: function() 141 { 142 onReady(); 143 } 144 }); 145 } 146 147 this.validateForm = function() 148 { 149 var errors = 0; 150 this.form.find('.row.error').removeClass('error'); 151 var inputs = this.form.find('input, select'); 152 for(var i=0; i<inputs.length; i++) 153 { 154 var input = inputs[i]; 155 var isValid = this.validateInput(input, true); 156 if(!isValid) 157 errors++; 158 } 159 160 if(errors>0) 161 return false;
162 else 163 return true; 164 } 165 166 this.validateInput = function(input, addErrors) 167 { 168 var errors = 0; 169 var isValid = true; 170 var row = $(input).parents('.row'); 171 var inputs = row.find('input, select'); 172 173 for(var i=0; i<inputs.length; i++) 174 { 175 var input = inputs[i]; 176 if(input.name==='fld-gender-other-text' && row.find('#fld-gender-other:checked').length===0) 177 { 178 continue; 179 } 180 if(!this._validateInput(input)) 181 { 182 errors++; 183 break; 184 } 185 } 186 187 if(errors===0) 188 { 189 row.removeClass('error'); 190 }else if(addErrors) 191 { 192 row.addClass('error'); 193 } 194 195 return (errors===0); 196 } 197 198 this._validateInput = function(input) 199 { 200 var isValid = true; 201 var row = $(input).parents('.row'); 202 var type = input.tagName.toLowerCase()==="input" ? input.type : input.tagName.toLowerCase(); 203 204 switch(type) 205 { 206 case 'radio': 207 var radios = row.find('input[name='+input.name+']:checked'); 208 if(!radios.length>0) 209 isValid = false; 210 break; 211 default: 212 isValid = (input.value && input.value!=="") ? true : false; 213 break; 214 } 215 216 return isValid; 217 } 218 219 this.updateDescription = function() 220 { 221 var desc = ""; 222 if(this.select.options[this.select.selectedIndex].hasAttribute('desc')) 223 desc = this.select.options[this.select.selectedIndex].getAttribute('desc'); 224 225 this.desc.innerHTML = desc; 226 } 227 228 this.updatePresents = function() 229 { 230 var lidmaatschap = this.select.options[this.select.selectedIndex].value; 231 this.renderPresents(lidmaatschap); 232 } 233 234 this.renderPresents = function(lidmaatschap) 235 { 236 if(lidmaatschap && lidmaatschap>0) 237 { 238 $(this.el).find('.row.lidmaatschap-kado').css({'display': 'flex'}); 239 var contentEl = $(this.el).find('.lidmaatschap-kado .field')[0]; 240 contentEl.innerHTML = ''; 241 242 this.activityIndicator = document.createElement('i'); 243 this.activityIndicator.className = 'fal fa-sync fa-spin activityIndicator'; 244 contentEl.appendChild(this.activityIndicator); 245 246 $.ajax( 247 { 248 type: "GET", 249 url: MyAjax.ajaxurl, 250 data: { 251 action: 'presentsFromLidmaatschap', 252 lidmaatschap: lidmaatschap 253 }, 254 success: function(result) 255 { 256 this.activityIndicator.parentNode.removeChild(this.activityIndicator); 257 258 for(var i=0; i<result.presents.length; i++) 259 { 260 var present = result.presents[i]; 261 var el = document.createElement('label'); 262 el.className = 'present'; 263 el.setAttribute('for', 'present-'+present.id); 264 265 var image = document.createElement('div'); 266 if(present.image) 267 image.style.backgroundImage = 'url('+present.image+')'; 268 269 image.className = 'image'; 270 el.appendChild(image); 271 272 273 var radiobutton = document.createElement('input'); 274 radiobutton.setAttribute('type', 'radio'); 275 radiobutton.setAttribute('name', 'present'); 276 radiobutton.setAttribute('id', 'present-'+present.id); 277 radiobutton.setAttribute('value', present.id); 278 el.appendChild(radiobutton); 279 280 var title = document.createElement('h3'); 281 title.innerHTML = present.title; 282 el.appendChild(title); 283 284 var desc = document.createElement('div'); 285 desc.className = 'desc'; 286 desc.innerHTML = present.description; 287 el.appendChild(desc); 288 289 contentEl.appendChild(el); 290 } 291 292 var clear = document.createElement('div'); 293 clear.className = 'clear'; 294 contentEl.appendChild(clear); 295 296 }.bind(this) 297 }); 298 } 299 } 300 301 this.init(); 302 }; 303 304 function userProfileForm(form) 305 { 306 this.form = form; 307 308 this.init = function() { 309 this.form.removeAttribute('onsubmit'); 310 this.form.onsubmit = function(e) 311 { 312 e.preventDefault(); 313 this.lock(true); 314 this.wait(true); 315 316 this.postForm(function() 317 { 318 this.lock(false); 319 this.wait(false); 320 }.bind(this)); 321 322 return false;
323 }.bind(this) 324 } 325 326 this.lock = function(state) 327 { 328 if(state) 329 { 330 $(this.form).addClass('lock'); 331 $(this.form).find(':input').attr('readonly', 'readonly'); 332 $(this.form).find('[type=submit]').attr('disabled', 'disabled'); 333 }else 334 { 335 $(this.form).find('[type=submit]').removeAttr('disabled'); 336 $(this.form).find(':input').removeAttr('readonly'); 337 $(this.form).removeClass('lock'); 338 } 339 } 340 341 this.wait = function(state) 342 { 343 if(state) 344 { 345 $(this.form).addClass('wait'); 346 347 if(this.activityIndicator && this.activityIndicator.parentNode) 348 this.activityIndicator.parentNode.removeChild(this.activityIndicator); 349 350 this.activityIndicator = document.createElement('i'); 351 this.activityIndicator.className = 'fal fa-sync fa-spin activityIndicator'; 352 $(this.form).find('[type=submit] span span')[0].appendChild(this.activityIndicator); 353 }else 354 { 355 $(this.form).removeClass('wait'); 356 357 if(this.activityIndicator && this.activityIndicator.parentNode) 358 this.activityIndicator.parentNode.removeChild(this.activityIndicator); 359 } 360 } 361 362 this.postForm = function(onReady) 363 { 364 $.ajax( 365 { 366 type: "POST", 367 url: MyAjax.ajaxurl, 368 data: { 369 action: 'updateUserProfile', 370 fields: $(this.form).serializeArray() 371 }, 372 success: function(data) 373 { 374 $(this.form).find('.row.error').removeClass('error'); 375 $(this.form).find('input[type="password"]').val(''); 376 377 if(data.errors) 378 { 379 for(var i=0; i<data.errors.length; i++) 380 { 381 var fieldname = data.errors[i]; 382 fieldname = fieldname.replace('[', '\\['); 383 fieldname = fieldname.replace(']', '\\]'); 384 385 var row = $('[name='+fieldname+']').parents('.row'); 386 row.addClass('error'); 387 } 388 } 389 390 if(data.messages) 391 { 392 for(var i=0; i<data.messages.length; i++) 393 { 394 var msg = document.createElement('div'); 395 msg.className = 'msg'; 396 msg.innerHTML = data.messages[i]; 397 398 $(this.form).prepend(msg); 399 } 400 } 401 402 onReady(); 403 }.bind(this), 404 error: function() 405 { 406 onReady(); 407 } 408 }); 409 } 410 411 this.init(); 412 } 413 414})(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.