| 1 |
;(function($, window) { |
| 2 |
|
| 3 |
$.fn.listautowidth = function() { |
| 4 |
return this.each(function() { |
| 5 |
var w = $(this).width(); |
| 6 |
var liw = w / $(this).children('li').length; |
| 7 |
$(this).children('li').each(function(){ |
| 8 |
var s = $(this).outerWidth(true)-$(this).width(); |
| 9 |
$(this).width(liw-s); |
| 10 |
}); |
| 11 |
}); |
| 12 |
}; |
| 13 |
$.fn.extend({ |
| 14 |
/** |
| 15 |
* Custom jQuery serialize wrapper. |
| 16 |
* |
| 17 |
* When WordPress 5.6 increased the jQuery version to 3.5.1, the serialize function changed. Instead of |
| 18 |
* sending spaces as "+", they are sent as "%20". This wrapper is for backwards compatibility. |
| 19 |
* |
| 20 |
* @todo This function is duplicated in both the frontend and backend. Need to have the code live in |
| 21 |
* just one location. |
| 22 |
* |
| 23 |
* @since 1.6.7 |
| 24 |
*/ |
| 25 |
weSerialize: function() { |
| 26 |
return $( this ).serialize().replaceAll( '%20', '+' ); |
| 27 |
}, |
| 28 |
}); |
| 29 |
window.WP_User_Frontend = { |
| 30 |
|
| 31 |
init: function() { |
| 32 |
|
| 33 |
//enable multistep |
| 34 |
this.enableMultistep(this); |
| 35 |
|
| 36 |
// clone and remove repeated field |
| 37 |
$('.wpuf-form').on('click', 'img.wpuf-clone-field', this.cloneField); |
| 38 |
$('.wpuf-form').on('click', 'img.wpuf-remove-field', this.removeField); |
| 39 |
$('.wpuf-form').on('click', 'a.wpuf-delete-avatar', this.deleteAvatar); |
| 40 |
$('.wpuf-form').on('click', 'a#wpuf-post-draft', this.draftPost); |
| 41 |
$('.wpuf-form').on('click', 'button#wpuf-account-update-profile', this.account_update_profile); |
| 42 |
|
| 43 |
$('.wpuf-form-add').on('submit', this.formSubmit); |
| 44 |
$('form#post').on('submit', this.adminPostSubmit); |
| 45 |
// $( '.wpuf-form').on('keyup', '#pass1', this.check_pass_strength ); |
| 46 |
|
| 47 |
// refresh pluploads on each step change (multistep form) |
| 48 |
$('.wpuf-form').on('step-change-fieldset', function(event, number, step) { |
| 49 |
if ( wpuf_plupload_items.length ) { |
| 50 |
for (var i = wpuf_plupload_items.length - 1; i >= 0; i--) { |
| 51 |
wpuf_plupload_items[i].refresh(); |
| 52 |
} |
| 53 |
} |
| 54 |
if ( wpuf_map_items.length ) { |
| 55 |
for (var i = wpuf_map_items.length - 1; i >= 0; i--) { |
| 56 |
google.maps.event.trigger(wpuf_map_items[i].map, 'resize'); |
| 57 |
wpuf_map_items[i].map.setCenter(wpuf_map_items[i].center); |
| 58 |
} |
| 59 |
} |
| 60 |
}); |
| 61 |
|
| 62 |
this.ajaxCategory(); |
| 63 |
// image insert |
| 64 |
// this.insertImage(); |
| 65 |
|
| 66 |
//comfirmation alert for canceling subscription |
| 67 |
$( ':submit[name="wpuf_user_subscription_cancel"]').click(function(e){ |
| 68 |
e.preventDefault(); |
| 69 |
|
| 70 |
swal({ |
| 71 |
text: wpuf_frontend.cancelSubMsg, |
| 72 |
type: 'warning', |
| 73 |
showCancelButton: true, |
| 74 |
confirmButtonColor: '#d54e21', |
| 75 |
confirmButtonText: wpuf_frontend.delete_it, |
| 76 |
cancelButtonText: wpuf_frontend.cancel_it, |
| 77 |
confirmButtonClass: 'btn btn-success', |
| 78 |
cancelButtonClass: 'btn btn-danger', |
| 79 |
}).then(function ( isConfirmed ) { |
| 80 |
if ( !isConfirmed ) { |
| 81 |
return false; |
| 82 |
} |
| 83 |
$('#wpuf_cancel_subscription').submit(); |
| 84 |
}); |
| 85 |
}); |
| 86 |
}, |
| 87 |
|
| 88 |
check_pass_strength : function() { |
| 89 |
var pass1 = $('#pass1').val(), strength; |
| 90 |
|
| 91 |
$('#pass-strength-result').show(); |
| 92 |
|
| 93 |
$('#pass-strength-result').removeClass('short bad good strong'); |
| 94 |
if ( ! pass1 ) { |
| 95 |
$('#pass-strength-result').html( ' ' ); |
| 96 |
$('#pass-strength-result').hide(); |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
if ( typeof wp.passwordStrength != 'undefined' ) { |
| 101 |
|
| 102 |
strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); |
| 103 |
|
| 104 |
switch ( strength ) { |
| 105 |
case 2: |
| 106 |
$('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); |
| 107 |
break; |
| 108 |
case 3: |
| 109 |
$('#pass-strength-result').addClass('good').html( pwsL10n.good ); |
| 110 |
break; |
| 111 |
case 4: |
| 112 |
$('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); |
| 113 |
break; |
| 114 |
case 5: |
| 115 |
$('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); |
| 116 |
break; |
| 117 |
default: |
| 118 |
$('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); |
| 119 |
} |
| 120 |
|
| 121 |
} |
| 122 |
}, |
| 123 |
|
| 124 |
enableMultistep: function(o) { |
| 125 |
|
| 126 |
var js_obj = this; |
| 127 |
var step_number = 0; |
| 128 |
var progressbar_type = $(':hidden[name="wpuf_multistep_type"]').val(); |
| 129 |
|
| 130 |
if ( progressbar_type == null ) { |
| 131 |
return; |
| 132 |
} |
| 133 |
|
| 134 |
// first fieldset doesn't have prev button, |
| 135 |
// last fieldset doesn't have next button |
| 136 |
$('fieldset.wpuf-multistep-fieldset').find('.wpuf-multistep-prev-btn').first().remove(); |
| 137 |
$('fieldset.wpuf-multistep-fieldset').find('.wpuf-multistep-next-btn').last().remove(); |
| 138 |
|
| 139 |
// at first first fieldset will be shown, and others will be hidden |
| 140 |
$('.wpuf-form fieldset').removeClass('field-active').first().addClass('field-active'); |
| 141 |
|
| 142 |
if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) { |
| 143 |
|
| 144 |
var firstLegend = $('fieldset.wpuf-multistep-fieldset legend').first(); |
| 145 |
$('.wpuf-multistep-progressbar').html('<div class="wpuf-progress-percentage"></div>' ); |
| 146 |
|
| 147 |
var progressbar = $( ".wpuf-multistep-progressbar" ), |
| 148 |
progressLabel = $( ".wpuf-progress-percentage" ); |
| 149 |
|
| 150 |
$( ".wpuf-multistep-progressbar" ).progressbar({ |
| 151 |
change: function() { |
| 152 |
progressLabel.text( progressbar.progressbar( "value" ) + "%" ); |
| 153 |
} |
| 154 |
}); |
| 155 |
|
| 156 |
$('.wpuf-multistep-fieldset legend').hide(); |
| 157 |
|
| 158 |
} else { |
| 159 |
$('.wpuf-form').each(function() { |
| 160 |
var this_obj = $(this); |
| 161 |
var progressbar = $('.wpuf-multistep-progressbar', this_obj); |
| 162 |
var nav = ''; |
| 163 |
|
| 164 |
progressbar.addClass('wizard-steps'); |
| 165 |
nav += '<ul class="wpuf-step-wizard">'; |
| 166 |
|
| 167 |
$('.wpuf-multistep-fieldset', this).each(function(){ |
| 168 |
nav += '<li>' + $.trim( $('legend', this).text() ) + '</li>'; |
| 169 |
$('legend', this).hide(); |
| 170 |
}); |
| 171 |
|
| 172 |
nav += '</ul>'; |
| 173 |
progressbar.append( nav ); |
| 174 |
|
| 175 |
$('.wpuf-step-wizard li', progressbar).first().addClass('active-step'); |
| 176 |
$('.wpuf-step-wizard', progressbar).listautowidth(); |
| 177 |
}); |
| 178 |
} |
| 179 |
|
| 180 |
this.change_fieldset(step_number, progressbar_type); |
| 181 |
|
| 182 |
$('fieldset .wpuf-multistep-prev-btn, fieldset .wpuf-multistep-next-btn').click(function(e) { |
| 183 |
// js_obj.formSubmit(); |
| 184 |
if ( $(this).hasClass('wpuf-multistep-next-btn') ) { |
| 185 |
var result = js_obj.formStepCheck( '', $(this).closest('fieldset') ); |
| 186 |
|
| 187 |
if ( result != false ) { |
| 188 |
o.change_fieldset(++step_number,progressbar_type); |
| 189 |
} |
| 190 |
|
| 191 |
} else if ( $(this).hasClass('wpuf-multistep-prev-btn') ) { |
| 192 |
o.change_fieldset( --step_number,progressbar_type ); |
| 193 |
} |
| 194 |
|
| 195 |
var formDiv = $( "form.wpuf-form-add" ); |
| 196 |
var position = formDiv.offset().top; |
| 197 |
|
| 198 |
// this changes the scrolling behavior to "smooth" |
| 199 |
window.scrollTo({ |
| 200 |
top: position - 32, |
| 201 |
behavior: "smooth" |
| 202 |
}); |
| 203 |
|
| 204 |
return false; |
| 205 |
}); |
| 206 |
}, |
| 207 |
|
| 208 |
change_fieldset: function(step_number, progressbar_type) { |
| 209 |
var current_step = $('fieldset.wpuf-multistep-fieldset').eq(step_number); |
| 210 |
|
| 211 |
$('fieldset.wpuf-multistep-fieldset').removeClass('field-active').eq(step_number).addClass('field-active'); |
| 212 |
|
| 213 |
$('.wpuf-step-wizard li').each(function(){ |
| 214 |
if ( $(this).index() <= step_number ){ |
| 215 |
progressbar_type == 'step_by_step'? $(this).addClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).addClass('passed-wpuf-ms-bar'); |
| 216 |
} else { |
| 217 |
progressbar_type == 'step_by_step'? $(this).removeClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).removeClass('passed-wpuf-ms-bar'); |
| 218 |
} |
| 219 |
}); |
| 220 |
|
| 221 |
$('.wpuf-step-wizard li').removeClass('wpuf-ms-bar-active active-step completed-step'); |
| 222 |
$('.passed-wpuf-ms-bar').addClass('completed-step').last().addClass('wpuf-ms-bar-active'); |
| 223 |
$('.wpuf-ms-bar-active').addClass('active-step'); |
| 224 |
|
| 225 |
var legend = $('fieldset.wpuf-multistep-fieldset').eq(step_number).find('legend').text(); |
| 226 |
legend = $.trim( legend ); |
| 227 |
|
| 228 |
if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) { |
| 229 |
var progress_percent = ( step_number + 1 ) * 100 / $('fieldset.wpuf-multistep-fieldset').length ; |
| 230 |
var progress_percent = Number( progress_percent.toFixed(2) ); |
| 231 |
$( ".wpuf-multistep-progressbar" ).progressbar({value: progress_percent }); |
| 232 |
$( '.wpuf-progress-percentage' ).text( legend + ' (' + progress_percent + '%)'); |
| 233 |
} |
| 234 |
|
| 235 |
// trigger a change event |
| 236 |
$('.wpuf-form').trigger('step-change-fieldset', [ step_number, current_step ]); |
| 237 |
}, |
| 238 |
|
| 239 |
ajaxCategory: function () { |
| 240 |
|
| 241 |
var el = '.cat-ajax', |
| 242 |
wrap = '.category-wrap'; |
| 243 |
|
| 244 |
$(wrap).on('change', el, function(){ |
| 245 |
currentLevel = parseInt( $(this).parent().attr('level') ); |
| 246 |
WP_User_Frontend.getChildCats( $(this), 'lvl', currentLevel+1, wrap, 'category'); |
| 247 |
}); |
| 248 |
}, |
| 249 |
|
| 250 |
getChildCats: function (dropdown, result_div, level, wrap_div, taxonomy) { |
| 251 |
|
| 252 |
cat = $(dropdown).val(); |
| 253 |
results_div = result_div + level; |
| 254 |
taxonomy = typeof taxonomy !== 'undefined' ? taxonomy : 'category'; |
| 255 |
field_attr = $(dropdown).siblings('span').data('taxonomy'); |
| 256 |
|
| 257 |
$.ajax({ |
| 258 |
type: 'post', |
| 259 |
url: wpuf_frontend.ajaxurl, |
| 260 |
data: { |
| 261 |
action: 'wpuf_get_child_cat', |
| 262 |
catID: cat, |
| 263 |
nonce: wpuf_frontend.nonce, |
| 264 |
field_attr: field_attr |
| 265 |
}, |
| 266 |
beforeSend: function() { |
| 267 |
$(dropdown).parent().parent().next('.loading').addClass('wpuf-loading'); |
| 268 |
}, |
| 269 |
complete: function() { |
| 270 |
$(dropdown).parent().parent().next('.loading').removeClass('wpuf-loading'); |
| 271 |
}, |
| 272 |
success: function(html) { |
| 273 |
//console.log( html ); return; |
| 274 |
$(dropdown).parent().nextAll().each(function(){ |
| 275 |
$(this).remove(); |
| 276 |
}); |
| 277 |
|
| 278 |
if(html != "") { |
| 279 |
$(dropdown).parent().addClass('hasChild').parent().append('<div id="'+result_div+level+'" level="'+level+'"></div>'); |
| 280 |
dropdown.parent().parent().find('#'+results_div).html(html).slideDown('fast'); |
| 281 |
} |
| 282 |
} |
| 283 |
}); |
| 284 |
}, |
| 285 |
|
| 286 |
cloneField: function(e) { |
| 287 |
e.preventDefault(); |
| 288 |
|
| 289 |
var $div = $(this).closest('tr'); |
| 290 |
var $clone = $div.clone(); |
| 291 |
// console.log($clone); |
| 292 |
|
| 293 |
//clear the inputs |
| 294 |
$clone.find('input').val(''); |
| 295 |
$clone.find(':checked').attr('checked', ''); |
| 296 |
$div.after($clone); |
| 297 |
}, |
| 298 |
|
| 299 |
removeField: function() { |
| 300 |
//check if it's the only item |
| 301 |
var $parent = $(this).closest('tr'); |
| 302 |
var items = $parent.siblings().andSelf().length; |
| 303 |
|
| 304 |
if( items > 1 ) { |
| 305 |
$parent.remove(); |
| 306 |
} |
| 307 |
}, |
| 308 |
|
| 309 |
adminPostSubmit: function(e) { |
| 310 |
e.preventDefault(); |
| 311 |
|
| 312 |
var form = $(this), |
| 313 |
form_data = WP_User_Frontend.validateForm(form); |
| 314 |
|
| 315 |
if (form_data) { |
| 316 |
return true; |
| 317 |
} |
| 318 |
}, |
| 319 |
|
| 320 |
draftPost: function (e) { |
| 321 |
e.preventDefault(); |
| 322 |
|
| 323 |
var self = $(this), |
| 324 |
form = $(this).closest('form'), |
| 325 |
form_data = form.weSerialize() + '&action=wpuf_draft_post', |
| 326 |
post_id = form.find('input[type="hidden"][name="post_id"]').val(); |
| 327 |
|
| 328 |
var rich_texts = [], |
| 329 |
val; |
| 330 |
|
| 331 |
// grab rich texts from tinyMCE |
| 332 |
$('.wpuf-rich-validation').each(function (index, item) { |
| 333 |
var item = $(item); |
| 334 |
var editor_id = item.data('id'); |
| 335 |
var item_name = item.data('name'); |
| 336 |
var val = $.trim( tinyMCE.get(editor_id).getContent() ); |
| 337 |
|
| 338 |
rich_texts.push(item_name + '=' + encodeURIComponent( val ) ); |
| 339 |
}); |
| 340 |
|
| 341 |
// append them to the form var |
| 342 |
form_data = form_data + '&' + rich_texts.join('&'); |
| 343 |
|
| 344 |
|
| 345 |
self.after(' <span class="wpuf-loading"></span>'); |
| 346 |
$.post(wpuf_frontend.ajaxurl, form_data, function(res) { |
| 347 |
// console.log(res, post_id); |
| 348 |
if ( typeof post_id === 'undefined') { |
| 349 |
var html = '<input type="hidden" name="post_id" value="' + res.post_id +'">'; |
| 350 |
html += '<input type="hidden" name="post_date" value="' + res.date +'">'; |
| 351 |
html += '<input type="hidden" name="post_author" value="' + res.post_author +'">'; |
| 352 |
html += '<input type="hidden" name="comment_status" value="' + res.comment_status +'">'; |
| 353 |
|
| 354 |
form.append( html ); |
| 355 |
} |
| 356 |
|
| 357 |
self.next('span.wpuf-loading').remove(); |
| 358 |
|
| 359 |
self.after('<span class="wpuf-draft-saved"> Post Saved</span>'); |
| 360 |
$('.wpuf-draft-saved').delay(2500).fadeOut('fast', function(){ |
| 361 |
$(this).remove(); |
| 362 |
}); |
| 363 |
}) |
| 364 |
}, |
| 365 |
|
| 366 |
// Frontend account dashboard update profile |
| 367 |
account_update_profile: function (e) { |
| 368 |
e.preventDefault(); |
| 369 |
var form = $(this).closest('form'); |
| 370 |
|
| 371 |
$.post(wpuf_frontend.ajaxurl, form.weSerialize(), function (res) { |
| 372 |
if (res.success) { |
| 373 |
form.find('.wpuf-error').hide(); |
| 374 |
form.find('.wpuf-success').show(); |
| 375 |
} else { |
| 376 |
form.find('.wpuf-success').hide(); |
| 377 |
form.find('.wpuf-error').show(); |
| 378 |
form.find('.wpuf-error').text(res.data); |
| 379 |
} |
| 380 |
}); |
| 381 |
}, |
| 382 |
|
| 383 |
formStepCheck : function(e,fieldset) { |
| 384 |
var form = fieldset, |
| 385 |
submitButton = form.find('input[type=submit]'); |
| 386 |
form_data = WP_User_Frontend.validateForm(form); |
| 387 |
|
| 388 |
if ( form_data == false ) { |
| 389 |
WP_User_Frontend.addErrorNotice( self, 'bottom' ); |
| 390 |
} |
| 391 |
return form_data; |
| 392 |
}, |
| 393 |
|
| 394 |
formSubmit: function(e) { |
| 395 |
e.preventDefault(); |
| 396 |
|
| 397 |
var form = $(this), |
| 398 |
submitButton = form.find('input[type=submit]') |
| 399 |
form_data = WP_User_Frontend.validateForm(form); |
| 400 |
|
| 401 |
if (form_data) { |
| 402 |
|
| 403 |
// send the request |
| 404 |
form.find('li.wpuf-submit').append('<span class="wpuf-loading"></span>'); |
| 405 |
submitButton.attr('disabled', 'disabled').addClass('button-primary-disabled'); |
| 406 |
|
| 407 |
$.post(wpuf_frontend.ajaxurl, form_data, function(res) { |
| 408 |
// var res = $.parseJSON(res); |
| 409 |
|
| 410 |
if ( res.success) { |
| 411 |
|
| 412 |
// enable external plugins to use events |
| 413 |
$('body').trigger('wpuf:postform:success', res); |
| 414 |
|
| 415 |
if ( res.show_message == true) { |
| 416 |
form.before( '<div class="wpuf-success">' + res.message + '</div>'); |
| 417 |
form.slideUp( 'fast', function() { |
| 418 |
form.remove(); |
| 419 |
}); |
| 420 |
|
| 421 |
//focus |
| 422 |
$('html, body').animate({ |
| 423 |
scrollTop: $('.wpuf-success').offset().top - 100 |
| 424 |
}, 'fast'); |
| 425 |
|
| 426 |
} else { |
| 427 |
window.location = res.redirect_to; |
| 428 |
} |
| 429 |
|
| 430 |
} else { |
| 431 |
|
| 432 |
if ( typeof res.type !== 'undefined' && res.type === 'login' ) { |
| 433 |
|
| 434 |
if ( confirm(res.error) ) { |
| 435 |
window.location = res.redirect_to; |
| 436 |
} else { |
| 437 |
submitButton.removeAttr('disabled'); |
| 438 |
submitButton.removeClass('button-primary-disabled'); |
| 439 |
form.find('span.wpuf-loading').remove(); |
| 440 |
} |
| 441 |
|
| 442 |
return; |
| 443 |
} else { |
| 444 |
if ( form.find('.g-recaptcha').length > 0 ) { |
| 445 |
grecaptcha.reset(); |
| 446 |
} |
| 447 |
|
| 448 |
swal({ |
| 449 |
html: res.error, |
| 450 |
type: 'warning', |
| 451 |
showCancelButton: false, |
| 452 |
confirmButtonColor: '#d54e21', |
| 453 |
confirmButtonText: 'OK', |
| 454 |
cancelButtonClass: 'btn btn-danger', |
| 455 |
}); |
| 456 |
|
| 457 |
} |
| 458 |
|
| 459 |
submitButton.removeAttr('disabled'); |
| 460 |
} |
| 461 |
|
| 462 |
submitButton.removeClass('button-primary-disabled'); |
| 463 |
form.find('span.wpuf-loading').remove(); |
| 464 |
}); |
| 465 |
} |
| 466 |
}, |
| 467 |
|
| 468 |
validateForm: function( self ) { |
| 469 |
|
| 470 |
var temp, |
| 471 |
temp_val = '', |
| 472 |
error = false, |
| 473 |
error_items = []; |
| 474 |
error_type = ''; |
| 475 |
|
| 476 |
// remove all initial errors if any |
| 477 |
WP_User_Frontend.removeErrors(self); |
| 478 |
WP_User_Frontend.removeErrorNotice(self); |
| 479 |
|
| 480 |
// Validate: Required Fields |
| 481 |
var required = self.find('[data-required="yes"]:visible'); |
| 482 |
|
| 483 |
required.each(function(i, item) { |
| 484 |
|
| 485 |
var data_type = $(item).data('type') |
| 486 |
val = ''; |
| 487 |
|
| 488 |
switch(data_type) { |
| 489 |
case 'rich': |
| 490 |
var name = $(item).data('id') |
| 491 |
val = $.trim( tinyMCE.get(name).getContent() ); |
| 492 |
|
| 493 |
if ( val === '') { |
| 494 |
error = true; |
| 495 |
|
| 496 |
// make it warn collor |
| 497 |
WP_User_Frontend.markError(item); |
| 498 |
} |
| 499 |
break; |
| 500 |
|
| 501 |
case 'textarea': |
| 502 |
case 'text': |
| 503 |
|
| 504 |
val = $.trim( $(item).val() ); |
| 505 |
|
| 506 |
if ( val === '') { |
| 507 |
error = true; |
| 508 |
error_type = 'required'; |
| 509 |
|
| 510 |
// make it warn collor |
| 511 |
WP_User_Frontend.markError( item, error_type ); |
| 512 |
} |
| 513 |
break; |
| 514 |
|
| 515 |
case 'password': |
| 516 |
case 'confirm_password': |
| 517 |
var hasRepeat = $(item).data('repeat'); |
| 518 |
|
| 519 |
val = $.trim( $(item).val() ); |
| 520 |
|
| 521 |
if ( val === '') { |
| 522 |
error = true; |
| 523 |
error_type = 'required'; |
| 524 |
|
| 525 |
// make it warn collor |
| 526 |
WP_User_Frontend.markError( item, error_type ); |
| 527 |
} |
| 528 |
|
| 529 |
if ( hasRepeat ) { |
| 530 |
var repeatItem = $('[data-type="confirm_password"]').eq(0);; |
| 531 |
|
| 532 |
if ( repeatItem.val() != val ) { |
| 533 |
error = true; |
| 534 |
error_type = 'mismatch'; |
| 535 |
|
| 536 |
WP_User_Frontend.markError( repeatItem, error_type ); |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
break; |
| 541 |
|
| 542 |
case 'select': |
| 543 |
val = $(item).val(); |
| 544 |
|
| 545 |
// console.log(val); |
| 546 |
if ( !val || val === '-1' ) { |
| 547 |
error = true; |
| 548 |
error_type = 'required'; |
| 549 |
|
| 550 |
// make it warn collor |
| 551 |
WP_User_Frontend.markError( item, error_type ); |
| 552 |
} |
| 553 |
break; |
| 554 |
|
| 555 |
case 'multiselect': |
| 556 |
val = $(item).val(); |
| 557 |
|
| 558 |
if ( val === null || val.length === 0 ) { |
| 559 |
error = true; |
| 560 |
error_type = 'required'; |
| 561 |
|
| 562 |
// make it warn collor |
| 563 |
WP_User_Frontend.markError( item, error_type ); |
| 564 |
} |
| 565 |
break; |
| 566 |
|
| 567 |
case 'tax-checkbox': |
| 568 |
var length = $(item).children().find('input:checked').length; |
| 569 |
|
| 570 |
if ( !length ) { |
| 571 |
error = true; |
| 572 |
error_type = 'required'; |
| 573 |
|
| 574 |
// make it warn collor |
| 575 |
WP_User_Frontend.markError( item, error_type ); |
| 576 |
} |
| 577 |
break; |
| 578 |
|
| 579 |
case 'radio': |
| 580 |
var length = $(item).find('input:checked').length; |
| 581 |
|
| 582 |
if ( !length ) { |
| 583 |
error = true; |
| 584 |
error_type = 'required'; |
| 585 |
|
| 586 |
// make it warn collor |
| 587 |
WP_User_Frontend.markError( item, error_type ); |
| 588 |
} |
| 589 |
break; |
| 590 |
|
| 591 |
case 'file': |
| 592 |
var length = $(item).find('ul').children().length; |
| 593 |
|
| 594 |
if ( !length ) { |
| 595 |
error = true; |
| 596 |
error_type = 'required'; |
| 597 |
|
| 598 |
// make it warn collor |
| 599 |
WP_User_Frontend.markError( item, error_type ); |
| 600 |
} |
| 601 |
break; |
| 602 |
|
| 603 |
case 'email': |
| 604 |
var val = $(item).val(); |
| 605 |
|
| 606 |
if ( val !== '' ) { |
| 607 |
//run the validation |
| 608 |
if( !WP_User_Frontend.isValidEmail( val ) ) { |
| 609 |
error = true; |
| 610 |
error_type = 'validation'; |
| 611 |
|
| 612 |
WP_User_Frontend.markError( item, error_type ); |
| 613 |
} |
| 614 |
} else if( val === '' ) { |
| 615 |
error = true; |
| 616 |
error_type = 'required'; |
| 617 |
|
| 618 |
WP_User_Frontend.markError( item, error_type ); |
| 619 |
} |
| 620 |
break; |
| 621 |
|
| 622 |
|
| 623 |
case 'url': |
| 624 |
var val = $(item).val(); |
| 625 |
|
| 626 |
if ( val !== '' ) { |
| 627 |
//run the validation |
| 628 |
if( !WP_User_Frontend.isValidURL( val ) ) { |
| 629 |
error = true; |
| 630 |
error_type = 'validation'; |
| 631 |
|
| 632 |
WP_User_Frontend.markError( item, error_type ); |
| 633 |
} |
| 634 |
} |
| 635 |
break; |
| 636 |
|
| 637 |
}; |
| 638 |
|
| 639 |
}); |
| 640 |
|
| 641 |
//check Google Map is required |
| 642 |
var map_required = self.find('[data-required="yes"][name="google_map"]'); |
| 643 |
if ( map_required ) { |
| 644 |
var val = $(map_required).val(); |
| 645 |
if ( val == ',' ) { |
| 646 |
error = true; |
| 647 |
error_type = 'required'; |
| 648 |
|
| 649 |
WP_User_Frontend.markError( map_required, error_type ); |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
// if already some error found, bail out |
| 654 |
if (error) { |
| 655 |
// add error notice |
| 656 |
WP_User_Frontend.addErrorNotice(self,'end'); |
| 657 |
|
| 658 |
return false; |
| 659 |
} |
| 660 |
|
| 661 |
var form_data = self.weSerialize(), |
| 662 |
rich_texts = []; |
| 663 |
|
| 664 |
// grab rich texts from tinyMCE |
| 665 |
$('.wpuf-rich-validation', self).each(function (index, item) { |
| 666 |
var item = $(item); |
| 667 |
var editor_id = item.data('id'); |
| 668 |
var item_name = item.data('name'); |
| 669 |
var val = $.trim( tinyMCE.get(editor_id).getContent() ); |
| 670 |
|
| 671 |
rich_texts.push(item_name + '=' + encodeURIComponent( val ) ); |
| 672 |
}); |
| 673 |
|
| 674 |
// append them to the form var |
| 675 |
form_data = form_data + '&' + rich_texts.join('&'); |
| 676 |
return form_data; |
| 677 |
}, |
| 678 |
|
| 679 |
/** |
| 680 |
* |
| 681 |
* @param form |
| 682 |
* @param position (value = bottom or end) end if form is onepare, bottom, if form is multistep |
| 683 |
*/ |
| 684 |
addErrorNotice: function( form, position ) { |
| 685 |
if( position == 'bottom' ) { |
| 686 |
$('.wpuf-multistep-fieldset:visible').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>'); |
| 687 |
} else { |
| 688 |
$(form).find('li.wpuf-submit').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>'); |
| 689 |
} |
| 690 |
|
| 691 |
}, |
| 692 |
|
| 693 |
removeErrorNotice: function(form) { |
| 694 |
$(form).find('.wpuf-errors').remove(); |
| 695 |
}, |
| 696 |
|
| 697 |
markError: function(item, error_type) { |
| 698 |
|
| 699 |
var error_string = ''; |
| 700 |
$(item).closest('li').addClass('has-error'); |
| 701 |
|
| 702 |
if ( error_type ) { |
| 703 |
error_string = $(item).closest('li').data('label'); |
| 704 |
switch ( error_type ) { |
| 705 |
case 'required' : |
| 706 |
error_string = error_string + ' ' + error_str_obj[error_type]; |
| 707 |
break; |
| 708 |
case 'mismatch' : |
| 709 |
error_string = error_string + ' ' +error_str_obj[error_type]; |
| 710 |
break; |
| 711 |
case 'validation' : |
| 712 |
error_string = error_string + ' ' + error_str_obj[error_type]; |
| 713 |
break |
| 714 |
} |
| 715 |
$(item).siblings('.wpuf-error-msg').remove(); |
| 716 |
$(item).after('<div class="wpuf-error-msg">'+ error_string +'</div>') |
| 717 |
} |
| 718 |
|
| 719 |
$(item).focus(); |
| 720 |
}, |
| 721 |
|
| 722 |
removeErrors: function(item) { |
| 723 |
$(item).find('.has-error').removeClass('has-error'); |
| 724 |
$('.wpuf-error-msg').remove(); |
| 725 |
}, |
| 726 |
|
| 727 |
isValidEmail: function( email ) { |
| 728 |
var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); |
| 729 |
return pattern.test(email); |
| 730 |
}, |
| 731 |
/** |
| 732 |
* Validate a url. |
| 733 |
* |
| 734 |
* While we could use the standard HTML5 form validator for urls, this regex does a more thorough job. |
| 735 |
* |
| 736 |
* @link https://gist.github.com/dperini/729294 |
| 737 |
*/ |
| 738 |
isValidURL: function(url) { |
| 739 |
var urlregex = new RegExp(/^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/); |
| 740 |
return urlregex.test(url); |
| 741 |
}, |
| 742 |
|
| 743 |
insertImage: function(button, form_id) { |
| 744 |
|
| 745 |
var container = 'wpuf-insert-image-container'; |
| 746 |
|
| 747 |
if ( ! $( '#' + button ).length ) { |
| 748 |
return; |
| 749 |
}; |
| 750 |
|
| 751 |
var imageUploader = new plupload.Uploader({ |
| 752 |
runtimes: 'html5,html4', |
| 753 |
browse_button: button, |
| 754 |
container: container, |
| 755 |
multipart: true, |
| 756 |
multipart_params: { |
| 757 |
action: 'wpuf_insert_image', |
| 758 |
form_id: $( '#' + button ).data('form_id') |
| 759 |
}, |
| 760 |
multiple_queues: false, |
| 761 |
multi_selection: false, |
| 762 |
urlstream_upload: true, |
| 763 |
file_data_name: 'wpuf_file', |
| 764 |
max_file_size: '2mb', |
| 765 |
url: wpuf_frontend_upload.plupload.url, |
| 766 |
flash_swf_url: wpuf_frontend_upload.flash_swf_url, |
| 767 |
filters: [{ |
| 768 |
title: 'Allowed Files', |
| 769 |
extensions: 'jpg,jpeg,gif,png,bmp' |
| 770 |
}] |
| 771 |
}); |
| 772 |
|
| 773 |
imageUploader.bind('Init', function(up, params) { |
| 774 |
// console.log("Current runtime environment: " + params.runtime); |
| 775 |
}); |
| 776 |
|
| 777 |
imageUploader.bind('FilesAdded', function(up, files) { |
| 778 |
var $container = $('#' + container); |
| 779 |
|
| 780 |
$.each(files, function(i, file) { |
| 781 |
$container.append( |
| 782 |
'<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div></div>'); |
| 783 |
}); |
| 784 |
|
| 785 |
up.refresh(); |
| 786 |
up.start(); |
| 787 |
}); |
| 788 |
|
| 789 |
imageUploader.bind('QueueChanged', function (uploader) { |
| 790 |
imageUploader.start(); |
| 791 |
}); |
| 792 |
|
| 793 |
imageUploader.bind('UploadProgress', function(up, file) { |
| 794 |
var item = $('#' + file.id); |
| 795 |
|
| 796 |
$('.bar', item).css({ width: file.percent + '%' }); |
| 797 |
$('.percent', item).html( file.percent + '%' ); |
| 798 |
}); |
| 799 |
|
| 800 |
imageUploader.bind('Error', function(up, error) { |
| 801 |
alert('Error #' + error.code + ': ' + error.message); |
| 802 |
}); |
| 803 |
|
| 804 |
imageUploader.bind('FileUploaded', function(up, file, response) { |
| 805 |
|
| 806 |
$('#' + file.id).remove(); |
| 807 |
|
| 808 |
if ( response.response !== 'error' ) { |
| 809 |
var success = false; |
| 810 |
|
| 811 |
if ( typeof tinyMCE !== 'undefined' ) { |
| 812 |
|
| 813 |
if ( typeof tinyMCE.execInstanceCommand !== 'function' ) { |
| 814 |
// tinyMCE 4.x |
| 815 |
var mce = tinyMCE.get( 'post_content_' + form_id ); |
| 816 |
|
| 817 |
if ( mce !== null ) { |
| 818 |
mce.insertContent(response.response); |
| 819 |
} |
| 820 |
} else { |
| 821 |
// tinyMCE 3.x |
| 822 |
tinyMCE.execInstanceCommand( 'post_content_' + form_id, 'mceInsertContent', false, response.response); |
| 823 |
} |
| 824 |
} |
| 825 |
|
| 826 |
// insert failed to the edit, perhaps insert into textarea |
| 827 |
var post_content = $('#post_content_' + form_id); |
| 828 |
post_content.val( post_content.val() + response.response ); |
| 829 |
|
| 830 |
} else { |
| 831 |
alert('Something went wrong'); |
| 832 |
} |
| 833 |
}); |
| 834 |
|
| 835 |
imageUploader.init(); |
| 836 |
}, |
| 837 |
|
| 838 |
deleteAvatar: function(e) { |
| 839 |
e.preventDefault(); |
| 840 |
|
| 841 |
if ( confirm( $(this).data('confirm') ) ) { |
| 842 |
$.post(wpuf_frontend.ajaxurl, {action: 'wpuf_delete_avatar', _wpnonce: wpuf_frontend.nonce}, function() { |
| 843 |
$(e.target).parent().remove(); |
| 844 |
$('[id^=wpuf-avatar]').css("display", ""); |
| 845 |
}); |
| 846 |
} |
| 847 |
}, |
| 848 |
|
| 849 |
editorLimit: { |
| 850 |
|
| 851 |
bind: function(limit, field, type) { |
| 852 |
if ( type === 'no' ) { |
| 853 |
// it's a textarea |
| 854 |
$('textarea#' + field).keydown( function(event) { |
| 855 |
WP_User_Frontend.editorLimit.textLimit.call(this, event, limit); |
| 856 |
}); |
| 857 |
|
| 858 |
$('input#' + field).keydown( function(event) { |
| 859 |
WP_User_Frontend.editorLimit.textLimit.call(this, event, limit); |
| 860 |
}); |
| 861 |
|
| 862 |
$('textarea#' + field).on('paste', function(event) { |
| 863 |
var self = $(this); |
| 864 |
|
| 865 |
setTimeout(function() { |
| 866 |
WP_User_Frontend.editorLimit.textLimit.call(self, event, limit); |
| 867 |
}, 100); |
| 868 |
}); |
| 869 |
|
| 870 |
$('input#' + field).on('paste', function(event) { |
| 871 |
var self = $(this); |
| 872 |
|
| 873 |
setTimeout(function() { |
| 874 |
WP_User_Frontend.editorLimit.textLimit.call(self, event, limit); |
| 875 |
}, 100); |
| 876 |
}); |
| 877 |
|
| 878 |
} else { |
| 879 |
// it's a rich textarea |
| 880 |
setTimeout(function () { |
| 881 |
tinyMCE.get(field).onKeyDown.add(function(ed, event) { |
| 882 |
WP_User_Frontend.editorLimit.tinymce.onKeyDown(ed, event, limit); |
| 883 |
} ); |
| 884 |
|
| 885 |
tinyMCE.get(field).onPaste.add(function(ed, event) { |
| 886 |
setTimeout(function() { |
| 887 |
WP_User_Frontend.editorLimit.tinymce.onPaste(ed, event, limit); |
| 888 |
}, 100); |
| 889 |
}); |
| 890 |
|
| 891 |
}, 1000); |
| 892 |
} |
| 893 |
}, |
| 894 |
|
| 895 |
tinymce: { |
| 896 |
|
| 897 |
getStats: function(ed) { |
| 898 |
var body = ed.getBody(), text = tinymce.trim(body.innerText || body.textContent); |
| 899 |
|
| 900 |
return { |
| 901 |
chars: text.length, |
| 902 |
words: text.split(/[\w\u2019\'-]+/).length |
| 903 |
}; |
| 904 |
}, |
| 905 |
|
| 906 |
onKeyDown: function(ed, event, limit) { |
| 907 |
var numWords = WP_User_Frontend.editorLimit.tinymce.getStats(ed).words - 1; |
| 908 |
|
| 909 |
limit ? $('.mce-path-item.mce-last', ed.container).html('Word Limit : '+ numWords +'/'+limit):''; |
| 910 |
|
| 911 |
if ( limit && numWords > limit ) { |
| 912 |
WP_User_Frontend.editorLimit.blockTyping(event); |
| 913 |
jQuery('.mce-path-item.mce-last', ed.container).html( wpuf_frontend.word_limit ); |
| 914 |
} |
| 915 |
}, |
| 916 |
|
| 917 |
onPaste: function(ed, event, limit) { |
| 918 |
var editorContent = ed.getContent().split(' ').slice(0, limit).join(' '); |
| 919 |
|
| 920 |
// Let TinyMCE do the heavy lifting for inserting that content into the editor. |
| 921 |
// ed.insertContent(content); //ed.execCommand('mceInsertContent', false, content); |
| 922 |
ed.setContent(editorContent); |
| 923 |
|
| 924 |
WP_User_Frontend.editorLimit.make_media_embed_code(editorContent, ed); |
| 925 |
} |
| 926 |
}, |
| 927 |
|
| 928 |
textLimit: function(event, limit) { |
| 929 |
var self = $(this), |
| 930 |
content = self.val().split(' '); |
| 931 |
|
| 932 |
if ( limit && content.length > limit ) { |
| 933 |
self.closest('.wpuf-fields').find('span.wpuf-wordlimit-message').html( wpuf_frontend.word_limit ); |
| 934 |
WP_User_Frontend.editorLimit.blockTyping(event); |
| 935 |
} else { |
| 936 |
self.closest('.wpuf-fields').find('span.wpuf-wordlimit-message').html(''); |
| 937 |
} |
| 938 |
|
| 939 |
// handle the paste event |
| 940 |
if ( event.type === 'paste' ) { |
| 941 |
self.val( content.slice(0, limit).join( ' ' ) ); |
| 942 |
} |
| 943 |
}, |
| 944 |
|
| 945 |
blockTyping: function(event) { |
| 946 |
// Allow: backspace, delete, tab, escape, minus enter and . backspace = 8,delete=46,tab=9,enter=13,.=190,escape=27, minus = 189 |
| 947 |
if ($.inArray(event.keyCode, [46, 8, 9, 27, 13, 110, 190, 189]) !== -1 || |
| 948 |
// Allow: Ctrl+A |
| 949 |
(event.keyCode == 65 && event.ctrlKey === true) || |
| 950 |
// Allow: home, end, left, right, down, up |
| 951 |
(event.keyCode >= 35 && event.keyCode <= 40)) { |
| 952 |
// let it happen, don't do anything |
| 953 |
return; |
| 954 |
} |
| 955 |
|
| 956 |
event.preventDefault(); |
| 957 |
event.stopPropagation(); |
| 958 |
}, |
| 959 |
|
| 960 |
make_media_embed_code: function(content, editor){ |
| 961 |
$.post( ajaxurl, { |
| 962 |
action:'make_media_embed_code', |
| 963 |
content: content |
| 964 |
}, |
| 965 |
function(data){ |
| 966 |
// console.log(data); |
| 967 |
editor.setContent(editor.getContent() + editor.setContent(data)); |
| 968 |
} |
| 969 |
) |
| 970 |
} |
| 971 |
} |
| 972 |
}; |
| 973 |
|
| 974 |
$(function() { |
| 975 |
WP_User_Frontend.init(); |
| 976 |
|
| 977 |
// payment gateway selection |
| 978 |
$('ul.wpuf-payment-gateways').on('click', 'input[type=radio]', function(e) { |
| 979 |
$('.wpuf-payment-instruction').slideUp(250); |
| 980 |
|
| 981 |
$(this).parents('li').find('.wpuf-payment-instruction').slideDown(250); |
| 982 |
}); |
| 983 |
|
| 984 |
if( !$('ul.wpuf-payment-gateways li').find('input[type=radio]').is(':checked') ) { |
| 985 |
$('ul.wpuf-payment-gateways li').first().find('input[type=radio]').click() |
| 986 |
} else { |
| 987 |
var el = $('ul.wpuf-payment-gateways li').find('input[type=radio]:checked'); |
| 988 |
el.parents('li').find('.wpuf-payment-instruction').slideDown(250); |
| 989 |
} |
| 990 |
}); |
| 991 |
|
| 992 |
$(function() { |
| 993 |
$('input[name="first_name"], input[name="last_name"]').on('change keyup', function() { |
| 994 |
var myVal, newVal = $.makeArray($('input[name="first_name"], input[name="last_name"]').map(function(){ |
| 995 |
if (myVal = $(this).val()) { |
| 996 |
return(myVal); |
| 997 |
} |
| 998 |
})).join(' '); |
| 999 |
$('input[name="display_name"]').val(newVal); |
| 1000 |
}); |
| 1001 |
}); |
| 1002 |
|
| 1003 |
// script for Dokan vendor registration template |
| 1004 |
$(function($) { |
| 1005 |
|
| 1006 |
$('.wpuf-form-add input[name="dokan_store_name"]').on('focusout', function() { |
| 1007 |
var value = $(this).val().toLowerCase().replace(/-+/g, '').replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, ''); |
| 1008 |
$('input[name="shopurl"]').val(value); |
| 1009 |
$('#url-alart').text( value ); |
| 1010 |
$('input[name="shopurl"]').focus(); |
| 1011 |
}); |
| 1012 |
|
| 1013 |
$('.wpuf-form-add input[name="shopurl"]').keydown(function(e) { |
| 1014 |
var text = $(this).val(); |
| 1015 |
|
| 1016 |
// Allow: backspace, delete, tab, escape, enter and . |
| 1017 |
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 91, 109, 110, 173, 189, 190]) !== -1 || |
| 1018 |
// Allow: Ctrl+A |
| 1019 |
(e.keyCode == 65 && e.ctrlKey === true) || |
| 1020 |
// Allow: home, end, left, right |
| 1021 |
(e.keyCode >= 35 && e.keyCode <= 39)) { |
| 1022 |
// let it happen, don't do anything |
| 1023 |
return; |
| 1024 |
} |
| 1025 |
|
| 1026 |
if ((e.shiftKey || (e.keyCode < 65 || e.keyCode > 90) && (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105) ) { |
| 1027 |
e.preventDefault(); |
| 1028 |
} |
| 1029 |
}); |
| 1030 |
|
| 1031 |
$('.wpuf-form-add input[name="shopurl"]').keyup(function(e) { |
| 1032 |
$('#url-alart').text( $(this).val() ); |
| 1033 |
}); |
| 1034 |
|
| 1035 |
$('.wpuf-form-add input[name="shopurl"]').on('focusout', function() { |
| 1036 |
var self = $(this), |
| 1037 |
data = { |
| 1038 |
action : 'shop_url', |
| 1039 |
url_slug : self.val(), |
| 1040 |
_nonce : dokan.nonce, |
| 1041 |
}; |
| 1042 |
|
| 1043 |
if ( self.val() === '' ) { |
| 1044 |
return; |
| 1045 |
} |
| 1046 |
|
| 1047 |
$.post( dokan.ajaxurl, data, function(resp) { |
| 1048 |
|
| 1049 |
if ( resp == 0){ |
| 1050 |
$('#url-alart').removeClass('text-success').addClass('text-danger'); |
| 1051 |
$('#url-alart-mgs').removeClass('text-success').addClass('text-danger').text(dokan.seller.notAvailable); |
| 1052 |
} else { |
| 1053 |
$('#url-alart').removeClass('text-danger').addClass('text-success'); |
| 1054 |
$('#url-alart-mgs').removeClass('text-danger').addClass('text-success').text(dokan.seller.available); |
| 1055 |
} |
| 1056 |
|
| 1057 |
} ); |
| 1058 |
|
| 1059 |
}); |
| 1060 |
|
| 1061 |
// Set name attribute for google map search field |
| 1062 |
$(".wpuf-form-add #wpuf-map-add-location").attr("name", "find_address"); |
| 1063 |
}); |
| 1064 |
|
| 1065 |
})(jQuery, window); |
| 1066 |
|