PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.74
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.74
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 1.0.20 1.0.21 All 174 releases
← All changes | admin/assets/js/users-wp-admin.js +493 -349 1.0.101.2.74 View file →
@@ -1,434 +1,578 @@
1 -jQuery(window).load(function() {
2 - // Chosen selects
3 - if (jQuery("select.uwp_chosen_select").length > 0) {
4 - jQuery("select.uwp_chosen_select").chosen();
5 - jQuery("select.uwp_chosen_select_nostd").chosen({
6 - allow_single_deselect: 'true'
7 - });
8 - }
9 -});
1 +(function ($) {
2 + 'use strict';
10 3
11 -function uwp_chosen() {
12 - if (jQuery("select.uwp_chosen_select").length > 0) {
13 - jQuery("select.uwp_chosen_select").chosen();
14 - jQuery("select.uwp_chosen_select_nostd").chosen({
15 - allow_single_deselect: 'true'
16 - });
17 - }
18 -}
4 + window.UWP = window.UWP || {};
19 5
20 -function uwp_show_hide(id) {
21 - jQuery('#' + id).toggle();
22 -}
6 + UWP.Admin = {
7 + mediaFrames: [],
23 8
24 -function uwp_show_hide_radio(id,sh,cl) {
25 - if(sh=='hide'){
26 - jQuery( id ).closest( '.widefat' ).find('.'+cl).hide('fast');
27 - }else{
28 - jQuery( id ).closest( '.widefat' ).find('.'+cl).show('fast');
29 - }
9 + init: function () {
10 + this.initColorPicker();
11 + this.initImageUploader();
12 + this.initFormHandlers();
13 + this.initMiscHandlers();
14 + this.initTooltips();
15 + this.initFormControls();
16 + this.initUserTypesReorder();
17 + },
30 18
31 -}
32 -
33 -function validate_field(field) {
34 -
35 - var is_error = true;
36 - switch (jQuery(field).attr('field_type')) {
37 - case 'radio':
38 - case 'checkbox':
39 -
40 - if (jQuery(field).closest('.required_field').find(":checked").length > 0) {
41 - is_error = false;
19 + /**
20 + * Toggle button loading state
21 + *
22 + * @param {jQuery} element Button element
23 + * @param {string} handle State to set ('loading' or 'reset')
24 + */
25 + buttonStatus: function (element, handle) {
26 + if (handle === "loading") {
27 + element.data('text', element.html());
28 + element.prop('disabled', true);
29 + element.html('<i class="fas fa-circle-notch fa-spin ml-2"></i> <span>Loading...</span>');
30 + } else {
31 + element.prop('disabled', false);
32 + element.html(element.data('text'));
42 33 }
43 - break;
34 + },
44 35
45 - case 'select':
46 - if (jQuery(field).find("option:selected").length > 0 && jQuery(field).find("option:selected").val() != '') {
47 - is_error = false;
36 + /**
37 + * Initialize color picker functionality
38 + */
39 + initColorPicker: function () {
40 + const $colorPicker = $('.uwp-color-picker');
41 + if ($colorPicker.length) {
42 + $colorPicker.wpColorPicker();
48 43 }
49 - break;
44 + },
50 45
51 - case 'multiselect':
46 + /**
47 + * Initialize image uploader functionality
48 + */
49 + initImageUploader: function () {
50 + const self = this;
52 51
53 - if (jQuery(field).find("option:selected").length > 0) {
54 - is_error = false;
55 - }
52 + // Initialize remove button visibility
53 + $('.uwp-upload-img').each(function () {
54 + const $wrap = $(this);
55 + const field = $wrap.data('field');
56 + if ($(`[name="${field}[id]"]`).length && !$(`[name="${field}[id]"]`).val()) {
57 + $('.uwp_remove_image_button', $wrap).hide();
58 + }
59 + });
56 60
61 + // Upload button handler
62 + $(document).on('click', '.uwp_upload_image_button', function (e) {
63 + e.preventDefault();
64 + self.handleImageUpload($(this));
65 + });
57 66
58 - break;
67 + // Remove button handler
68 + $(document).on('click', '.uwp_remove_image_button', function () {
69 + self.handleImageRemove($(this));
70 + return false;
71 + });
72 + },
59 73
60 - case 'email':
61 - var email_filter = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
62 - if (field.value != '' && email_filter.test(field.value)) {
63 - is_error = false;
64 - }
65 - break;
74 + /**
75 + * Handle image upload process
76 + * @param {jQuery} $button Upload button element
77 + */
78 + handleImageUpload: function ($button) {
79 + const $wrap = $button.closest('.uwp-upload-img');
80 + const field = $wrap.data('field');
66 81
67 - case 'url':
68 - var url_filter = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
69 - if (field.value != '' && url_filter.test(field.value)) {
70 - is_error = false;
71 - }
72 - break;
82 + if (!field) return;
73 83
74 - case 'editor':
75 - if (jQuery('#' + jQuery(field).attr('field_id')).val() != '') {
76 - is_error = false;
84 + if (this.mediaFrames[field]) {
85 + this.mediaFrames[field].open();
86 + return;
77 87 }
78 - break;
79 88
80 - case 'datepicker':
81 - case 'time':
82 - case 'text':
83 - case 'textarea':
84 - if (field.value != '') {
85 - is_error = false;
86 - }
87 - break;
89 + this.mediaFrames[field] = wp.media({
90 + title: uwp_admin_ajax.txt_choose_image,
91 + button: {
92 + text: uwp_admin_ajax.txt_use_image
93 + },
94 + multiple: false
95 + });
88 96
89 - default:
90 - if (field.value != '') {
91 - is_error = false;
92 - }
93 - break;
97 + this.mediaFrames[field].on('select', function () {
98 + const attachment = this.mediaFrames[field].state().get('selection').first().toJSON();
99 + const thumbnail = attachment.sizes.medium || attachment.sizes.full;
94 100
95 - }
101 + if (field) {
102 + $(`[name="${field}[id]"]`).val(attachment.id);
103 + $(`[name="${field}[src]"]`).val(attachment.url);
104 + $(`[name="${field}"]`).val(attachment.id);
105 + }
96 106
107 + $wrap.closest('.form-field.form-invalid').removeClass('form-invalid');
108 + $('.uwp-upload-display', $wrap).find('img')
109 + .attr('src', thumbnail.url);
110 + $('.uwp_remove_image_button').show();
111 + }.bind(this));
97 112
98 - if (is_error) {
99 - if (jQuery(field).closest('.required_field').find('span.uwp_message_error').html() == '') {
100 - jQuery(field).closest('.required_field').find('span.uwp_message_error').html(uwp_admin_ajax.custom_field_id_required)
101 - }
113 + this.mediaFrames[field].open();
114 + },
102 115
103 - jQuery(field).closest('.required_field').find('span.uwp_message_error').fadeIn();
116 + /**
117 + * Handle image removal
118 + * @param {jQuery} $button Remove button element
119 + */
120 + handleImageRemove: function ($button) {
121 + const $wrap = $button.closest('.uwp-upload-img');
122 + const field = $wrap.data('field');
104 123
105 - return false;
106 - } else {
124 + $('.uwp-upload-display', $wrap).find('img')
125 + .attr('src', uwp_admin_ajax.img_spacer)
126 + .removeAttr('width height sizes alt class srcset');
107 127
108 - jQuery(field).closest('.required_field').find('span.uwp_message_error').html('');
109 - jQuery(field).closest('.required_field').find('span.uwp_message_error').fadeOut();
128 + if (field) {
129 + $(`[name="${field}[id]"]`).val('');
130 + $(`[name="${field}[src]"]`).val('');
131 + $(`[name="${field}"]`).val('');
132 + }
110 133
111 - return true;
112 - }
113 -}
134 + $button.hide();
135 + },
114 136
115 -jQuery(document).ready(function () {
116 - jQuery("#uwp-form-builder-tab, #uwp-form-builder-tab-predefined").find("ul li a").click(function () {
117 - if(!jQuery(this).attr('id')){return;}
118 - var type = jQuery(this).data("field-type");
119 - var type_key = jQuery(this).data("field-type-key");
120 - var custom_type = jQuery(this).data("field-custom-type");
121 - var form_type = jQuery(this).closest('#uwp-form-builder-tab, #uwp-form-builder-tab-predefined').find('#form_type').val();
122 - var id = 'new' + jQuery(".field_row_main ul.core li:last").index();
123 - var manage_field_type = jQuery(this).closest('#uwp-available-fields').find(".manage_field_type").val();
124 - if (manage_field_type == 'custom_fields') {
125 - jQuery.get(uwp_admin_ajax.url + '?action=uwp_ajax_action&create_field=true', {
126 - field_type: type,
127 - field_type_key: type_key,
128 - form_type: form_type,
129 - field_id: id,
130 - field_ins_upd: 'new',
131 - manage_field_type: manage_field_type,
132 - custom_type: custom_type
133 - }, function (data) {
134 - jQuery('.field_row_main ul.core').append(data);
135 - uwp_chosen();
136 - jQuery('#licontainer_' + id).find('#sort_order').val(parseInt(jQuery('#licontainer_' + id).index()) + 1);
137 - uwp_show_hide('field_frm'+id);
138 - jQuery('html, body').animate({
139 - scrollTop: jQuery("#licontainer_"+id).offset().top
140 - }, 1000);
137 + /**
138 + * Initialize form related handlers
139 + */
140 + initFormHandlers: function () {
141 + const self = this;
141 142
143 + // Handle large text inputs
144 + $('.userswp .forminp .large-text').on({
145 + focus: function () {
146 + const $this = $(this);
147 + const placeholder = $this.attr('placeholder');
148 + if ($this.val() === '') {
149 + $this.val(placeholder);
150 + }
151 + },
152 + blur: function () {
153 + const $this = $(this);
154 + const placeholder = $this.attr('placeholder');
155 + if ($this.val() === placeholder) {
156 + $this.val('');
157 + }
158 + }
142 159 });
143 - }
144 - });
145 - jQuery(".field_row_main ul.core").sortable({
146 - opacity: 0.8,
147 - cursor: 'move',
148 - placeholder: "ui-state-highlight",
149 - cancel: "input,label,select",
150 - update: function () {
151 - var manage_field_type = jQuery(this).closest('#uwp-selected-fields').find(".manage_field_type").val();
152 - var order = jQuery(this).sortable("serialize") + '&update=update&manage_field_type=' + manage_field_type;
153 - if (manage_field_type == 'custom_fields' || manage_field_type == 'sorting_options') {
154 - jQuery.get(uwp_admin_ajax.url + '?action=uwp_ajax_action&create_field=true', order, function (theResponse) {
155 - //alert('Fields have been ordered.');
156 - });
157 - }
158 - }
159 - });
160 160
161 - jQuery(".field_row_main ul.uwp_form_extras").sortable({ opacity: 0.8, placeholder: "ui-state-highlight",
162 - cancel: "input,label,select",cursor: 'move', update: function() {
161 + // Handle register form submission
162 + $('#uwp_user_type_form').on('submit', function (e) {
163 + self.handleRegisterFormSubmit(e, $(this));
164 + });
163 165
164 - var order = jQuery(this).sortable("serialize") + '&update=update';
165 -
166 - jQuery.get(uwp_admin_ajax.url+'?action=uwp_ajax_register_action&create_field=true', order, function(theResponse){
167 -
166 + // Handle register form removal
167 + $(document).on('click', '.register-form-remove', function (e) {
168 + self.handleRegisterFormRemove($(this));
168 169 });
169 - }
170 - });
170 + },
171 171
172 - jQuery("#uwp-form-builder-tab").find("ul li a").click(function() {
173 - if(!jQuery(this).attr('id')){return;}
174 - var htmlvar_name = jQuery(this).attr('id').replace('uwp-','');
175 - var field_type = jQuery(this).data('type');
172 + /**
173 + * Handle register form submission
174 + * @param {Event} e Submit event
175 + * @param {jQuery} $form Form element
176 + */
177 + handleRegisterFormSubmit: function (e, $form) {
178 + e.preventDefault();
179 + const { __ } = wp.i18n;
180 + const self = this;
181 + const error = $form.find('.alert.alert-danger');
182 + const success = $form.find('.alert.alert-success');
183 + const action = $form.find('[name="action"]').val() || 'edit';
184 + const ajaxAction = action === 'edit' ? 'uwp_ajax_update_register' : 'uwp_ajax_create_register';
185 + const data = $form.serialize() + `&action=${ajaxAction}&type=update`;
186 + const $button = $("button[type=submit]", $form);
176 187
177 - var form_type = jQuery(this).closest('#uwp-form-builder-tab').find('#form_type').val();
188 + const formTitleInput = $form.find('[name="form_title"]');
178 189
179 - var id = 'new'+jQuery(".field_row_main ul.uwp_form_extras li:last").index();
190 + formTitleInput.on('input', function () {
191 + if ($(this).hasClass('is-invalid')) {
192 + $(this).removeClass('is-invalid');
193 + }
194 + });
180 195
181 - var manage_field_type = jQuery(this).closest('#uwp-available-fields').find(".manage_field_type").val();
196 + if (formTitleInput.val() === '') {
197 + formTitleInput.addClass('is-invalid');
198 + formTitleInput.next('.invalid-feedback').text(__('Form title is required.', 'userswp'));
199 + return;
200 + } else {
201 + formTitleInput.removeClass('is-invalid');
202 + }
182 203
183 - if (manage_field_type == 'register'){
204 + self.buttonStatus($button, 'loading');
184 205
185 - jQuery.get(uwp_admin_ajax.url+'?action=uwp_ajax_register_action&create_field=true',{ htmlvar_name: htmlvar_name,form_type:form_type, field_type:field_type, field_id: id, field_ins_upd: 'new' },
186 - function(data)
187 - {
188 - console.log(id);
189 - jQuery('.field_row_main ul.uwp_form_extras').append(data);
206 + $.post(uwp_admin_ajax.url, data, (response) => {
207 + self.buttonStatus($button, 'reset');
190 208
191 - jQuery('#licontainer_'+htmlvar_name).find('#sort_order').val( parseInt(jQuery('#licontainer_'+htmlvar_name).index()) + 1 );
209 + if (response.success === false) {
210 + this.handleError(error, success, response.data.message);
211 + } else if (response.success) {
212 + this.handleSuccess(error, success, response.data.message);
192 213
193 - uwp_show_hide('field_frm'+htmlvar_name);
194 - jQuery('html, body').animate({
195 - scrollTop: jQuery("#licontainer_"+htmlvar_name).offset().top
196 - }, 1000);
197 -
198 - save_register_field(htmlvar_name); // save registration fields on add
199 -
214 + if (response.data.redirect) {
215 + setTimeout(() => {
216 + window.location.replace(response.data.redirect);
217 + }, 1000);
218 + }
219 + }
220 + }, "json")
221 + .fail(() => {
222 + self.buttonStatus($button, "reset");
223 + self.handleError(error, success, __('There is something that went wrong!', 'userswp'));
200 224 });
225 + },
201 226
202 - if(htmlvar_name!='fieldset'){
203 - jQuery(this).closest('li').hide();
204 - }
227 + /**
228 + * Handle error response.
229 + *
230 + * @param {jQuery} error Error element
231 + * @param {jQuery} success Success element
232 + * @param {string} message Error message
233 + */
234 + handleError: function (error, success, message) {
235 + if (success.is(":visible")) success.addClass('d-none');
236 + error.html(message).removeClass('d-none').slideDown();
237 + },
205 238
206 - }
239 + /**
240 + * Handle success response.
241 + *
242 + * @param {jQuery} error Error element
243 + * @param {jQuery} success Success element
244 + * @param {string} message Error message
245 + */
246 + handleSuccess: function (error, success, message) {
247 + if (error.is(":visible")) error.addClass('d-none');
248 + success.html(message).removeClass('d-none').slideDown();
249 + },
207 250
208 - if (manage_field_type == 'search'){
251 + /**
252 + * Handle register form removal
253 + * @param {jQuery} $button Remove button element
254 + */
255 + handleRegisterFormRemove: function ($button) {
256 + const self = this;
257 + const formId = $button.attr('data-id');
209 258
210 - var field_data_type = jQuery(this).data('data_type');
259 + self.buttonStatus($button, 'loading');
211 260
212 - jQuery.get(uwp_admin_ajax.url+'?action=uwp_ajax_search_action&create_field=true',{ htmlvar_name: htmlvar_name,form_type:form_type, field_type:field_type, field_data_type:field_data_type, field_id: id, field_ins_upd: 'new' },
213 - function(data)
214 - {
215 - console.log(id);
216 - jQuery('.field_row_main ul.uwp_form_extras').append(data);
261 + const confirmation = confirm(uwp_admin_ajax.delete_register_form);
217 262
218 - jQuery('#licontainer_'+htmlvar_name).find('#sort_order').val( parseInt(jQuery('#licontainer_'+htmlvar_name).index()) + 1 );
263 + if (confirmation) {
264 + const data = {
265 + 'action': 'uwp_ajax_remove_user_type',
266 + 'type': 'remove',
267 + 'form_id': formId,
268 + 'nonce': uwp_admin_ajax.nonces.uwp_delete_user_type
269 + };
219 270
220 - uwp_show_hide('field_frm'+htmlvar_name);
221 - jQuery('html, body').animate({
222 - scrollTop: jQuery("#licontainer_"+htmlvar_name).offset().top
223 - }, 1000);
271 + $.post(uwp_admin_ajax.url, data, function (response) {
272 + if (response.status) {
273 + window.location.replace(response.redirect);
274 + }
224 275
276 + self.buttonStatus($button, 'reset');
225 277 });
226 -
227 - if(htmlvar_name!='fieldset'){
228 - jQuery(this).closest('li').hide();
278 + } else {
279 + self.buttonStatus($button, 'reset');
229 280 }
281 + },
230 282
231 - }
283 + /**
284 + * Initialize miscellaneous handlers
285 + */
286 + initMiscHandlers: function () {
287 + // Code copy handler
288 + $(document).on('click', '.userswp span code', function () {
289 + const $code = $(this);
290 + $('.userswp span code').removeClass('uwp-tag-copied').find('span').remove();
291 + $code.addClass('uwp-tag-copied').append('<span></span>');
232 292
233 - });
234 -});
293 + const $temp = $("<input>");
294 + $("body").append($temp);
295 + $temp.val($code.text()).select();
296 + document.execCommand("copy");
297 + $temp.remove();
235 298
236 -function uwp_data_type_changed(obj, cont) {
237 - if (obj && cont) {
238 - jQuery('#licontainer_' + cont).find('.decimal-point-wrapper').hide();
239 - if (jQuery(obj).val() == 'FLOAT') {
240 - jQuery('#licontainer_' + cont).find('.decimal-point-wrapper').show();
241 - }
299 + setTimeout(function () {
300 + $('.userswp span code').removeClass('uwp-tag-copied').find('span').remove();
301 + }, 1000);
302 + });
242 303
243 - if (jQuery(obj).val() == 'FLOAT' || jQuery(obj).val() == 'INT') {
244 - jQuery('#licontainer_' + cont).find('.uwp-price-extra-set').show();
304 + // SEO meta separator handler
305 + $('input.uwp-seo-meta-separator').on('change', function () {
306 + if ($(this).attr("checked") === "checked") {
307 + $('input.uwp-seo-meta-separator').parent().removeClass('active');
308 + $(this).parent().addClass('active');
309 + }
310 + }).change();
245 311
246 - if(jQuery('#licontainer_' + cont).find(".uwp-price-extra-set input[name='extra[is_price]']:checked").val()=='1'){
247 - jQuery('#licontainer_' + cont).find('.uwp-price-extra').show();
248 - }
312 + // Font Awesome select handler
313 + $(".aui-fa-select2").select2({
314 + templateResult: this.formatFaSelect,
315 + templateSelection: this.formatFaSelection,
316 + escapeMarkup: function (m) {
317 + return m;
318 + }
319 + });
249 320
250 - }else{
251 - jQuery('#licontainer_' + cont).find('.uwp-price-extra-set').hide();
252 - jQuery('#licontainer_' + cont).find('.uwp-price-extra').hide();
253 - }
254 - }
255 -}
321 + // Register options toggle
322 + $(document).on('click', '.register-show-options', function () {
323 + $("#uwp-form-more-options").toggle("fast");
324 + });
325 + },
256 326
257 -function save_field(id) {
327 + /**
328 + * Initialize user types reordering functionality
329 + */
330 + initUserTypesReorder: function () {
331 + const table = $('.wp-list-table.usertypes tbody, .wp-list-table.membershiptypes tbody');
332 + table.length && table.sortable({
333 + handle: '.uwp-user-type-handle',
334 + axis: 'y',
335 + helper: function (e, ui) {
336 + ui.children().each(function () {
337 + $(this).width($(this).width());
338 + });
339 + ui.addClass('uwp-dragging');
340 + return ui;
341 + },
342 + start: function(e, ui) {
343 + ui.placeholder.addClass('uwp-drag-placeholder');
344 + },
345 + stop: function(e, ui) {
346 + ui.item.removeClass('uwp-dragging');
347 + table.find('.uwp-drag-placeholder').removeClass('uwp-drag-placeholder');
348 + },
349 + update: function (event, ui) {
350 + const order = table.find('input[name="user_types[]"]').map(function () {
351 + return $(this).val();
352 + }).get();
258 353
259 - if (jQuery('#licontainer_' + id + ' #htmlvar_name').length > 0) {
354 + $.ajax({
355 + url: uwp_admin_ajax.url,
356 + type: 'POST',
357 + data: {
358 + action: 'uwp_ajax_reorder_user_types',
359 + order: order,
360 + nonce: uwp_admin_ajax.nonces.uwp_reorder_user_types
361 + },
362 + success: function (response) {
363 + if (response.success) {
364 + aui_toast('uwp_reorder_user_types_success', 'success', uwp_admin_ajax.txt_saved);
365 + } else {
366 + aui_toast('uwp_reorder_user_types_error', 'error', uwp_admin_ajax.txt_saving_error);
367 + }
368 + },
369 + error: function () {
370 + aui_toast('uwp_reorder_user_types_error', 'error', uwp_admin_ajax.txt_saving_error);
371 + }
372 + });
373 + }
374 + });
375 + },
260 376
261 - var htmlvar_name = jQuery('#licontainer_' + id + ' #htmlvar_name').val();
377 + /**
378 + * Display an admin notice
379 + *
380 + * @param {string} message The message to display
381 + * @param {string} type The notice type ('success' or 'error')
382 + */
383 + showNotice: function (message, type) {
384 + const noticeClass = type === 'success' ? 'notice-success' : 'notice-error';
385 + const $notice = $(`<div class="notice ${noticeClass} is-dismissible"><p>${message}</p></div>`);
386 + $notice.insertAfter('.wp-header-end');
262 387
263 - if (htmlvar_name == '') {
388 + // Auto-dismiss after 3 seconds
389 + setTimeout(function () {
390 + $notice.fadeOut(300, function () { $(this).remove(); });
391 + }, 3000);
392 + },
264 393
265 - alert(uwp_admin_ajax.custom_field_not_blank_var);
394 + /**
395 + * Initialize form control handlers
396 + */
397 + initFormControls: function () {
398 + this.initSectionToggles();
399 + this.initAdvancedSettings();
400 + },
266 401
267 - return false;
268 - }
402 + /**
403 + * Initialize section toggle handlers
404 + */
405 + initSectionToggles: function () {
406 + $(document).on('click', '.toggle-arrow', (e) => {
407 + this.handleSectionToggle($(e.currentTarget));
408 + });
409 + },
269 410
270 - if (htmlvar_name != '') {
411 + /**
412 + * Initialize advanced settings toggle
413 + */
414 + initAdvancedSettings: function () {
415 + const $advancedToggle = $('.uwp-advanced-toggle');
416 + const $advancedElements = $('.uwp-advanced-setting, #default_location_set_address_button');
271 417
272 - var iChars = "!`@#$%^&*()+=-[]\\\';,./{}|\":<>?~ ";
418 + $advancedToggle
419 + .off('click')
420 + .on('click', function () {
421 + $advancedToggle.toggleClass('uwpa-hide');
422 + $advancedElements.toggleClass('uwpa-show');
423 + $advancedElements.collapse('toggle');
424 + });
425 + },
273 426
274 - for (var i = 0; i < htmlvar_name.length; i++) {
275 - if (iChars.indexOf(htmlvar_name.charAt(i)) != -1) {
427 + /**
428 + * Handle section toggle visibility
429 + * @param {jQuery} $toggleElement The clicked toggle element
430 + */
431 + handleSectionToggle: function ($toggleElement) {
432 + const $parentSettings = $toggleElement.parent('.li-settings');
433 + const $currentForm = $parentSettings.find('.field_frm').first();
434 + const isOpen = !$currentForm.is(':hidden');
276 435
277 - alert(uwp_admin_ajax.custom_field_not_special_char);
436 + // Hide all forms and reset all arrows
437 + $('.field_frm').hide();
438 + $('.toggle-arrow')
439 + .addClass('fa-caret-down')
440 + .removeClass('fa-caret-up');
278 441
279 -
280 - return false;
281 - }
442 + if (isOpen) {
443 + // Close current section
444 + $toggleElement
445 + .addClass('fa-caret-down')
446 + .removeClass('fa-caret-up');
447 + $currentForm
448 + .hide()
449 + .removeClass('uwp-tab-settings-open');
450 + } else {
451 + // Open current section
452 + $toggleElement
453 + .addClass('fa-caret-up')
454 + .removeClass('fa-caret-down');
455 + $currentForm
456 + .show()
457 + .addClass('uwp-tab-settings-open');
282 458 }
283 - }
459 + },
284 460
285 - var option_val_input = jQuery('#licontainer_' + id + ' #option_values');
286 - if (option_val_input.length == 1) {
287 - var option_values = option_val_input.val();
288 - if (option_values == '') {
289 - alert(uwp_admin_ajax.custom_field_options_not_blank_var);
290 - return false;
291 - }
461 + /**
462 + * Handle radio button visibility changes
463 + * @param {string} elementId The ID of the radio element
464 + * @param {string} showHide Show/hide parameter (unused but kept for backwards compatibility)
465 + * @param {string} className The class to toggle visibility on
466 + */
467 + handleRadioVisibility: function (elementId, showHide, className) {
468 + setTimeout(() => {
469 + const $element = $(elementId);
470 + const $targetElement = $element.closest('.li-settings').find('.' + className);
471 + const isChecked = $element.is(':checked');
292 472
293 - }
294 - }
473 + $targetElement.toggle(isChecked ? 'fast' : 'fast');
474 + }, 100);
475 + },
295 476
296 - var fieldrequest = jQuery('#licontainer_' + id).find("select, textarea, input").serialize();
297 - var request_data = 'create_field=true&field_ins_upd=submit&' + fieldrequest;
298 -
299 -
300 - jQuery.ajax({
301 - 'url': uwp_admin_ajax.url + '?action=uwp_ajax_action&manage_field_type=custom_fields',
302 - 'type': 'POST',
303 - 'data': request_data,
304 - 'success': function (result) {
305 -
306 - //alert(result);
307 - if (jQuery.trim(result) == 'HTML Variable Name should be a unique name') {
308 -
309 - alert(uwp_admin_ajax.custom_field_unique_name);
310 -
477 + /**
478 + * Format Font Awesome select option
479 + * @param {Object} option Select option
480 + * @returns {string} Formatted option HTML
481 + */
482 + formatFaSelect: function (option) {
483 + if (!option.id) {
484 + return option.text;
311 485 }
312 - else {
313 - jQuery('#licontainer_' + id).replaceWith(jQuery.trim(result));
314 - uwp_chosen();
486 + const icon = $(option.element).attr('data-fa-icon');
487 + return '<i class="fa-lg ' + icon + '"></i> ' + option.text;
488 + },
315 489
316 - var order = jQuery(".field_row_main ul.core").sortable("serialize") + '&update=update&manage_field_type=custom_fields';
317 -
318 - jQuery.get(uwp_admin_ajax.url + '?action=uwp_ajax_action&create_field=true', order,
319 - function (theResponse) {
320 - //alert(theResponse);
321 - });
322 -
323 - jQuery('.field_frm').hide();
490 + /**
491 + * Format Font Awesome selected option
492 + * @param {Object} option Selected option
493 + * @returns {string} Formatted option HTML
494 + */
495 + formatFaSelection: function (option) {
496 + if (option.id.length > 0) {
497 + const icon = $(option.element).attr('data-fa-icon');
498 + return "<i class='fa-lg " + icon + "'></i> " + option.text;
324 499 }
500 + return option.text;
501 + },
325 502
503 + /**
504 + * Initialize tooltips
505 + */
506 + initTooltips: function () {
507 + const $tooltips = $('.uwp-help-tip').tooltip();
508 + const method = this.getTooltipVersion() >= 4 ? 'dispose' : 'destroy';
326 509
327 -
328 - }
329 - });
330 -
331 -
332 -}
333 -
334 -function delete_field(id, nonce) {
335 -
336 - var confarmation = confirm(uwp_admin_ajax.custom_field_delete);
337 -
338 - if (confarmation == true) {
339 -
340 - jQuery.get(uwp_admin_ajax.url + '?action=uwp_ajax_action&create_field=true&manage_field_type=custom_fields', {
341 - field_id: id,
342 - field_ins_upd: 'delete',
343 - _wpnonce: nonce
344 - },
345 - function (data) {
346 - jQuery('#licontainer_' + id).remove();
347 -
510 + $tooltips.tooltip(method).tooltip({
511 + content: function () {
512 + return $(this).prop('title');
513 + },
514 + tooltipClass: 'uwp-ui-tooltip',
515 + position: {
516 + my: 'center top',
517 + at: 'center bottom+10',
518 + collision: 'flipfit'
519 + },
520 + show: null,
521 + close: function (event, ui) {
522 + ui.tooltip.hover(
523 + function () {
524 + $(this).stop(true).fadeTo(400, 1);
525 + },
526 + function () {
527 + $(this).fadeOut("400", function () {
528 + $(this).remove();
529 + });
530 + }
531 + );
532 + }
348 533 });
534 + },
349 535
350 - }
536 + /**
537 + * Get Bootstrap tooltip version
538 + * @returns {number} Tooltip version number
539 + */
540 + getTooltipVersion: function () {
541 + let version = 0;
542 + if (typeof $.fn === 'object' &&
543 + typeof $.fn.tooltip === 'function' &&
544 + typeof $.fn.tooltip.Constructor === 'function' &&
545 + typeof $.fn.tooltip.Constructor.VERSION !== 'undefined') {
546 + version = parseFloat($.fn.tooltip.Constructor.VERSION);
547 + }
548 + return version;
549 + },
550 + };
351 551
352 -}
552 + // Global function mappings for backward compatibility
553 + window.uwp_show_hide = function ($element) {
554 + UWP.Admin.handleSectionToggle($($element));
555 + };
353 556
354 -function uwp_show_hide_register(id)
355 -{
356 - jQuery('#'+id).toggle();
357 -}
557 + window.uwp_show_hide_radio = function (id, sh, cl) {
558 + UWP.Admin.handleRadioVisibility(id, sh, cl);
559 + };
358 560
359 -function delete_register_field(id, nonce,deleteid)
360 -{
561 + window.uwp_init_advanced_settings = function () {
562 + UWP.Admin.initAdvancedSettings();
563 + };
361 564
362 - var restore_id = id.replace('new','');
565 + window.uwp_init_tooltips = function () {
566 + UWP.Admin.initTooltips();
567 + };
363 568
364 - var confirmation = confirm(uwp_admin_ajax.custom_field_delete);
569 + window.uwp_tooltip_version = function () {
570 + return UWP.Admin.getTooltipVersion();
571 + };
365 572
366 - if(confirmation == true)
367 - {
368 - jQuery('#create_advance_search_li_'+deleteid).show();
369 - jQuery.get(uwp_admin_ajax.url+'?action=uwp_ajax_register_action&create_field=true', { field_id: id, field_ins_upd: 'delete', _wpnonce:nonce },
370 - function(data)
371 - {
372 - jQuery('#licontainer_'+id).remove();
373 -
374 - });
375 -
376 - jQuery('#uwp-'+deleteid).closest('li').show();
377 -
378 - }
379 -
380 -}
381 -
382 -function save_register_field(id)
383 -{
384 - if(jQuery('#licontainer_'+id+' #field_title').length > 0){
385 -
386 - var htmlvar_name = jQuery('#licontainer_'+id+' #field_title').val();
387 -
388 - if(htmlvar_name == '')
389 - {
390 - alert(uwp_admin_ajax.custom_field_not_blank_var);
391 -
392 - return false;
393 - }
394 - }
395 -
396 -
397 -
398 - var fieldrequest = jQuery('#licontainer_'+id).find("select, textarea, input").serialize();
399 -
400 - var request_data = 'create_field=true&field_ins_upd=submit&' + fieldrequest ;
401 -
402 - jQuery.ajax({
403 - 'url': uwp_admin_ajax.url+'?action=uwp_ajax_register_action',
404 - 'type': 'POST',
405 - 'data': request_data ,
406 - 'success': function(result){
407 -
408 -
409 - if(jQuery.trim( result ) == 'HTML Variable Name should be a unique name')
410 - {
411 -
412 - alert(uwp_admin_ajax.custom_field_unique_name);
413 -
414 - }
415 - else
416 - {
417 - jQuery('#licontainer_'+id).replaceWith(jQuery.trim( result ));
418 -
419 - var order = jQuery(".field_row_main ul.uwp_form_extras").sortable("serialize") + '&update=update';
420 -
421 - jQuery.get(uwp_admin_ajax.url+'?action=uwp_ajax_register_action&create_field=true', order,
422 - function(theResponse){
423 - //alert(theResponse);
424 - });
425 -
426 - jQuery('.field_frm').hide();
427 - }
428 -
429 -
430 - }
573 + // Initialize when document is ready
574 + $(document).ready(function () {
575 + UWP.Admin.init();
431 576 });
432 577
433 -
434 -}
578 +})(jQuery);