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