| 1 |
jQuery(window).on('load', function () { |
| 2 |
|
| 3 |
// Load color picker |
| 4 |
var UWPColorPicker = jQuery('.uwp-color-picker'); |
| 5 |
if (UWPColorPicker.length) { |
| 6 |
UWPColorPicker.wpColorPicker(); |
| 7 |
} |
| 8 |
|
| 9 |
jQuery('.uwp-upload-img').each(function () { |
| 10 |
var $wrap = jQuery(this); |
| 11 |
var field = $wrap.data('field'); |
| 12 |
if (jQuery('[name="' + field + '[id]"]').length && !jQuery('[name="' + field + '[id]"]').val()) { |
| 13 |
jQuery('.uwp_remove_image_button', $wrap).hide(); |
| 14 |
} |
| 15 |
}); |
| 16 |
|
| 17 |
var media_frame = []; |
| 18 |
jQuery(document).on('click', '.uwp_upload_image_button', function (e) { |
| 19 |
e.preventDefault(); |
| 20 |
|
| 21 |
var $this = jQuery(this); |
| 22 |
var $wrap = $this.closest('.uwp-upload-img'); |
| 23 |
var field = $wrap.data('field'); |
| 24 |
|
| 25 |
if (!field) { |
| 26 |
return |
| 27 |
} |
| 28 |
|
| 29 |
if (media_frame && media_frame[field]) { |
| 30 |
media_frame[field].open(); |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
media_frame[field] = wp.media.frames.downloadable_file = wp.media({ |
| 35 |
title: uwp_admin_ajax.txt_choose_image, |
| 36 |
button: { |
| 37 |
text: uwp_admin_ajax.txt_use_image |
| 38 |
}, |
| 39 |
multiple: false |
| 40 |
}); |
| 41 |
|
| 42 |
// When an image is selected, run a callback. |
| 43 |
media_frame[field].on('select', function () { |
| 44 |
var attachment = media_frame[field].state().get('selection').first().toJSON(); |
| 45 |
|
| 46 |
var thumbnail = attachment.sizes.medium || attachment.sizes.full; |
| 47 |
if (field) { |
| 48 |
if (jQuery('[name="' + field + '[id]"]').length) { |
| 49 |
jQuery('[name="' + field + '[id]"]').val(attachment.id); |
| 50 |
} |
| 51 |
if (jQuery('[name="' + field + '[src]"]').length) { |
| 52 |
jQuery('[name="' + field + '[src]"]').val(attachment.url); |
| 53 |
} |
| 54 |
if (jQuery('[name="' + field + '"]').length) { |
| 55 |
jQuery('[name="' + field + '"]').val(attachment.id); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
} |
| 60 |
$wrap.closest('.form-field.form-invalid').removeClass('form-invalid'); |
| 61 |
jQuery('.uwp-upload-display', $wrap).find('img').attr('src', thumbnail.url); |
| 62 |
jQuery('.uwp_remove_image_button').show(); |
| 63 |
}); |
| 64 |
// Finally, open the modal. |
| 65 |
media_frame[field].open(); |
| 66 |
}); |
| 67 |
|
| 68 |
jQuery(document).on('click', '.uwp_remove_image_button', function () { |
| 69 |
var $this = jQuery(this); |
| 70 |
var $wrap = $this.closest('.uwp-upload-img'); |
| 71 |
var field = $wrap.data('field'); |
| 72 |
jQuery('.uwp-upload-display', $wrap).find('img').attr('src', uwp_admin_ajax.img_spacer).removeAttr('width height sizes alt class srcset'); |
| 73 |
if (field) { |
| 74 |
if (jQuery('[name="' + field + '[id]"]').length > 0) { |
| 75 |
jQuery('[name="' + field + '[id]"]').val(''); |
| 76 |
jQuery('[name="' + field + '[src]"]').val(''); |
| 77 |
} |
| 78 |
if (jQuery('[name="' + field + '"]').length > 0) { |
| 79 |
jQuery('[name="' + field + '"]').val(''); |
| 80 |
} |
| 81 |
} |
| 82 |
$this.hide(); |
| 83 |
return false; |
| 84 |
}); |
| 85 |
|
| 86 |
jQuery('.userswp .forminp .large-text').focus(function () { |
| 87 |
var placeholder = jQuery(this).attr('placeholder'); |
| 88 |
var current_val = jQuery(this).val(); |
| 89 |
if ('' == current_val) { |
| 90 |
jQuery(this).val(placeholder); |
| 91 |
} |
| 92 |
}).blur(function () { |
| 93 |
var placeholder = jQuery(this).attr('placeholder'); |
| 94 |
var current_val = jQuery(this).val(); |
| 95 |
if (current_val == placeholder) { |
| 96 |
jQuery(this).val(''); |
| 97 |
} |
| 98 |
}); |
| 99 |
|
| 100 |
jQuery(document).on('click', '.userswp span code', function ($) { |
| 101 |
jQuery('span code').removeClass('uwp-tag-copied'); |
| 102 |
jQuery('span code span').remove(); |
| 103 |
jQuery(this).addClass('uwp-tag-copied'); |
| 104 |
jQuery(this).append('<span></span>'); |
| 105 |
var $temp = jQuery("<input>"); |
| 106 |
jQuery("body").append($temp); |
| 107 |
$temp.val(jQuery(this).text()).select(); |
| 108 |
document.execCommand("copy"); |
| 109 |
$temp.remove(); |
| 110 |
|
| 111 |
setTimeout(function () { |
| 112 |
jQuery('span code').removeClass('uwp-tag-copied'); |
| 113 |
jQuery('span code span').remove(); |
| 114 |
}, 1000); |
| 115 |
}); |
| 116 |
|
| 117 |
jQuery('input.uwp-seo-meta-separator').on('change', function () { |
| 118 |
if (jQuery(this).attr("checked") === "checked") { |
| 119 |
jQuery('input.uwp-seo-meta-separator').parent().removeClass('active'); |
| 120 |
jQuery(this).parent().addClass('active'); |
| 121 |
} |
| 122 |
}).change(); |
| 123 |
|
| 124 |
jQuery(".aui-fa-select2").select2({ |
| 125 |
templateResult: aui_fa_select_format, |
| 126 |
templateSelection: function (option) { |
| 127 |
if (option.id.length > 0) { |
| 128 |
var icon = jQuery(option.element).attr('data-fa-icon'); |
| 129 |
return "<i class='fa-lg " + icon + "'></i> " + option.text; |
| 130 |
} else { |
| 131 |
return option.text; |
| 132 |
} |
| 133 |
}, |
| 134 |
escapeMarkup: function (m) { |
| 135 |
return m; |
| 136 |
} |
| 137 |
}); |
| 138 |
|
| 139 |
jQuery(document).on('click', '.register-show-options', function ($) { |
| 140 |
jQuery( "#uwp-form-more-options" ).toggle( "fast", function() { |
| 141 |
// Animation complete. |
| 142 |
}); |
| 143 |
}); |
| 144 |
|
| 145 |
jQuery(document).on('click', '.register-form-create', function ($) { |
| 146 |
var current_obj = jQuery(this); |
| 147 |
var nonce = current_obj.attr('data-nonce'); |
| 148 |
|
| 149 |
uwp_get_spin_loader(current_obj); |
| 150 |
|
| 151 |
var form_confirmation = prompt(uwp_admin_ajax.ask_register_form_title); |
| 152 |
|
| 153 |
if (form_confirmation !== null) { |
| 154 |
if (form_confirmation !== '') { |
| 155 |
var data = { |
| 156 |
'action': 'uwp_ajax_create_register', |
| 157 |
'type': 'create', |
| 158 |
'form_title': form_confirmation, |
| 159 |
'nonce': nonce, |
| 160 |
}; |
| 161 |
|
| 162 |
jQuery.post(uwp_admin_ajax.url, data, function (response) { |
| 163 |
response = JSON.parse(response); |
| 164 |
|
| 165 |
if (response.status) { |
| 166 |
uwp_remove_spin_loader(current_obj); |
| 167 |
window.location.replace(response.redirect); |
| 168 |
} else { |
| 169 |
console.log(response.message); |
| 170 |
} |
| 171 |
}); |
| 172 |
} else{ |
| 173 |
uwp_remove_spin_loader(current_obj); |
| 174 |
} |
| 175 |
} else { |
| 176 |
uwp_remove_spin_loader(current_obj); |
| 177 |
} |
| 178 |
}); |
| 179 |
|
| 180 |
jQuery(document).on('submit', '#uwp_user_type_form', function (e) { |
| 181 |
e.preventDefault(); |
| 182 |
|
| 183 |
var data = jQuery(this).serialize()+ "&action=uwp_ajax_update_register&type=update"; |
| 184 |
var btn = jQuery("button[type=submit]",this); |
| 185 |
|
| 186 |
uwp_get_spin_loader(btn); |
| 187 |
|
| 188 |
jQuery.post(uwp_admin_ajax.url, data, function (response) { |
| 189 |
response = JSON.parse(response); |
| 190 |
uwp_remove_spin_loader(btn); |
| 191 |
if (response.status) { |
| 192 |
btn.after('<b class="ml-1 text-success">'+uwp_admin_ajax.form_updated_msg+'</b>'); |
| 193 |
location.reload(); |
| 194 |
} else { |
| 195 |
console.log(response.message); |
| 196 |
} |
| 197 |
}); |
| 198 |
}); |
| 199 |
|
| 200 |
jQuery(document).on('click', '.register-form-remove', function (e) { |
| 201 |
var current_obj = jQuery(this); |
| 202 |
var form_id = current_obj.attr('data-id'); |
| 203 |
var nonce = current_obj.attr('data-nonce'); |
| 204 |
|
| 205 |
uwp_get_spin_loader(current_obj); |
| 206 |
|
| 207 |
var confirmation = confirm(uwp_admin_ajax.delete_register_form); |
| 208 |
|
| 209 |
if (confirmation === true) { |
| 210 |
var data = { |
| 211 |
'action': 'uwp_ajax_remove_register', |
| 212 |
'type': 'remove', |
| 213 |
'form_id': form_id, |
| 214 |
'nonce': nonce, |
| 215 |
}; |
| 216 |
|
| 217 |
jQuery.post(uwp_admin_ajax.url, data, function (response) { |
| 218 |
response = JSON.parse(response); |
| 219 |
|
| 220 |
if (response.status) { |
| 221 |
uwp_remove_spin_loader(current_obj); |
| 222 |
window.location.replace(response.redirect); |
| 223 |
} else { |
| 224 |
console.log(response.message); |
| 225 |
} |
| 226 |
}); |
| 227 |
} else { |
| 228 |
uwp_remove_spin_loader(current_obj); |
| 229 |
} |
| 230 |
}); |
| 231 |
|
| 232 |
uwp_init_tooltips(); |
| 233 |
}); |
| 234 |
|
| 235 |
function aui_fa_select_format(option) { |
| 236 |
if (!option.id) { |
| 237 |
return option.text; |
| 238 |
} |
| 239 |
|
| 240 |
var icon = jQuery(option.element).attr('data-fa-icon'); |
| 241 |
return '<i class="fa-lg ' + icon + '"></i> ' + option.text; |
| 242 |
} |
| 243 |
|
| 244 |
function uwp_show_hide($this) { |
| 245 |
var is_open = !jQuery($this).parent('.li-settings').find('.field_frm').first().is(':hidden'); |
| 246 |
jQuery('.field_frm').hide(); |
| 247 |
jQuery('.field_frm').parent().parent().find('.toggle-arrow').addClass("fa-caret-down").removeClass("fa-caret-up"); |
| 248 |
if (is_open) { |
| 249 |
jQuery($this).addClass("fa-caret-down").removeClass("fa-caret-up"); |
| 250 |
jQuery($this).parent('.li-settings').find('.field_frm').first().hide().removeClass("uwp-tab-settings-open"); |
| 251 |
} else { |
| 252 |
jQuery($this).addClass("fa-caret-up").removeClass("fa-caret-down"); |
| 253 |
jQuery($this).parent('.li-settings').find('.field_frm').first().show().addClass("uwp-tab-settings-open"); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
function uwp_show_hide_radio(id, sh, cl) { |
| 258 |
setTimeout(function() { |
| 259 |
$show = jQuery(id).is(":checked"); |
| 260 |
if ($show) { |
| 261 |
console.log('checked'); |
| 262 |
jQuery(id).closest('.li-settings').find('.' + cl).show('fast'); |
| 263 |
} else { |
| 264 |
console.log('unchecked'); |
| 265 |
jQuery(id).closest('.li-settings').find('.' + cl).hide('fast'); |
| 266 |
} |
| 267 |
}, 100); |
| 268 |
} |
| 269 |
|
| 270 |
function uwp_init_advanced_settings() { |
| 271 |
jQuery(".uwp-advanced-toggle").off("click").click(function () { |
| 272 |
jQuery(".uwp-advanced-toggle").toggleClass("uwpa-hide"); |
| 273 |
console.log('toggle'); |
| 274 |
jQuery(".uwp-advanced-setting, #default_location_set_address_button").toggleClass("uwpa-show"); |
| 275 |
}); |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Init the tooltips |
| 280 |
*/ |
| 281 |
function uwp_init_tooltips() { |
| 282 |
|
| 283 |
// we create, then destroy then create so we can ajax load and then call this function with impunity. |
| 284 |
var $tooltips = jQuery('.uwp-help-tip').tooltip(); |
| 285 |
|
| 286 |
var $method = uwp_tooltip_version() >= 4 ? 'dispose' : 'destroy'; |
| 287 |
|
| 288 |
$tooltips.tooltip($method).tooltip({ |
| 289 |
content: function () { |
| 290 |
return jQuery(this).prop('title'); |
| 291 |
}, |
| 292 |
tooltipClass: 'uwp-ui-tooltip', |
| 293 |
position: { |
| 294 |
my: 'center top', |
| 295 |
at: 'center bottom+10', |
| 296 |
collision: 'flipfit' |
| 297 |
}, |
| 298 |
show: null, |
| 299 |
close: function (event, ui) { |
| 300 |
ui.tooltip.hover( |
| 301 |
|
| 302 |
function () { |
| 303 |
jQuery(this).stop(true).fadeTo(400, 1); |
| 304 |
}, |
| 305 |
|
| 306 |
function () { |
| 307 |
jQuery(this).fadeOut("400", function () { |
| 308 |
jQuery(this).remove(); |
| 309 |
}) |
| 310 |
}); |
| 311 |
} |
| 312 |
}); |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* Get Bootstrap tooltip version. |
| 317 |
*/ |
| 318 |
function uwp_tooltip_version() { |
| 319 |
var ttv = 0; |
| 320 |
if (typeof jQuery.fn === 'object' && typeof jQuery.fn.tooltip === 'function' && typeof jQuery.fn.tooltip.Constructor === 'function' && typeof jQuery.fn.tooltip.Constructor.VERSION != 'undefined') { |
| 321 |
ttv = parseFloat(jQuery.fn.tooltip.Constructor.VERSION); |
| 322 |
} |
| 323 |
return ttv; |
| 324 |
} |
| 325 |
|
| 326 |
function uwp_get_spin_loader(loader_obj) { |
| 327 |
|
| 328 |
loader_obj.append('<i class="fas fa-circle-notch fa-spin ml-2 userswp-admin-spin"></i>'); |
| 329 |
} |
| 330 |
|
| 331 |
function uwp_remove_spin_loader(loader_obj) { |
| 332 |
|
| 333 |
setTimeout(function () { |
| 334 |
loader_obj.children('i.userswp-admin-spin').remove(); |
| 335 |
}, 1000); |
| 336 |
} |