PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.16.4
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.16.4
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / assets / js / jquery-pb-sitewide.js

jquery-pb-sitewide.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.16.4, at assets/js/jquery-pb-sitewide.js

1,011 lines 39.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Add a negative letter spacing to Profile Builder email customizer menus.
3 */
4
5 jQuery( document ).ready(function(){
6 jQuery('li a[href$="admin-email-customizer"]').css("letter-spacing", "-0.7px");
7 jQuery('li a[href$="user-email-customizer"]').css("letter-spacing", "-0.7px");
8 });
9
10 /*
11 * Set the width of the shortcode input based on an element that
12 * has the width of its contents
13 */
14 function setShortcodeInputWidth( $inputField ) {
15 var tempSpan = document.createElement('span');
16 tempSpan.className = "wppb-shortcode-temp";
17 tempSpan.innerHTML = $inputField.val();
18 document.body.appendChild(tempSpan);
19
20 var tempWidth = jQuery(tempSpan).outerWidth();
21
22 document.body.removeChild(tempSpan);
23
24 $inputField.outerWidth( tempWidth + 18 );
25 }
26
27 jQuery( document ).ready( function() {
28
29 jQuery('.wppb-shortcode.input').each( function() {
30 setShortcodeInputWidth( jQuery(this) );
31 });
32
33 jQuery('.wppb-shortcode.textarea').each( function() {
34 jQuery(this).outerHeight( jQuery(this)[0].scrollHeight + parseInt( jQuery(this).css('border-top-width') ) * 2 );
35 });
36
37 jQuery('.wppb-shortcode').on('click', function() {
38 this.select();
39 });
40 });
41
42
43 /* make sure that we don;t leave the page without having a title in the Post Title field, otherwise we loose data */
44 jQuery( function(){
45 if( jQuery( 'body').hasClass('post-new-php') ){
46
47 if( jQuery( 'body').hasClass('post-type-wppb-rf-cpt') || jQuery( 'body').hasClass('post-type-wppb-epf-cpt') || jQuery( 'body').hasClass('post-type-wppb-ul-cpt') ){
48
49 if( jQuery('#title').val() == '' ){
50 jQuery(window).on('beforeunload',function() {
51 return "This page is asking you to confirm that you want to leave - data you have entered may not be saved";
52 });
53 }
54
55 /* remove beforeunload event when entering a title or pressing the puclish button */
56 jQuery( '#title').on( 'keypress', function() {
57 jQuery(window).off('beforeunload');
58 });
59 jQuery( '#publish').on('click', function() {
60 jQuery(window).off('beforeunload');
61 });
62 }
63 }
64 });
65
66
67 /* show hide fields based on selected options */
68 jQuery( function(){
69 jQuery( '#wppb-rf-settings-args').on('change', '#redirect', function(){
70 if( jQuery(this).val() == 'Yes' ){
71 jQuery( '.row-url, .row-display-messages', jQuery(this).parent().parent().parent()).css('display', 'flex');
72 }
73 else{
74 jQuery( '.row-url, .row-display-messages', jQuery(this).parent().parent().parent()).hide();
75 }
76 });
77
78 jQuery( '#wppb-epf-settings-args').on('change', '#redirect', function(){
79 if( jQuery(this).val() == 'Yes' ){
80 jQuery( '.row-url, .row-display-messages', jQuery(this).parent().parent().parent()).css('display', 'flex');
81 }
82 else{
83 jQuery( '.row-url, .row-display-messages', jQuery(this).parent().parent().parent()).hide();
84 }
85 });
86
87
88 jQuery( '#wppb-ul-settings-args').on('click', '#visible-only-to-logged-in-users_yes', function(){
89
90 if (jQuery(this).is(':checked')) {
91 jQuery( '.row-visible-to-following-roles').css('display', 'flex');
92 }
93 else jQuery( '.row-visible-to-following-roles').css('display', 'none');
94 });
95
96 jQuery( '#wppb-ul-faceted-args').on('change', '#facet-type', function(){
97 if( jQuery(this).val() == 'checkboxes' ){
98 jQuery( '.row-facet-behaviour, .row-facet-limit', jQuery(this).parent().parent().parent()).show();
99 }else if( jQuery(this).val() == 'select_multiple' ){
100 jQuery( '.row-facet-behaviour, .row-facet-limit', jQuery(this).parent().parent().parent()).hide();
101 jQuery( '.row-facet-behaviour #facet-behaviour', jQuery(this).parent().parent().parent()).val('expand');
102 }
103 else{
104 jQuery( '.row-facet-behaviour, .row-facet-limit', jQuery(this).parent().parent().parent()).hide();
105 jQuery( '.row-facet-behaviour #facet-behaviour', jQuery(this).parent().parent().parent()).val('narrow');
106 }
107 if( jQuery(this).val() == 'search' ){
108 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="billing_country"] ').hide();
109 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="shipping_country"] ').hide();
110 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="billing_state"] ').hide();
111 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="shipping_state"] ').hide();
112 }
113 else {
114 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="billing_country"] ').show();
115 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="shipping_country"] ').show();
116 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="billing_state"] ').show();
117 jQuery( '#wppb-ul-faceted-args .row-facet-meta #facet-meta option[value="shipping_state"] ').show()
118 }
119
120 });
121
122 });
123
124 /*
125 * Dialog boxes throughout Profile Builder
126 */
127 jQuery( function() {
128 if ( jQuery.fn.dialog ) {
129 jQuery('.wppb-modal-box').dialog({
130 autoOpen: false,
131 modal: true,
132 draggable: false,
133 minWidth: 450,
134 minHeight: 450
135 });
136
137 jQuery('.wppb-open-modal-box').on('click', function (e) {
138 e.preventDefault();
139 jQuery('#' + jQuery(this).attr('href')).dialog('open');
140 });
141 }
142 });
143
144 /*
145 * Private Website Settings page
146 */
147
148 jQuery( function() {
149 if( jQuery( '.wppb-private-website' ).length != 0 ) {
150
151 wppbSelect2.call( jQuery('#private-website-redirect-to-login') );
152 wppbSelect2.call( jQuery('#private-website-allowed-pages') );
153
154 wppbDisablePrivatePageOptions(jQuery('#private-website-enable').val());
155
156 jQuery('#private-website-enable').on('change', function () {
157 wppbDisablePrivatePageOptions(jQuery(this).val());
158 });
159
160
161 function wppbDisablePrivatePageOptions(value) {
162 if (value == 'no') {
163 jQuery('#private-website-redirect-to-login').closest('tr').addClass("wppb-disabled");
164 jQuery('#private-website-allowed-pages').closest('tr').addClass("wppb-disabled");
165 jQuery('#private-website-menu-hide').addClass("wppb-disabled");
166 jQuery('#private-website-disable-rest-api').addClass("wppb-disabled");
167 jQuery('#private-website-allowed-paths').addClass("wppb-disabled");
168 }
169 else if (value == 'yes') {
170 jQuery('#private-website-redirect-to-login').closest('tr').removeClass("wppb-disabled");
171 jQuery('#private-website-allowed-pages').closest('tr').removeClass("wppb-disabled");
172 jQuery('#private-website-menu-hide').removeClass("wppb-disabled");
173 jQuery('#private-website-disable-rest-api').removeClass("wppb-disabled");
174 jQuery('#private-website-allowed-paths').removeClass("wppb-disabled");
175 }
176 }
177 }
178 });
179
180 /*
181 * Login Widget trigger html validation
182 */
183 jQuery( function() {
184 if( jQuery( ".widgets-php" ).length != 0 ){//should be in the admin widgets page
185 jQuery("#wpbody").on("click", ".widget-control-save", function () {
186 if (jQuery('.wppb-widget-url-field', jQuery(this).closest('form')).length != 0) {//we are in the PB widget
187 jQuery('.wppb-widget-url-field', jQuery(this).closest('form')).each(function () {
188 jQuery(this)[0].reportValidity();//reportValidity is the function that triggers the default html validation
189 });
190 }
191 });
192 }
193 });
194
195
196 /*
197 * Advanced Settings page (Toolbox)
198 */
199
200 jQuery( function() {
201 if( jQuery('body.profile-builder_page_profile-builder-toolbox-settings').length != 0 ) {
202
203 wppbSelect2.call( jQuery('#toolbox-bypass-ec') );
204
205 wppbSelect2.call( jQuery('#toolbox-restricted-emails'), {
206 tags: true,
207 });
208
209 jQuery('.wppb-toolbox-switch').on('click', function () {
210 if (jQuery(this).prop('checked'))
211 jQuery('.wppb-toolbox-accordion').css('display','flex');
212 else
213 jQuery('.wppb-toolbox-accordion').hide();
214 });
215
216 jQuery('#toolbox-send-credentials-hide').on('click', function () {
217 if (jQuery(this).prop('checked'))
218 jQuery('#wppb-toolbox-send-credentials-text').hide();
219 else
220 jQuery('#wppb-toolbox-send-credentials-text').css('display','flex');
221 });
222
223 jQuery('#toolbox-redirect-if-empty-required').on('click', function () {
224 if (jQuery(this).prop('checked'))
225 jQuery('#wppb-toolbox-redirect-if-empty-required-url').css('display','flex');
226 else
227 jQuery('#wppb-toolbox-redirect-if-empty-required-url').hide();
228 });
229
230 jQuery('#wppb-color-switcher').on('click', function () {
231 if (jQuery(this).prop('checked'))
232 jQuery('.wppb-color-switcher-section').css('display','flex');
233 else
234 jQuery('.wppb-color-switcher-section').hide();
235 });
236
237
238 if (jQuery('.wppb-toolbox-switch').prop('checked'))
239 jQuery('.wppb-toolbox-accordion').css('display','flex');
240
241 if (jQuery('#toolbox-send-credentials-hide').prop('checked'))
242 jQuery('#wppb-toolbox-send-credentials-text').hide();
243
244 if (jQuery('#toolbox-redirect-if-empty-required').prop('checked'))
245 jQuery('#wppb-toolbox-redirect-if-empty-required-url').css('display','flex');
246
247 if (jQuery('#wppb-color-switcher').prop('checked'))
248 jQuery('.wppb-color-switcher-section').css('display','flex');
249 else
250 jQuery('.wppb-color-switcher-section').hide();
251
252 // Color Switcher - Notifications Background
253 var activeDesign = jQuery('.color-switcher').data('active-design');
254
255 if ( activeDesign === 'form-style-1' ) {
256 jQuery('.wppb-form-style-1-fields').show();
257 jQuery('.wppb-other-style-fields').hide();
258 } else {
259 jQuery('.wppb-form-style-1-fields').hide();
260 jQuery('.wppb-other-style-fields').show();
261 }
262 }
263 });
264
265 // Fix for Select2 search not focusing
266 jQuery(document).on('select2:open', function() {
267 let allSelect2Found = document.querySelectorAll('.select2-container--open .select2-search__field');
268 allSelect2Found[allSelect2Found.length - 1].focus();
269 });
270
271 /**
272 * Add Link to PB Docs next to page/setting titles
273 * */
274 jQuery(document).ready( function () {
275 // email customizer
276 jQuery('.wp-admin.profile-builder_page_user-email-customizer .wrap h2.cozmoslabs-page-title').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-email-customizer/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
277 jQuery('.wp-admin.profile-builder_page_admin-email-customizer .wrap h2.cozmoslabs-page-title').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/admin-email-customizer/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
278
279 // roles editor
280 jQuery('.wp-admin.post-type-wppb-roles-editor .wrap h1.wp-heading-inline').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/general-settings/roles-editor/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
281
282 // manage form fields
283 jQuery('.wp-admin.profile-builder_page_manage-fields .wrap > h2').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/manage-user-fields/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
284 jQuery('html').on('wpbFormMetaLoaded', function() {
285 // conditional logic
286 jQuery('.wp-admin.profile-builder_page_manage-fields .update_container_wppb_manage_fields ul.mb-list-entry-fields li.row-conditional-logic-enabled .mb-right-column label').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/manage-user-fields/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Conditional_Logic" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 10px"></a>');
287 // visibility
288 jQuery('.wp-admin.profile-builder_page_manage-fields .update_container_wppb_manage_fields ul.mb-list-entry-fields li.row-visibility .mb-right-column').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/field-visibility/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Visibility" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 10px"></a>');
289 // user role visibility
290 jQuery('.wp-admin.profile-builder_page_manage-fields .update_container_wppb_manage_fields ul.mb-list-entry-fields li.row-user-role-visibility .mb-right-column .wck-checkboxes').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/field-visibility/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#User_Role_Visibility" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
291 // location visibility
292 jQuery('.wp-admin.profile-builder_page_manage-fields .update_container_wppb_manage_fields ul.mb-list-entry-fields li.row-location-visibility .mb-right-column .wck-checkboxes').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/field-visibility/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Location_Visibility" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
293 // admin approval
294 jQuery('.wp-admin.profile-builder_page_manage-fields .update_container_wppb_manage_fields ul.mb-list-entry-fields li.row-edit-profile-approved-by-admin .mb-right-column .wck-checkboxes label').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/edit-profile-approved-by-admin/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 10px"></a>');
295 });
296
297 // register forms
298 jQuery('.wp-admin.post-type-wppb-rf-cpt .wrap h1.wp-heading-inline').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/multiple-registration-forms/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
299
300 // edit profile forms
301 jQuery('.wp-admin.post-type-wppb-epf-cpt .wrap h1.wp-heading-inline').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/multiple-edit-profile-forms/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
302
303 // user-listing
304 jQuery('.wp-admin.post-type-wppb-ul-cpt .wrap h1.wp-heading-inline').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-listing/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
305 // ul settings
306 jQuery('.wp-admin.post-type-wppb-ul-cpt #wppb_ul_page_settings').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-listing/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#User_Listing_Settings" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
307 // ul faceted menus
308 jQuery('.wp-admin.post-type-wppb-ul-cpt #wppb_ul_faceted_settings').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-listing/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Faceted_Menus" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
309 // ul search settings
310 jQuery('.wp-admin.post-type-wppb-ul-cpt #wppb_ul_search_settings').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-listing/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Search_Settings" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
311 // ul themes
312 jQuery('.wp-admin.post-type-wppb-ul-cpt #wppb-ul-themes-settings .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-listing/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Themes" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
313 // ul all users template
314 jQuery('.wp-admin.post-type-wppb-ul-cpt #wppb-ul-templates .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-listing/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#The_All-Userlisting_Template" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
315 // ul single user template
316 jQuery('.wp-admin.post-type-wppb-ul-cpt #wppb-single-ul-templates .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/user-listing/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#The_Single-Userlisting_Template" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
317
318 // custom redirects
319 jQuery('.wp-admin.profile-builder_page_custom-redirects .wrap h2.cozmoslabs-page-title').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/custom-redirects/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
320 // cr individual user
321 jQuery('.wp-admin.profile-builder_page_custom-redirects #wppb_custom_redirects_user .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/custom-redirects/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Individual_User_Redirects" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
322 // cr user role based
323 jQuery('.wp-admin.profile-builder_page_custom-redirects #wppb_custom_redirects_role .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/custom-redirects/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#User_Role_based_Redirects" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
324 // cr global
325 jQuery('.wp-admin.profile-builder_page_custom-redirects #wppb_custom_redirects_global .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/custom-redirects/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Global_Redirects" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
326 // cr default wp pages
327 jQuery('.wp-admin.profile-builder_page_custom-redirects #wppb_custom_redirects_default_wp_pages .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/modules/custom-redirects/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs#Redirect_Default_WordPress_Forms_and_Pages" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
328
329 // social connect
330 jQuery('.wp-admin.profile-builder_page_wppb-social-connect .wrap h2.cozmoslabs-page-title').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/social-connect/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
331
332 // multi-step forms
333 jQuery('.wp-admin.profile-builder_page_manage-fields #wppb-msf-side .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/multi-step-forms/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
334
335 // form fields in columns
336 jQuery('.wp-admin.profile-builder_page_manage-fields #wppb-ffc-side .inside').prepend('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/form-fields-in-columns/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>');
337
338 // labels edit
339 jQuery('.wp-admin.profile-builder_page_pb-labels-edit .wrap h2.cozmoslabs-page-title').append('<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/labels-edit/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px"></a>');
340 });
341
342
343 /**
344 * Documentation links popup
345 */
346 jQuery( function() {
347 if ( ! jQuery.fn.dialog ) {
348 return;
349 }
350
351 const $docsLinkPopup = jQuery('#wppb-docs-link-popup');
352
353 if ( ! $docsLinkPopup.length ) {
354 return;
355 }
356
357 $docsLinkPopup.dialog({
358 autoOpen: false,
359 modal: true,
360 draggable: false,
361 resizable: false,
362 width: 480,
363 dialogClass: 'wppb-docs-link-popup-dialog'
364 });
365
366 jQuery(document).on('click', 'a.wppb-docs-link', function (e) {
367 const docsUrl = jQuery(this).attr('href');
368
369 if ( ! docsUrl ) {
370 return;
371 }
372
373 e.preventDefault();
374
375 $docsLinkPopup.find('.wppb-docs-link-popup-open-docs').attr('href', docsUrl);
376
377 $docsLinkPopup.dialog('open');
378 });
379
380 $docsLinkPopup.on('click', '.wppb-docs-link-popup-open-docs, .wppb-docs-link-popup-open-wporg', function () {
381 $docsLinkPopup.dialog('close');
382 });
383 });
384
385
386 /**
387 * Initialize Select2
388 *
389 * */
390 jQuery(document).ready(function() {
391 if ( typeof jQuery.fn.select2 === 'function') {
392 if (jQuery('.wppb-select2').is('#toolbox-restricted-words-data')) {
393 jQuery('.wppb-select2').select2({
394 tags: true,
395 });
396 }
397 else jQuery('.wppb-select2').select2();
398 }
399 });
400
401
402 /**
403 * Form Designs Feature --> Admin UI
404 *
405 * - Activate new Design
406 * - Preview Modal
407 * - Modal Image Slider controls
408 *
409 * */
410
411 jQuery( document ).ready(function(){
412
413 jQuery('.wppb-forms-design-preview').click(function (e) {
414 let themeID = e.target.id.replace('-info', '');
415 displayDesignPreviewModal(themeID);
416 });
417
418 jQuery('.wppb-slideshow-button').click(function (e) {
419 let themeID = jQuery(e.target).data('theme-id'),
420 direction = jQuery(e.target).data('slideshow-direction'),
421 currentSlide = jQuery('#modal-' + themeID + ' .wppb-forms-design-preview-image.active'),
422 changeSlideshowImage = window[direction+'SlideshowImage'];
423
424 changeSlideshowImage(currentSlide,themeID);
425 });
426
427 });
428
429 function displayDesignPreviewModal( themeID ) {
430 jQuery('#modal-' + themeID).dialog({
431 resizable: false,
432 height: 'auto',
433 width: 1200,
434 modal: true,
435 closeOnEscape: true,
436 open: function () {
437 jQuery('.ui-widget-overlay').bind('click',function () {
438 jQuery('#modal-' + themeID).dialog('close');
439 })
440 },
441 close: function () {
442 let allImages = jQuery('.wppb-forms-design-preview-image');
443
444 allImages.each( function() {
445 if ( jQuery(this).is(':first-child') && !jQuery(this).hasClass('active') ) {
446 jQuery(this).addClass('active');
447 }
448 else if ( !jQuery(this).is(':first-child') ) {
449 jQuery(this).removeClass('active');
450 }
451 });
452
453 jQuery('.wppb-forms-design-sildeshow-previous').addClass('disabled');
454 jQuery('.wppb-forms-design-sildeshow-next').removeClass('disabled');
455 }
456 });
457 return false;
458 }
459
460 function nextSlideshowImage( currentSlide, themeID ){
461 if ( currentSlide.next().length > 0 ) {
462 currentSlide.removeClass('active');
463 currentSlide.next().addClass('active');
464
465 jQuery('#modal-' + themeID + ' .wppb-forms-design-sildeshow-previous').removeClass('disabled');
466
467 if ( currentSlide.next().next().length <= 0 )
468 jQuery('#modal-' + themeID + ' .wppb-forms-design-sildeshow-next').addClass('disabled');
469
470 }
471 }
472
473 function previousSlideshowImage( currentSlide, themeID ){
474 if ( currentSlide.prev().length > 0 ) {
475 currentSlide.removeClass('active');
476 currentSlide.prev().addClass('active');
477
478 jQuery('#modal-' + themeID + ' .wppb-forms-design-sildeshow-next').removeClass('disabled');
479
480 if ( currentSlide.prev().prev().length <= 0 )
481 jQuery('#modal-' + themeID + ' .wppb-forms-design-sildeshow-previous').addClass('disabled');
482
483 }
484 }
485
486
487 /**
488 * Hide/Show Roles Selector
489 *
490 * */
491 jQuery(document).ready(function() {
492 let input = jQuery('input#wppb-auth-enable'),
493 rolesSelector = jQuery('#wppb-auth-roles-selector');
494
495 input.click(function (e) {
496 rolesSelector.toggle();
497 });
498
499 // Upgrade notice in PB Free Version
500 jQuery('input#wppb-2fa-enable').click(function (e) {
501 jQuery('#wppb-2fa-upgrade-notice').toggle();
502 });
503
504 });
505
506
507 /**
508 * Handle Admin Dashboard Publish Box/Button position
509 *
510 */
511 jQuery(window).on('load', function () {
512
513 // limit Publish Box/Button positioning to Profile Builder Custom Pages and CPTs
514 if (jQuery('body').is('[class*="profile-builder_page"], [class*="admin_page_profile-builder"], [class*="post-type-wppb"]')) {
515
516 handlePublishBoxPosition();
517
518 // Reset the scroll event on manual window resize to keep the Publish button scrollable without refreshing
519 jQuery(window).on('resize', function() {
520
521 // clear existing scroll events
522 jQuery(window).off('scroll');
523
524 handlePublishBoxPosition();
525 });
526
527 }
528
529 });
530
531
532 /**
533 * Reposition the Publish Box/Button in Admin Dashboard
534 * - PMS CPTs
535 * - Custom Pages
536 *
537 */
538 function handlePublishBoxPosition() {
539 let largeScreen = window.matchMedia("(min-width: 1402px)"),
540 settingsContainer = jQuery('#wppb-register-version'),
541 buttonContainer = jQuery('.cozmoslabs-submit');
542
543 if ( settingsContainer.length === 0 ){
544 settingsContainer = jQuery( '.cozmoslabs-settings' );
545 }
546
547 // determine if we are on a PMS Custom Page or CPT
548 if ( settingsContainer.length === 0 ) {
549 settingsContainer = jQuery('#poststuff');
550 buttonContainer = jQuery('#submitdiv');
551 }
552
553 if ( settingsContainer.length > 0 && buttonContainer.length > 0 ) {
554
555 if ( largeScreen.matches )
556 wppbRepositionPublishMetaBox( settingsContainer, buttonContainer );
557 else wppbRepositionPublishButton( buttonContainer );
558
559 }
560 }
561
562 /**
563 * Reposition Publish Meta-Box
564 * - PMS CPTs
565 * - Custom Pages
566 *
567 * - works on large screens
568 *
569 * */
570 function wppbRepositionPublishMetaBox( settingsContainer, buttonContainer ) {
571
572 buttonContainer.removeClass('cozmoslabs-publish-button-fixed');
573
574 if ( buttonContainer.length > 0 ) {
575
576 // set initial position
577 wppbSetPublishMetaBoxPosition();
578
579 // reposition on scroll
580 jQuery(window).scroll(function () {
581 wppbSetPublishMetaBoxPosition();
582 });
583
584 }
585
586 /**
587 * Position the Publish Meta-Box
588 */
589 function wppbSetPublishMetaBoxPosition() {
590
591 if ( wppbCalculateDistanceToTop( settingsContainer ) < 50 ) {
592 buttonContainer.addClass('cozmoslabs-publish-metabox-fixed');
593
594 buttonContainer.css({
595 'left' : settingsContainer.offset().left + settingsContainer.outerWidth() + 'px'
596 });
597 } else {
598
599 buttonContainer.removeClass('cozmoslabs-publish-metabox-fixed');
600
601 buttonContainer.css({
602 'left' : 'unset'
603 });
604 }
605
606 }
607
608 }
609
610 /**
611 * Reposition Publish Button
612 * - PMS CPTs
613 * - Custom Pages
614 *
615 * - works on small/medium screens
616 *
617 * */
618 function wppbRepositionPublishButton( buttonContainer ) {
619
620 buttonContainer.removeClass('cozmoslabs-publish-metabox-fixed');
621
622 if ( buttonContainer.length > 0 ) {
623
624 // set initial position
625 wppbSetPublishButtonPosition();
626
627 // reposition on scroll
628 jQuery(window).on('scroll', function() {
629 wppbSetPublishButtonPosition();
630 });
631
632 }
633
634 /**
635 * Position the Publish Button
636 */
637 function wppbSetPublishButtonPosition() {
638
639 let button = buttonContainer.find('input[type="submit"]');
640
641 if ( wppbElementInViewport( buttonContainer ) ) {
642 buttonContainer.removeClass('cozmoslabs-publish-button-fixed');
643
644 button.css({
645 'max-width': 'unset',
646 'left': 'unset',
647 });
648 }
649 else {
650 buttonContainer.addClass('cozmoslabs-publish-button-fixed');
651
652 button.css({
653 'max-width': buttonContainer.outerWidth() + 'px',
654 'left': buttonContainer.offset().left + 'px',
655 });
656 }
657 }
658 }
659
660
661 /**
662 * Calculate the distance to Top for a specific element
663 *
664 * */
665 function wppbCalculateDistanceToTop(element) {
666 let scrollTop = jQuery(window).scrollTop(),
667 elementOffset = element.offset().top;
668
669 return elementOffset - scrollTop;
670 }
671
672
673 /**
674 * Check if a specific element is visible on screen
675 *
676 * */
677 function wppbElementInViewport(element) {
678 let elementTop = element.offset().top,
679 elementBottom = elementTop + element.outerHeight(),
680 viewportTop = jQuery(window).scrollTop(),
681 viewportBottom = viewportTop + jQuery(window).height();
682
683 return elementBottom > viewportTop && elementTop < viewportBottom;
684 }
685
686
687
688 /**
689 * Display initially hidden admin notices, after the scripts have loaded
690 *
691 * */
692 jQuery( document ).ready(function(){
693
694 let noticeTypes = [
695 ".error",
696 ".notice"
697 ];
698
699 noticeTypes.forEach(function(notice){
700 let selector = "body[class*='builder_page_'] " + notice + ", " + "body[class*='post-type-wppb-'] " + notice;
701
702 jQuery(selector).each(function () {
703 jQuery(this).css('display', 'block');
704 });
705 });
706
707 });
708
709
710 /**
711 * Function that copies the shortcode from an input
712 *
713 * */
714 jQuery(document).ready(function() {
715 jQuery('.wppb-shortcode_copy').click(function (e) {
716
717 e.preventDefault();
718
719 navigator.clipboard.writeText(jQuery(this).val());
720
721 // Show copy message
722 var copyMessage = jQuery(this).next('.wppb-copy-message');
723 copyMessage.fadeIn(400).delay(2000).fadeOut(400);
724
725 })
726 });
727
728
729 /**
730 * Function that copies the shortcode from a text
731 *
732 * */
733 jQuery(document).ready(function() {
734 jQuery('.wppb-shortcode_copy-text').click(function (e) {
735
736 e.preventDefault();
737
738 navigator.clipboard.writeText(jQuery(this).text());
739
740 // Show copy message
741 var copyMessage = jQuery(this).next('.wppb-copy-message');
742 copyMessage.fadeIn(400).delay(2000).fadeOut(400);
743
744 })
745 });
746
747
748 /**
749 * Handle extra post meta cleanup
750 *
751 * - wppb_sc_rf_epf_active
752 * - wppb-content-restrict-message-purchasing_restricted
753 * - wppb-ul-active-theme
754 * - wppb-ul-default-single-user-template
755 * - wppb-ul-default-all-user-template
756 *
757 */
758 jQuery(document).ready(function() {
759 jQuery('.wppb-cleanup-postmeta').click(function (e) {
760 e.preventDefault();
761
762 let $button = jQuery(this);
763 let originalText = $button.text();
764
765 $button.prop('disabled', true).text('Cleaning...');
766
767 // Function to handle cleanup process
768 function processCleanup(step = 1) {
769 jQuery.post( ajaxurl, {
770 action: 'wppb_cleanup_postmeta',
771 nonce : $button.data('nonce'),
772 step : step
773 }, function( response ) {
774 if( response.success ) {
775 if( response.data.step === 'done' ) {
776
777 $button.text('Cleanup Complete!');
778
779 // If cleanup is complete, hide the button after showing completion message
780 if( response.data.hide_button ) {
781 setTimeout(function() {
782 let wrapper = jQuery($button).closest('.cozmoslabs-form-field-wrapper')
783
784 wrapper.fadeOut(400, function() {
785 jQuery(this).remove();
786 });
787 }, 2000);
788 } else {
789 setTimeout(function() {
790 $button.text(originalText).prop('disabled', false);
791 }, 2000);
792 }
793
794 } else {
795 processCleanup(response.data.step);
796 }
797 } else {
798 $button.text('Error occurred').prop('disabled', false);
799 setTimeout(function() {
800 $button.text(originalText);
801 }, 2000);
802 }
803 }).fail(function() {
804 $button.text('Error occurred').prop('disabled', false);
805 setTimeout(function() {
806 $button.text(originalText);
807 }, 2000);
808 });
809 }
810
811 // Start the cleanup process
812 processCleanup();
813
814 })
815 });
816
817
818 /**
819 * Prevent Email Customizer meta-boxes from being moved into the side section
820 *
821 */
822 jQuery(function () {
823
824 if ( pagenow !== 'profile-builder_page_user-email-customizer' && pagenow !== 'profile-builder_page_admin-email-customizer' )
825 return;
826
827 function handleDownArrows() {
828
829 // reset all down arrows
830 jQuery('.cozmoslabs-email-customizer-section .meta-box-sortables .postbox button.handle-order-lower').attr('aria-disabled', 'false');
831
832 // disable the last down arrow in the main area
833 jQuery('.cozmoslabs-email-customizer-section #advanced-sortables .postbox:last-of-type button.handle-order-lower').attr('aria-disabled', 'true');
834
835 }
836
837 handleDownArrows();
838
839 // handle down arrows after meta-boxes order change
840 jQuery('.handle-order-lower, .handle-order-higher').on('click', handleDownArrows);
841
842 });
843
844
845 /**
846 * Handle the Profile Builder deactivation popup on the Plugins page
847 *
848 * - intercepts the plugin deactivation link
849 * - validates and stores the selected reason through AJAX before redirecting
850 *
851 */
852 jQuery(function () {
853
854 if ( typeof jQuery.fn.dialog !== 'function' )
855 return;
856
857 const $popup = jQuery('#wppb-deactivation-popup');
858
859 if ( $popup.length === 0 )
860 return;
861
862 const $form = $popup.find('.wppb-deactivation-popup-form');
863 const $error = $popup.find('.wppb-deactivation-popup-error');
864 const $actionButtons = $popup.find('.wppb-deactivation-popup-confirm, .wppb-deactivation-popup-skip');
865 const pluginBasename = $popup.data('plugin');
866 let deactivateLink = '';
867 let isRedirecting = false;
868
869 $actionButtons.each(function () {
870 const $btn = jQuery(this);
871 $btn.data('wppbOriginalText', $btn.text().trim());
872 });
873
874 function resetActionButtons() {
875 $actionButtons.each(function () {
876 const $btn = jQuery(this);
877 const original = $btn.data('wppbOriginalText');
878 if (original !== undefined) {
879 $btn.text(original);
880 }
881 $btn.prop('disabled', false);
882 });
883 }
884
885 $popup.dialog({
886 autoOpen: false,
887 modal: true,
888 draggable: false,
889 resizable: false,
890 width: 480
891 });
892
893 function setError(message) {
894 if (!message) {
895 $error.hide().text('');
896 jQuery('.wppb-deactivation-popup-extra').removeClass('error');
897 return;
898 }
899
900 $error.text(message).show();
901 jQuery('.wppb-deactivation-popup-extra').addClass('error');
902 }
903
904 function toggleExtraFields() {
905 const selectedReason = $form.find('input[name="wppb_deactivation_reason"]:checked').val() || '';
906
907 $form.find('.wppb-deactivation-popup-extra').each(function () {
908 const $input = jQuery(this);
909 const shouldShow = $input.data('reason') === selectedReason;
910
911 $input.toggle(shouldShow);
912
913 if (!shouldShow) {
914 $input.val('');
915 }
916 });
917 }
918
919 function getPayload(reasonOverride) {
920 const payload = {
921 action: 'wppb_store_deactivation_reason',
922 nonce: (window.wppbDeactivationData && window.wppbDeactivationData.deactivationReasonNonce) ? window.wppbDeactivationData.deactivationReasonNonce : '',
923 reason: reasonOverride || ($form.find('input[name="wppb_deactivation_reason"]:checked').val() || '')
924 };
925
926 $form.find('.wppb-deactivation-popup-extra').each(function () {
927 const $input = jQuery(this);
928
929 if ($input.val()) {
930 payload[$input.attr('name')] = $input.val();
931 }
932 });
933
934 return payload;
935 }
936
937 function validatePayload(payload) {
938 if (payload.reason === 'skip') {
939 return true;
940 }
941
942 if (!payload.reason) {
943 setError(window.wppbDeactivationData ? window.wppbDeactivationData.deactivationReasonRequired : '');
944 return false;
945 }
946
947 if (
948 (payload.reason === 'switched_to_another_plugin' && !payload.switched_to_another_plugin_reason) ||
949 (payload.reason === 'missing_features' && !payload.missing_features_reason) ||
950 (payload.reason === 'other' && !payload.other_reason)
951 ) {
952 setError(window.wppbDeactivationData ? window.wppbDeactivationData.deactivationReasonInput : '');
953 return false;
954 }
955
956 setError('');
957 return true;
958 }
959
960 function submitReason(payload, $triggerButton) {
961 if (!validatePayload(payload) || !deactivateLink || isRedirecting) {
962 return;
963 }
964
965 isRedirecting = true;
966
967 if ($triggerButton && $triggerButton.length) {
968 $triggerButton.text('Deactivating...');
969 }
970 $actionButtons.prop('disabled', true);
971
972 jQuery.post(ajaxurl, payload)
973 .done(function () {
974 window.location.href = deactivateLink;
975 })
976 .fail(function () {
977 isRedirecting = false;
978 resetActionButtons();
979 setError(window.wppbDeactivationData ? window.wppbDeactivationData.deactivationReasonSaveError : '');
980 });
981 }
982
983 jQuery(document).on('click', 'tr[data-plugin="' + pluginBasename + '"] .deactivate a', function (e) {
984 e.preventDefault();
985 e.stopPropagation();
986
987 deactivateLink = jQuery(this).attr('href');
988 isRedirecting = false;
989 resetActionButtons();
990 $form[0].reset();
991 toggleExtraFields();
992 setError('');
993 $popup.dialog('open');
994 });
995
996 $form.on('change', 'input[name="wppb_deactivation_reason"]', function () {
997 toggleExtraFields();
998 setError('');
999 });
1000
1001 $popup.on('click', '.wppb-deactivation-popup-confirm', function (e) {
1002 e.preventDefault();
1003 submitReason(getPayload(), jQuery(this));
1004 });
1005
1006 $popup.on('click', '.wppb-deactivation-popup-skip', function (e) {
1007 e.preventDefault();
1008 submitReason(getPayload('skip'), jQuery(this));
1009 });
1010 });
1011