PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.63
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.63
1.2.76 1.2.75 1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 All 176 releases
userswp / assets / js / users-wp.js

users-wp.js in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.63, at assets/js/users-wp.js

889 lines 34.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(window).on('load',function () {
2 // Enable auth modals
3 uwp_init_auth_modal();uwp_switch_reg_form_init();
4 });
5
6
7 (function( $, window, undefined ) {
8 $(document).ready(function() {
9 var showChar = uwp_localize_data.uwp_more_char_limit;
10 var ellipsestext = uwp_localize_data.uwp_more_ellipses_text;
11 var moretext = uwp_localize_data.uwp_more_text;
12 var lesstext = uwp_localize_data.uwp_less_text;
13 $('.uwp_more').each(function() {
14 var content = $.trim($(this).text());
15 var length = $( this ).data( 'maxchar' );
16 if(length > 0 ){
17 showChar = length;
18 }
19 if(content.length > showChar) {
20
21 var c = content.substr(0, showChar);
22 var h = content.substr(showChar, content.length - showChar);
23 var html = uwp_nl2br(c) + '<span class="uwp_more_ellipses">' + ellipsestext+ '&nbsp;</span><span class="uwp_more_content"><span style="display: none;">' + uwp_nl2br(h) + '</span>&nbsp;&nbsp;<a href="" class="uwp_more_link">' + moretext + '</a></span>';
24
25 $(this).html(html);
26 }
27
28 });
29
30 $(".uwp_more_link").on('click', function(){
31 if($(this).hasClass("uwp_less")) {
32 $(this).removeClass("uwp_less");
33 $(this).html(moretext);
34 } else {
35 $(this).addClass("uwp_less");
36 $(this).html(lesstext);
37 }
38 $(this).parent().prev().toggle();
39 $(this).prev().toggle();
40 return false;
41 });
42
43 // set the current user selection if set
44 if (typeof(Storage) !== "undefined") {
45 var $storage_key = "uwp_list_view";
46 var $list = jQuery('.uwp-users-loop > .row');
47 if (!$list.length) {
48 $list = jQuery('.uwp-profile-cpt-loop > .row');
49 $storage_key = "uwp_cpt_list_view";
50 }
51 var $noStore = false;
52 var uwp_list_view = localStorage.getItem($storage_key);
53 setTimeout(function () {
54 if (!uwp_list_view) {
55 $noStore = true;
56 if ($list.hasClass('row-cols-md-0')) {
57 uwp_list_view = 0;
58 } else if ($list.hasClass('row-cols-md-1')) {
59 uwp_list_view = 1;
60 } else if ($list.hasClass('row-cols-md-2')) {
61 uwp_list_view = 2;
62 } else if ($list.hasClass('row-cols-md-3')) {
63 uwp_list_view = 3;
64 } else if ($list.hasClass('row-cols-md-4')) {
65 uwp_list_view = 4;
66 } else if ($list.hasClass('row-cols-md-5')) {
67 uwp_list_view = 5;
68 } else {
69 uwp_list_view = 3;
70 }
71 }
72 uwp_list_view_select(uwp_list_view, $noStore);
73 }, 10); // we need to give it a very short time so the page loads the actual html
74 }
75 });
76 }( jQuery, window ));
77
78
79 (function( $, window, undefined ) {
80
81 var uwp_popup_type;
82
83 $(document).ready( function() {
84 $( '.uwp-profile-modal-form-trigger' ).on( 'click', function( event ) {
85 event.preventDefault();
86
87 uwp_popup_type = $( this ).data( 'type' );
88
89 // do something with the file here
90 var data = {
91 'action': 'uwp_ajax_image_crop_popup_form',
92 'type': uwp_popup_type
93 };
94
95 var container = jQuery('#uwp-popup-modal-wrap');
96 container.show();
97
98 jQuery.post(uwp_localize_data.ajaxurl, data, function(response) {
99 $(document.body).append("<div id='uwp-modal-backdrop'></div>");
100 container.replaceWith(response);
101 });
102 });
103 });
104
105 $(document).ready(function() {
106 $( '.uwp_upload_file_remove' ).on( 'click', function( event ) {
107 event.preventDefault();
108
109 var $this = $(this);
110 var htmlvar = $this.data( 'htmlvar' );
111 var uid = $this.data( 'uid' );
112
113 var data = {
114 'action': 'uwp_upload_file_remove',
115 'htmlvar': htmlvar,
116 'uid': uid,
117 'security': uwp_localize_data.basicNonce
118 };
119
120 if ($this.closest("form").find('.uwp-field-error').length) {
121 $this.closest("form").find('.uwp-field-error').remove();
122 }
123
124 jQuery.ajax({
125 url: uwp_localize_data.ajaxurl,
126 type: 'POST',
127 data: data,
128 dataType: 'json'
129 }).done(function(res, textStatus, jqXHR) {
130 if (res && typeof res == 'object') {
131 if (res.success) {
132 $("#"+htmlvar+"_row").find(".uwp_file_preview_wrap").remove();
133 $("#"+htmlvar).closest("td").find(".uwp_file_preview_wrap").remove();
134 if($('input[name='+htmlvar+']').data( 'is-required' )){
135 $('input[name='+htmlvar+']').prop('required',true);
136 }
137 } else if (res.data && typeof res.data == 'object' && res.data.message) {
138 $this.parent(".uwp_file_preview_wrap").append('<div class="uwp-field-error">' + res.data.message + '</div>');
139 }
140 }
141 });
142 });
143 });
144
145 }( jQuery, window ));
146
147 (function( $, window, undefined ) {
148 $(document).ready(function() {
149 $( '#uwp_layout' ).on( 'change', function() {
150 var layout = $(this).val();
151 var container = $('#uwp_user_items_layout');
152 container.removeClass();
153 if (layout == 'list') {
154 container.addClass('uwp-users-list-wrap uwp_listview');
155 } else if (layout == '2col') {
156 container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_2col');
157 } else if (layout == '3col') {
158 container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_3col');
159 } else if (layout == '4col') {
160 container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_4col');
161 } else if (layout == '5col') {
162 container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_5col');
163 } else {
164 container.addClass('uwp-users-list-wrap uwp_listview');
165 }
166 });
167
168 jQuery( document ).ready(function($) {
169 $( '#uwp_login_modal form.uwp-login-form' ).on( 'submit', function( e ) {
170 e.preventDefault();
171 uwp_ajax_login(this);
172 });
173 });
174
175 function uwp_ajax_login($this) {
176
177 $('#uwp_login_modal .uwp-login-ajax-notice').remove();
178
179 var data = jQuery($this).serialize()+ "&action=uwp_ajax_login";
180
181 jQuery.post(uwp_localize_data.ajaxurl, data, function(response) {
182 response = jQuery.parseJSON(response);
183
184 if(response.error){
185 $('#uwp_login_modal form.uwp-login-form').before(response.message);
186 } else {
187 $('#uwp_login_modal form.uwp-login-form').before(response.message);
188 setTimeout(function(){location.reload()}, 1200)
189 }
190
191 });
192 }
193
194 });
195 }( jQuery, window ));
196
197 function uwp_nl2br(str, is_xhtml) {
198 var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
199 return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
200 }
201
202 function uwp_list_view_select($val, $noStore) {
203
204 var $storage_key = "uwp_list_view";
205 var $list = jQuery('.uwp-users-loop > .row');
206 if (!$list.length) {
207 $list = jQuery('.uwp-profile-cpt-loop > .row');
208 $storage_key = "uwp_cpt_list_view";
209 }
210
211 var $listSelect = jQuery('.uwp-list-view-select');
212 if ($val == 0) {
213 $list.removeClass('row-cols-sm-2 row-cols-md-2 row-cols-md-3 row-cols-md-4 row-cols-md-5').addClass('row-cols-md-0');
214 $listSelect.find('button').removeClass('active');
215 $listSelect.find('button.uwp-list-view-select-list').addClass('active');
216 } else {
217 $listSelect.find('button').removeClass('active');
218 $listSelect.find('button.uwp-list-view-select-grid').addClass('active');
219 $listSelect.find('button[data-gridview="' + $val + '"]').addClass('active');
220 $list.removeClass('row-cols-md-0 row-cols-md-2 row-cols-md-3 row-cols-md-4 row-cols-md-5').addClass('row-cols-sm-2 row-cols-md-' + $val);
221 }
222
223 // only store if it was a user action
224 if (!$noStore) {
225 // store the user selection
226 localStorage.setItem($storage_key, $val);
227 }
228 }
229
230 function uwp_profile_image_change(type){
231 // remove it first
232 jQuery('.uwp-profile-image-change-modal').remove();
233
234 var $modal = '<div class="modal fade uwp-profile-image-change-modal bsui" tabindex="-1" role="dialog" aria-labelledby="uwp-profile-modal-title" aria-hidden="true"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="uwp-profile-modal-title"></h5></div><div class="modal-body text-center"><i class="fas fa-circle-notch fa-spin fa-3x"></i></div></div></div></div>';
235 jQuery('body').append($modal);
236
237 // jQuery('.uwp-profile-image-change-modal').modal({
238 // backdrop: 'static'
239 // });
240
241 if ( window.bootstrap && window.bootstrap.Modal ) {
242 var authModal = new window.bootstrap.Modal(document.querySelector('.uwp-profile-image-change-modal'));
243 authModal.show();
244 } else {
245 jQuery('.uwp-profile-image-change-modal').modal({
246 backdrop: 'static'
247 });
248 }
249
250 // do something with the file here
251 var data = {
252 'action': 'uwp_ajax_image_crop_popup_form',
253 'type': type,
254 'style': 'bootstrap'
255 };
256
257 jQuery.post(uwp_localize_data.ajaxurl, data, function(response) {
258 jQuery('.uwp-profile-image-change-modal .modal-content').html(response);
259 });
260 }
261
262 function uwp_init_auth_modal(){
263
264 // open login form
265 if(uwp_localize_data.login_modal) {
266 jQuery('.users-wp-login-nav a, .uwp-login-link, [data-uwp-link="login"]').off('click');
267 jQuery('.users-wp-login-nav a, .uwp-login-link, [data-uwp-link="login"]').on('click', function (e) {
268 uwp_cancelBubble(e);
269 uwp_modal_login_form();
270 return false;
271 });
272 }
273
274 // open the register form
275 if(uwp_localize_data.register_modal) {
276 jQuery('.users-wp-register-nav a, .uwp-register-link, [data-uwp-link="register"]').off('click');
277 jQuery('.users-wp-register-nav a, .uwp-register-link, [data-uwp-link="register"]').on('click', function (e) {
278 uwp_cancelBubble(e);
279 uwp_modal_register_form();
280 return false;
281 });
282 }
283
284 // open the forgot password form
285 if(uwp_localize_data.forgot_modal) {
286 jQuery('.users-wp-forgot-nav a, .uwp-forgot-password-link, [data-uwp-link="forgot-password"]').off('click');
287 jQuery('.users-wp-forgot-nav a, .uwp-forgot-password-link, [data-uwp-link="forgot-password"]').on('click', function (e) {
288 uwp_cancelBubble(e);
289 uwp_modal_forgot_password_form();
290 return false;
291 });
292 }
293 }
294
295 function uwp_modal_loading(inputs) {
296 $input_single = '<span class="badge badge-pill badge-light p-3 mt-3 w-100 bg-loading">&nbsp;</span>';
297 $inputs = inputs ? $input_single.repeat(inputs) : $input_single;
298
299 var $modal_content = '<div class="modal-header">' +
300 '<span class="badge badge-pill badge-light p-0 mt-2 w-25 bg-loading">&nbsp;</span></div>' +
301 '<div class="modal-body text-center">' + $inputs + '</div>';
302 var $modal = '<div class="modal fade uwp-auth-modal bsui" tabindex="-1" role="dialog" aria-labelledby="uwp-profile-modal-title" aria-hidden="true">' +
303 '<div class="modal-dialog modal-dialog-centered">' +
304 '<div class="modal-content">' +
305 $modal_content +
306 '</div></div></div>';
307
308 if (!jQuery('.uwp-auth-modal').length) {
309 jQuery('body').append($modal);
310 } else {
311 jQuery('.uwp-auth-modal .modal-content').html($modal_content);
312 }
313
314 jQuery('.modal-backdrop').remove();
315
316 if (window.bootstrap && window.bootstrap.Modal) {
317 var authModal = new window.bootstrap.Modal(document.querySelector('.uwp-auth-modal'));
318 authModal.show();
319 } else {
320 jQuery('.uwp-auth-modal').modal();
321 }
322 }
323
324 /**
325 * Get the login form via ajax and load it in a modal.
326 */
327 function uwp_modal_login_form(){
328 var data = {
329 'action': 'uwp_ajax_login_form' // deliberately no nonce for caching reasons
330 };
331 jQuery.ajax({
332 type: "POST",
333 url: uwp_localize_data.ajaxurl,
334 data: data,
335 beforeSend: function() {
336 uwp_modal_loading(4);
337 },
338 success: function(data) {
339 if(data.success){
340 jQuery('.uwp-auth-modal .modal-content').html(data.data);
341 setTimeout(function(){jQuery('.uwp-auth-modal .modal-content input:visible:enabled:first').focus().unbind('focus');}, 300); // set focus on the first input after load animation
342
343 // process login form
344 jQuery( '.uwp-auth-modal .modal-content form.uwp-login-form' ).on( 'submit', function( e ) {
345 e.preventDefault(e);
346 uwp_modal_login_form_process();
347 });
348 }
349 uwp_init_auth_modal();
350 }
351 });
352 }
353
354 /**
355 * Check if we are waiting on a recaptcha callback.
356 *
357 * @param $form
358 * @returns {boolean}
359 */
360 function uwp_maybe_check_recaptcha($form){
361 if(typeof uwp_recaptcha_loops === 'undefined' || !uwp_recaptcha_loops){uwp_recaptcha_loops = 1;}
362 if(jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').length && jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').val() == ''){
363 setTimeout(function(){
364 // remove the original spinner
365 jQuery('.uwp-auth-modal .modal-content button[type="submit"] i.fa-spin,.uwp-auth-modal .modal-content button[type="submit"] svg.fa-spin').remove();
366
367 // bail and add warning if still no recaptcha after 5 loops`
368 if(uwp_recaptcha_loops>=6){
369 jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').prop('disabled', false);
370 jQuery('.uwp-auth-modal .modal-content .uwp_register_submit').prop('disabled', false);
371 jQuery('.uwp-auth-modal .modal-content .uwp_forgot_submit').prop('disabled', false);
372 jQuery('.uwp-auth-modal .modal-content .uwp-captcha-render').addClass("alert alert-danger");
373
374 // maybe show general error
375 if(jQuery('.uwp-auth-modal .modal-content .modal-error').html()==''){
376 jQuery('.uwp-auth-modal .modal-content .modal-error').html("<div class='alert alert-danger'>"+uwp_localize_data.error_retry+"</div>");
377 }
378
379 return false;
380 }
381
382 if($form=='login'){
383 uwp_modal_login_form_process();
384 }else if($form == 'register'){
385 uwp_modal_register_form_process();
386 }else if($form == 'forgot'){
387 uwp_modal_forgot_password_form_process();
388 }
389 }, 500); // 6 x 500 = 3 seconds we wait for response before showing error.
390 uwp_recaptcha_loops++;
391 return false;
392 }
393 uwp_recaptcha_loops = 0;
394 return true;
395 }
396
397 /**
398 * Maybe reset the recaptcha on ajax submit fail.
399 */
400 function uwp_maybe_reset_recaptcha() {
401 if( jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').length ){
402 var id = jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').attr('id');
403 uwp_reset_captcha(id);
404 }
405
406 document.dispatchEvent(new Event('ayecode_reset_captcha'));
407 }
408
409 /**
410 * Submit the login form via ajax.
411 */
412 function uwp_modal_login_form_process(){
413 var data = jQuery(".modal-content form.uwp-login-form").serialize() + '&action=uwp_ajax_login';
414 $button_text = jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html();
415 jQuery.ajax({
416 type: "POST",
417 url: uwp_localize_data.ajaxurl,
418 data: data,
419 beforeSend: function() {
420 jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit
421 jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages
422 return uwp_maybe_check_recaptcha('login');
423 },
424 success: function(data) {
425 if(data.success==true){
426 jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html($button_text).prop('disabled', true);// remove spinner
427 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message);
428 // Show success message for 1 second before redirecting.
429 if(data.data.is_2fa){
430 jQuery(".modal-content form.uwp-login-form").replaceWith(data.data.html);
431
432 jQuery( '.uwp-auth-modal .modal-content form.validate_2fa_form' ).on( 'submit', function( e ) {
433 e.preventDefault(e);
434 uwp_modal_login_form_2fa_process('form.validate_2fa_form', '');
435 });
436
437 jQuery( '.uwp-auth-modal .modal-content form.validate_2fa_backup_codes_form' ).on( 'submit', function( e ) {
438 e.preventDefault(e);
439 uwp_modal_login_form_2fa_process('form.validate_2fa_backup_codes_form', '');
440 });
441
442 jQuery( '.uwp-auth-modal .modal-content .uwp-2fa-email-resend' ).on( 'click', function( e ) {
443 e.preventDefault(e);
444 uwp_modal_login_form_2fa_process('form.validate_2fa_form', '&wp-2fa-email-code-resend=1');
445 });
446 } else {
447 if(data.data.redirect){
448 setTimeout(function(){
449 location.href = data.data.redirect;
450 }, 1000);
451 } else {
452 setTimeout(function(){
453 location.reload();
454 }, 1000);
455 }
456 }
457
458 }else if(data.success===false){
459 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message);
460 jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html($button_text).prop('disabled', false);// enable submit
461 uwp_maybe_reset_recaptcha();
462 }
463 uwp_init_auth_modal();
464 }
465 });
466 }
467
468 function uwp_modal_login_form_2fa_process(type, fields){
469 var data = jQuery(".modal-content " + type).serialize() + '&action=uwp_ajax_login_process_2fa'+fields;
470 $button = jQuery('.uwp-auth-modal .modal-content '+type).find('.uwp-2fa-submit');
471 $button_text = $button.html();
472 jQuery.ajax({
473 type: "POST",
474 url: uwp_localize_data.ajaxurl,
475 data: data,
476 beforeSend: function() {
477 $button.html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit
478 jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages
479 },
480 success: function(data) {
481 if(data.success==true){
482 $button.html($button_text).prop('disabled', true);// remove spinner
483 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message);
484 // Show success message for 1 second before redirecting.
485 if(data.data.redirect){
486 setTimeout(function(){
487 location.href = data.data.redirect;
488 }, 1000);
489 } else {
490 setTimeout(function(){
491 location.reload();
492 }, 1000);
493 }
494
495 }else if(data.success===false){
496 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message);
497 $button.html($button_text).prop('disabled', false);// enable submit
498 }
499 uwp_init_auth_modal();
500 }
501 });
502 }
503
504
505 /**
506 * Get the register form via ajax and load it in a modal.
507 */
508 function uwp_modal_register_form(form_id){
509 var data = {
510 'action': 'uwp_ajax_register_form', // deliberately no nonce for caching reasons
511 'form_id': form_id,
512 };
513 jQuery.ajax({
514 type: "POST",
515 url: uwp_localize_data.ajaxurl,
516 data: data,
517 beforeSend: function() {
518 uwp_modal_loading(6);
519 },
520 success: function(data) {
521 if(data.success){
522 jQuery('.uwp-auth-modal .modal-content').html(data.data);
523 setTimeout(function(){jQuery('.uwp-auth-modal .modal-content input:visible:enabled:first').focus().unbind('focus');}, 300); // set focus on the first input after load animation
524
525 // process register form
526 jQuery(".uwp-auth-modal .modal-content form.uwp-registration-form").submit(function(e){
527 e.preventDefault(e);
528 uwp_modal_register_form_process();
529 });
530 }
531 uwp_init_auth_modal();aui_init_select2();uwp_switch_reg_form_init();aui_init();
532 }
533 });
534 }
535
536 /**
537 * Load register form via AJAX for normal (non-modal) forms.
538 */
539 function uwp_load_register_form(form_id, form, activeElement) {
540 var data = {
541 'action': 'uwp_ajax_register_form',
542 'form_id': form_id,
543 };
544
545 jQuery.ajax({
546 type: "POST",
547 url: uwp_localize_data.ajaxurl,
548 data: data,
549 beforeSend: function() {
550 jQuery(document).trigger('uwp_form_loading', { form_id, form });
551
552 if (activeElement) {
553 activeElement.addClass('active');
554 }
555 var $inputDivs = form.find('input, select, textarea').not('#uwp-form-type-select');
556 var $placeholder = '<div class="badge badge-pill badge-light p-3 mt-3 w-100 bg-loading">&nbsp;</div>';
557
558 // Replace each input's parent div with the placeholder
559 $inputDivs.each(function() {
560 jQuery(this).replaceWith($placeholder);
561 });
562
563 // Remove everything else in the form except the placeholders
564 form.children().not('.badge, #uwp-form-select').remove();
565 },
566 success: function(data) {
567 if(data.success){
568 var $returnedForm = jQuery(data.data).find('form');
569 var $formSelector = form.find('#uwp-form-select');
570
571 form.html($returnedForm.html());
572
573 if (!$returnedForm.find('#uwp-form-select').length && !$returnedForm.find('#uwp-form-select-ajax').length && $formSelector) {
574 form.prepend($formSelector);
575 }
576
577 form.find('#uwp-form-select-ajax').attr('id', 'uwp-form-select');
578
579 jQuery(document).trigger('uwp_form_loaded', { form_id, form, html: data.data });
580 }
581
582 uwp_init_auth_modal();
583 aui_init_select2();
584 uwp_switch_reg_form_init();
585 }
586 });
587 }
588
589 function uwp_switch_reg_form_init() {
590 // Handle button clicks for lightbox (AJAX modal)
591 jQuery( '#uwp-form-select-ajax a' ).off( 'click.uwpSwitchRegForm' ).on( 'click.uwpSwitchRegForm', function( e ) {
592 e.preventDefault(e);
593 var form_id = jQuery(this).attr('data-form_id');
594 uwp_modal_register_form(form_id);
595 });
596
597 // Handle select dropdown for lightbox (AJAX modal)
598 jQuery( '#uwp-form-select-ajax select#uwp-form-type-select' ).off( 'change.uwpSwitchRegForm' ).on( 'change.uwpSwitchRegForm', function( e ) {
599 var form_id = jQuery(this).find('option:selected').attr('data-form_id');
600 uwp_modal_register_form(form_id);
601 });
602
603 // Handle button clicks for normal forms
604 jQuery( '#uwp-form-select a' ).off( 'click.uwpSwitchRegForm' ).on( 'click.uwpSwitchRegForm', function( e ) {
605 e.preventDefault(e);
606 var self = jQuery(this);
607 var form_id = self.attr('data-form_id');
608 var form = self.parents('form');
609 jQuery('#uwp-form-select a').removeClass('active');
610
611 uwp_load_register_form(form_id, form, self);
612 });
613
614 // Handle select dropdown for normal forms
615 jQuery( '#uwp-form-select select#uwp-form-type-select' ).off( 'change.uwpSwitchRegForm' ).on( 'change.uwpSwitchRegForm', function( e ) {
616 var self = jQuery(this);
617 var form_id = self.find('option:selected').attr('data-form_id');
618 var form = self.parents('form');
619
620 uwp_load_register_form(form_id, form);
621 });
622 }
623
624 /**
625 * Submit the login form via ajax.
626 */
627 function uwp_modal_register_form_process(){
628 var data = jQuery(".modal-content form.uwp-registration-form").serialize() + '&action=uwp_ajax_register';
629 $button = jQuery('.uwp-auth-modal .modal-content .uwp_register_submit');
630 $button_text = $button.html();
631 jQuery.ajax({
632 type: "POST",
633 url: uwp_localize_data.ajaxurl,
634 data: data,
635 beforeSend: function() {
636 $button.html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit
637 jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages
638 return uwp_maybe_check_recaptcha('register');
639 },
640 success: function(data) {
641 if(data.success){
642 $button.html($button_text).prop('disabled', true);// remove spinner
643
644 if(data.data.message){
645 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message);
646 jQuery(".modal-content form.uwp-registration-form").trigger('reset');
647 setTimeout(function(){
648 if(data.data.redirect){
649 window.location = data.data.redirect;
650 }
651 }, 3000);
652 }else{
653 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message);
654 }
655
656 }else if(data.success===false){
657 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message);
658 $button.html($button_text).prop('disabled', false);// enable submit
659 uwp_maybe_reset_recaptcha();
660 }
661 uwp_init_auth_modal();aui_init_select2();uwp_switch_reg_form_init();
662 }
663 });
664 }
665
666
667 /**
668 * Get the forgot password form via ajax and load it in a modal.
669 */
670 function uwp_modal_forgot_password_form(){
671 var data = {
672 'action': 'uwp_ajax_forgot_password_form' // deliberately no nonce for caching reasons
673 };
674 jQuery.ajax({
675 type: "POST",
676 url: uwp_localize_data.ajaxurl,
677 data: data,
678 beforeSend: function() {
679 uwp_modal_loading(2);
680 },
681 success: function(data) {
682 if(data.success){
683 jQuery('.uwp-auth-modal .modal-content').html(data.data);
684 setTimeout(function(){jQuery('.uwp-auth-modal .modal-content input:visible:enabled:first').focus().unbind('focus');}, 300); // set focus on the first input after load animation
685
686 // process login form
687 jQuery( '.uwp-auth-modal .modal-content form.uwp-forgot-form' ).on( 'submit', function( e ) {
688 e.preventDefault(e);
689 uwp_modal_forgot_password_form_process();
690 });
691 }
692 uwp_init_auth_modal();
693 }
694 });
695 }
696
697 /**
698 * Submit the forgot password form via ajax.
699 */
700 function uwp_modal_forgot_password_form_process(){
701 var data = jQuery(".modal-content form.uwp-forgot-form").serialize() + '&action=uwp_ajax_forgot_password';
702 $button = jQuery('.uwp-auth-modal .modal-content .uwp_forgot_submit');
703 $button_text = $button.html();
704 jQuery.ajax({
705 type: "POST",
706 url: uwp_localize_data.ajaxurl,
707 data: data,
708 beforeSend: function() {
709 $button.html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit
710 jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages
711 return uwp_maybe_check_recaptcha('forgot');
712 },
713 success: function(data) {
714 if(data.success){
715 $button.html($button_text).prop('disabled', true);// remove spinner
716 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data);
717 setTimeout(function(){
718 jQuery('.uwp-auth-modal').modal('hide');
719 }, 2000);
720 }else if(data.success===false){
721 jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data);
722 $button.html($button_text).prop('disabled', false);// enable submit
723 uwp_maybe_reset_recaptcha();
724 }
725 uwp_init_auth_modal();
726 }
727 });
728 }
729
730 /**
731 * A password strength indicator.
732 *
733 * @param $pass1
734 * @param $pass2
735 * @param $strengthResult
736 * @param $submitButton
737 * @param blacklistArray
738 * @returns {*|number}
739 */
740 function uwp_checkPasswordStrength( $pass1,
741 $pass2,
742 $strengthResult,
743 $submitButton,
744 blacklistArray ) {
745 var pass1 = $pass1.val();
746 var pass2 = $pass2.val();
747
748 // maybe insert
749 if(!jQuery('#uwp-password-strength').length && pass1){
750 if($pass2.length){
751 $container = $pass2.closest('.uwp-password-wrap');
752 }else{
753 $container = $pass1.closest('.uwp-password-wrap');
754 }
755 $container.append( '<div class="progress mt-1"><div id="uwp-password-strength" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div></div>' );
756 $strengthResult = jQuery('#uwp-password-strength');
757 }else if(!pass1 && !pass2){
758 $strengthResult.parent().remove();
759 }
760
761 if ( parseInt(uwp_localize_data.uwp_pass_strength) > 0 ) {
762 $submitButton.attr('disabled', 'disabled');
763 }
764
765 // Reset the form & meter
766 $strengthResult.removeClass( 'short bad good strong bg-warning bg-success bg-danger' );
767
768 // Extend our blacklist array with those from the inputs & site data
769 blacklistArray = blacklistArray.concat( wp.passwordStrength.userInputDisallowedList() );
770
771 // Get the password strength
772 var strength = wp.passwordStrength.meter( pass1, blacklistArray, pass2 );
773
774 // Add the strength meter results
775 switch ( strength ) {
776
777 case -1:
778 $strengthResult.addClass( 'short bg-danger' ).html( pwsL10n.unknown );
779 break;
780
781 case 2:
782 $strengthResult.addClass( 'bad bg-danger' ).html( pwsL10n.bad ).width('50%');
783 break;
784
785 case 3:
786 $strengthResult.addClass( 'good bg-warning' ).html( pwsL10n.good ).width('75%');
787 break;
788
789 case 4:
790 $strengthResult.addClass( 'strong bg-success' ).html( pwsL10n.strong ).width('100%');
791 break;
792
793 case 5:
794 $strengthResult.addClass( 'short bg-danger' ).html( pwsL10n.mismatch ).width('25%');
795 break;
796
797 default:
798 $strengthResult.addClass( 'short bg-danger' ).html( pwsL10n.short ).width('25%');
799
800 }
801
802 // set the status of the submit button
803 if ( parseInt(uwp_localize_data.uwp_pass_strength) > 0) {
804 if($pass2.length){
805 $container = $pass2.closest('.uwp-password-wrap');
806 }else{
807 $container = $pass1.closest('.uwp-password-wrap');
808 }
809 $container.find('small').remove();
810
811 if(4 == parseInt(uwp_localize_data.uwp_pass_strength) && strength === 4){
812 $submitButton.removeAttr( 'disabled' );
813 } else if(3 == parseInt(uwp_localize_data.uwp_pass_strength) && (strength === 3 || strength === 4)){
814 $submitButton.removeAttr( 'disabled' );
815 } else {
816 $container.append("<small class='text-danger'>"+uwp_localize_data.uwp_strong_pass_msg+"</small>");
817 }
818 }
819
820 return strength;
821 }
822
823 /**
824 * Prevent onclick affecting parent elements.
825 *
826 * @param e
827 */
828 function uwp_cancelBubble(e){
829 var evt = e ? e:window.event;
830 if (evt.stopPropagation) evt.stopPropagation();
831 if (evt.cancelBubble!=null) evt.cancelBubble = true;
832 }
833
834 function uwp_gd_delete_post($post_id){
835 var message = geodir_params.my_place_listing_del;
836 if (confirm(message)) {
837
838 jQuery.ajax({
839 url: uwp_localize_data.ajaxurl,
840 type: 'POST',
841 dataType: 'json',
842 data: {
843 action: 'geodir_user_delete_post',
844 security: geodir_params.basic_nonce,
845 post_id: $post_id
846 },
847 timeout: 20000,
848 success: function(data) {
849
850 if(data.success){
851 var $modal_content = '<div class="alert alert-success m-0"><i class="fas fa-check-circle"></i> '+ data.data.message +'</div>';
852 }else{
853 var $modal_content = '<div class="alert alert-danger m-0"><i class="fas fa-exclamation-circle"></i> '+ data.data.message +'</div>';
854 }
855
856 var $modal = '<div class="modal fade uwp-gd-modal bsui" tabindex="-1" role="dialog" aria-labelledby="uwp-gd-modal-title" aria-hidden="true">' +
857 '<div class="modal-dialog modal-dialog-centered">' +
858 '<div class="modal-content">' +
859 $modal_content +
860 '</div></div></div>';
861
862 if(!jQuery('.uwp-gd-modal').length){
863 jQuery('body').append($modal);
864 }else{
865 jQuery('.uwp-gd-modal .modal-content').html($modal_content);
866 }
867
868 // jQuery('.uwp-gd-modal').modal();
869
870 if ( window.bootstrap && window.bootstrap.Modal ) {
871 var authModal = new window.bootstrap.Modal(document.querySelector('.uwp-gd-modal'));
872 authModal.show();
873 } else {
874 jQuery('.uwp-gd-modal').modal();
875 }
876
877 if(data.success){
878 setTimeout(function() {
879 location.reload();
880 }, 3000);
881 }
882 }
883 });
884
885 return true;
886 } else {
887 return false;
888 }
889 }