1if (typeof ajaxFormSubmit === 'undefined') { 2 3 $(document).on('click', 'button[data-button-action="ajax-recaptcha"]', function(event) { 4 new ajaxFormSubmit( $(this) ); 5 }); 6 7 class ajaxFormSubmit { 8 _SELF; 9 _FORM_ID; 10 _FORM_ACTION; 11 _GOOGLE_RECAPTCHA_SITE_KEY; 12 _GOOGLE_RECAPTCHA_VER; 13 _SITE_TPL_VER; 14 _VALIDATION_ERROR; 15 _MODAL_VER; 16 _NO_RESET_FORM; 17 _EXTERNAL_VALIDATION; 18 _RELOAD_PAGE; 19 _GO_TO_URL; 20 _RECAPTCHA_ACTION 21 22 constructor(thisObj) { 23 let _this = this; 24 this._SELF = $(thisObj); 25 this._FORM_ID = this._SELF.attr('data-id'); 26 this._FORM_ACTION = this._SELF.attr('data-form-action'); 27 this._GOOGLE_RECAPTCHA_SITE_KEY = this._SELF.attr('data-grecaptcha-site-key'); 28 this._GOOGLE_RECAPTCHA_VER = this._SELF.attr('data-recaptcha-ver'); 29 this._SITE_TPL_VER = this._SELF.attr('data-site-tpl'); 30 this._VALIDATION_ERROR = this._SELF.attr('data-validation-error'); 31 this._MODAL_VER = this._SELF.attr('data-modal-ver'); 32 this._NO_RESET_FORM = this._SELF.attr('data-no-reset-form'); 33 this._EXTERNAL_VALIDATION = this._SELF.attr('data-external-validation'); 34 this._RELOAD_PAGE = this._SELF.attr('data-reload-page'); 35 this._GO_TO_URL = this._SELF.attr('data-go-to-url'); 36 this._RECAPTCHA_ACTION = this._SELF.attr('data-recaptcha-action'); 37 this._CALLBACK_ON_SUCCESS = this._SELF.attr('data-callback-on-success'); 38 39 if (this._MODAL_VER != 0) { 40 this.modalCloseEvents(); 41 } 42 43 this.openRecaptchaLoader(); 44 45 46 this.sendsFormResponse('reset', false, false); 47 48 if (this._SELF.closest('form[data-form-id="' + this._FORM_ID + '"]').hasClass('validateValidatorEngine')) { 49 50 this._SELF.closest('form[data-form-id="' + this._FORM_ID + '"]').validationEngine('attach', { 51 focusFirstField : false 52 }); 53 if ( !this._SELF.closest('form[data-form-id="' + this._FORM_ID + '"]').validationEngine('validate') ) { 54 55 this.sendsFormResponse('error', false, this._VALIDATION_ERROR); 56 this.closeRecaptchaLoader(); 57 if ( this._GOOGLE_RECAPTCHA_VER && this._GOOGLE_RECAPTCHA_VER != 3 ) { 58 59 $('.g-recaptcha').each(function( index ) { 60 grecaptcha.reset(index); 61 }); 62 } 63 return false; 64 } 65 } 66 if (this._EXTERNAL_VALIDATION == 1) { 67 if ( !customValidateForm() ) { 68 this.sendsFormResponse('error', false, this._VALIDATION_ERROR); 69 this.closeRecaptchaLoader(); 70 this.formResetRecaptcha(); 71 return false; 72 } 73 } 74 75 if (this._GOOGLE_RECAPTCHA_VER == 3) { 76 let recaptchaAction = 'validate_captcha'; 77 if (this._RECAPTCHA_ACTION) { 78 recaptchaAction = this._RECAPTCHA_ACTION; 79 } 80 grecaptcha.ready(function () { 81 grecaptcha.execute(_this._GOOGLE_RECAPTCHA_SITE_KEY, { action: recaptchaAction }).then(function (token) { 82 $('input[data-id="g-recaptcha-response"]').val(token); 83 _this.sendsForm(); 84 }); 85 }); 86 } else { 87 this.sendsForm(); 88 } 89 } 90 91 sendsForm() { 92 93 if ( typeof validatePasswordStrenght == 'function' ) { 94 if ( validatePasswordStrenght( $('form[data-form-id="'+ this._FORM_ID +'"] :input[data-event="password-strenght"][data-ps-min-value]') ) == false) { 95 this.sendsFormResponse('error', false, 'La password non soddisfa i criteri di sicurezza'); 96 this.closeRecaptchaLoader(); 97 this.formResetRecaptcha(); 98 return false; 99 } 100 } 101 102 let _this = this; 103 104 let settingsData = this._SELF.closest('form[data-form-id="' + this._FORM_ID + '"]').serializeArray(); 105 $.ajax({ 106 url: this._FORM_ACTION, 107 type: 'POST', 108 dataType: 'json', 109 data: settingsData, 110 success: function (data) { 111 _this.responseReturnData(data); 112 } 113 }); 114 }; 115 116 sendsFormResponse(response, data, customMessage) { 117 let responseMessage = (customMessage) ? customMessage : data.message; 118 let parentForm = this._SELF.closest('form[data-form-id="' + this._FORM_ID + '"]'); 119 120 let alertWrapper = parentForm.siblings('[data-alert-id="' + this._FORM_ID + '"]'); 121 if ( parentForm.find('[data-alert-id="' + this._FORM_ID + '"]').length ) { 122 alertWrapper = parentForm.find('[data-alert-id="' + this._FORM_ID + '"]'); 123 } 124 125 switch (response) { 126 case 'error': 127 alertWrapper.html(responseMessage); 128 alertWrapper.removeClass('alert-success'); 129 alertWrapper.addClass('alert-danger'); 130 alertWrapper.addClass('active'); 131 alertWrapper.removeAttr('aria-live'); 132 alertWrapper.attr('role', 'alert'); 133 if (typeof validateError === 'function') { 134 validateError(parentForm); 135 } 136 this.scrollToFormError(alertWrapper); 137 break; 138 case 'reset': 139 alertWrapper.empty(); 140 alertWrapper.removeClass('alert-success'); 141 alertWrapper.removeClass('alert-danger'); 142 alertWrapper.removeClass('active'); 143 alertWrapper.removeAttr('role'); 144 alertWrapper.removeAttr('aria-live'); 145 break; 146 default: 147 alertWrapper.html(responseMessage); 148 alertWrapper.addClass('alert-success'); 149 alertWrapper.removeClass('alert-danger'); 150 alertWrapper.addClass('active'); 151 alertWrapper.removeAttr('role'); 152 alertWrapper.attr('aria-live', 'polite'); 153 154 if( this._CALLBACK_ON_SUCCESS ) { 155 var callback = window[this._CALLBACK_ON_SUCCESS]; 156 if( typeof callback === "function" ) { 157 callback(); 158 } 159 } 160 break; 161 } 162 }; 163 164 modalCloseEvents() { 165 166 if (typeof settedModalEvent === 'undefined' || settedModalEvent === null) { 167 var settedModalEvent = settedModalEvent; 168 } else { 169 var settedModalEvent = false;
170 } 171 172 let _this = this; 173 switch (this._MODAL_VER) { 174 case 'bs-5': 175 $(document).on('hidden.bs.modal', this._SELF.closest('.modal[data-modal-id="' + _this._FORM_ID + '"]'), function () { 176 $(this).find('form[data-form-id="' + _this._FORM_ID + '"]')[0].reset(); 177 $(this).find('form[data-form-id="' + _this._FORM_ID + '"]').validationEngine('hideAll'); 178 settedModalEvent = true; 179 _this.sendsFormResponse('reset', false, false); 180 _this.formResetRecaptcha(); 181 }); 182 break; 183 case 'bs-3': 184 $(document).on('hidden.bs.modal', this._SELF.closest('.modal[data-modal-id="' + _this._FORM_ID + '"]'), function () { 185 $(this).find('form[data-form-id="' + _this._FORM_ID + '"]')[0].reset(); 186 $(this).find('form[data-form-id="' + _this._FORM_ID + '"]').validationEngine('hideAll'); 187 settedModalEvent = true; 188 _this.sendsFormResponse('reset', false, false); 189 _this.formResetRecaptcha(); 190 }); 191 break; 192 default: 193 _this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]')[0].reset(); 194 195 if ( _this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]').find('.rateit-reset').length ) { 196 _this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]').find('.rateit-reset').trigger('click'); 197 } 198 break; 199 } 200 201 }; 202 203 responseReturnData(data) { 204 let _this = this; 205 206 if (data.status === true) { 207 208 if (data.sconto_utente) { 209 // ########################################################################### 210 // ########################################################################### 211 // ########################################################################### 212 // da attivare layer per sconto tente in registrazionew 213 // ########################################################################### 214 // ########################################################################### 215 // ########################################################################### 216 } 217 218 _this.sendsFormResponse('success', data, false); 219 if (_this._NO_RESET_FORM != 1) { 220 _this.formResetFields(); 221 } 222 223 if ( _this._RELOAD_PAGE == 'success' ) { 224 if (data.admin_moderation == 0) { 225 window.location.reload(true); 226 } 227 } else if ( _this._RELOAD_PAGE == 'form_submit' ) { 228 window.location.reload(true); 229 } 230 231 if ( typeof _this._GO_TO_URL !== 'undefined' && _this._GO_TO_URL ) { 232 if ( _this._GO_TO_URL == 'registrazione_nuovo_utente' ) { 233 if ( typeof data.url !== 'undefined' && data.url ) { 234 window.location.href=data.url; 235 } 236 } else { 237 window.location.href=_this._GO_TO_URL; 238 } 239 } 240 241 } else if ( !isNaN(data.status) && data.status>0) { 242 243 _this.sendsFormResponse('success', data, false); 244 if (_this._NO_RESET_FORM != 1) { 245 _this.formResetFields(); 246 } 247 248 if ( _this._RELOAD_PAGE == 'success' ) { 249 if (data.admin_moderation == 0) { 250 window.location.reload(true); 251 } 252 } 253 254 } else if ( !isNaN(data.status) && data.status<=0) { 255 256 _this.sendsFormResponse('error', data, false); 257 258 } else { 259 260 _this.sendsFormResponse('error', data, false); 261 262 } 263 264 265 if (typeof data.html_commento !== 'undefined' && data.html_commento) { 266 let commentsWrapper = $('[data-comments-list="1"]'); 267 commentsWrapper.prepend(data.html_commento); 268 269 if ( _this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]').find('.rateit').length ) { 270 $('.rateit').rateit(); 271 } 272 273 $('html, body').animate({ scrollTop: commentsWrapper.offset().top - 250 }, 500); 274 275 } 276 277 if ( _this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]').find('.rateit-reset').length ) { 278 _this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]').find('.rateit-reset').trigger('click'); 279 } 280 281 _this.closeRecaptchaLoader(); 282 283 _this.formResetRecaptcha(); 284 285 } 286 287 openRecaptchaLoader() { 288 if ( $('body>.recaptcha-loader').length <= 0 ) { 289 let recaptchaLoaderSpinner; 290 recaptchaLoaderSpinner = '<div class="spinner-border text-light" role="status"><span class="visually-hidden">Loading...</span></div>'; 291 $('body').append('<div class="recaptcha-loader">'+ recaptchaLoaderSpinner +'</div>'); 292 $('body>.recaptcha-loader').fadeIn(500, function() { 293 $('body').addClass('recaptcha-loader-open'); 294 }); 295 } 296 } 297 closeRecaptchaLoader() { 298 setTimeout(function(){ 299 $('body').removeClass('recaptcha-loader-open'); 300 $('.recaptcha-loader').fadeOut(500, function() { 301 $('.recaptcha-loader').remove(); 302 }); 303 }, 500); 304 } 305 formResetFields() { 306 let _this = this; 307 308 if (_this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]').length ) { 309 _this._SELF.closest('form[data-form-id="' + _this._FORM_ID + '"]')[0].reset(); 310 } 311 } 312 formResetRecaptcha() { 313 let _this = this; 314 315 if ( _this._GOOGLE_RECAPTCHA_VER && _this._GOOGLE_RECAPTCHA_VER != 3 ) { 316 $('.g-recaptcha').each(function( index ) { 317 grecaptcha.reset(index); 318 }); 319 } 320 } 321 scrollToFormError(item) { 322 323 if ( !isInViewport(item[0]) ) { 324 let windowScrollTop = item.offset().top + item.outerHeight() - window.innerHeight + 50; 325 $('html, body').animate({ 326 scrollTop: windowScrollTop 327 }, 800); 328 } 329 330 function isInViewport(element) { 331 const rect = element.getBoundingClientRect(); 332 return ( 333 rect.top >= 0 && 334 rect.left >= 0 && 335 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 336 rect.right <= (window.innerWidth || document.documentElement.clientWidth) 337 ); 338 } 339 340 } 341 } 342} 343 344$(function() { 345 if ( $('.modal[data-modal-ver="bs-5"]').length ) { 346 $(document).on('hidden.bs.modal','.modal[data-modal-id][data-modal-ver="bs-5"]',function() { 347 $(this).find('form[data-form-id]')[0].reset(); 348 $(this).find('form[data-form-id]').validationEngine('hideAll'); 349 350 $('.g-recaptcha').each(function( index ) { 351 grecaptcha.reset(index); 352 }); 353 }); 354 } else if ( $('.modal[data-modal-ver="bs-3"]').length ) { 355 $(document).on('hidden.bs.modal','.modal[data-modal-id][data-modal-ver="bs-3"]',function() { 356 $(this).find('form[data-form-id]')[0].reset(); 357 $(this).find('form[data-form-id]').validationEngine('hideAll'); 358 359 $('.g-recaptcha').each(function( index ) { 360 grecaptcha.reset(index); 361 }); 362 }); 363 } 364}); 365
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.