| 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 |
}); |
| 500 |
|
| 501 |
|
| 502 |
/** |
| 503 |
* Handle Admin Dashboard Publish Box/Button position |
| 504 |
* |
| 505 |
*/ |
| 506 |
jQuery(window).on('load', function () { |
| 507 |
|
| 508 |
// limit Publish Box/Button positioning to Profile Builder Custom Pages and CPTs |
| 509 |
if (jQuery('body').is('[class*="profile-builder_page"], [class*="admin_page_profile-builder"], [class*="post-type-wppb"]')) { |
| 510 |
|
| 511 |
handlePublishBoxPosition(); |
| 512 |
|
| 513 |
// Reset the scroll event on manual window resize to keep the Publish button scrollable without refreshing |
| 514 |
jQuery(window).on('resize', function() { |
| 515 |
|
| 516 |
// clear existing scroll events |
| 517 |
jQuery(window).off('scroll'); |
| 518 |
|
| 519 |
handlePublishBoxPosition(); |
| 520 |
}); |
| 521 |
|
| 522 |
} |
| 523 |
|
| 524 |
}); |
| 525 |
|
| 526 |
|
| 527 |
/** |
| 528 |
* Reposition the Publish Box/Button in Admin Dashboard |
| 529 |
* - PMS CPTs |
| 530 |
* - Custom Pages |
| 531 |
* |
| 532 |
*/ |
| 533 |
function handlePublishBoxPosition() { |
| 534 |
let largeScreen = window.matchMedia("(min-width: 1402px)"), |
| 535 |
settingsContainer = jQuery('#wppb-register-version'), |
| 536 |
buttonContainer = jQuery('.cozmoslabs-submit'); |
| 537 |
|
| 538 |
if ( settingsContainer.length === 0 ){ |
| 539 |
settingsContainer = jQuery( '.cozmoslabs-settings' ); |
| 540 |
} |
| 541 |
|
| 542 |
// determine if we are on a PMS Custom Page or CPT |
| 543 |
if ( settingsContainer.length === 0 ) { |
| 544 |
settingsContainer = jQuery('#poststuff'); |
| 545 |
buttonContainer = jQuery('#submitdiv'); |
| 546 |
} |
| 547 |
|
| 548 |
if ( settingsContainer.length > 0 && buttonContainer.length > 0 ) { |
| 549 |
|
| 550 |
if ( largeScreen.matches ) |
| 551 |
wppbRepositionPublishMetaBox( settingsContainer, buttonContainer ); |
| 552 |
else wppbRepositionPublishButton( buttonContainer ); |
| 553 |
|
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
/** |
| 558 |
* Reposition Publish Meta-Box |
| 559 |
* - PMS CPTs |
| 560 |
* - Custom Pages |
| 561 |
* |
| 562 |
* - works on large screens |
| 563 |
* |
| 564 |
* */ |
| 565 |
function wppbRepositionPublishMetaBox( settingsContainer, buttonContainer ) { |
| 566 |
|
| 567 |
buttonContainer.removeClass('cozmoslabs-publish-button-fixed'); |
| 568 |
|
| 569 |
if ( buttonContainer.length > 0 ) { |
| 570 |
|
| 571 |
// set initial position |
| 572 |
wppbSetPublishMetaBoxPosition(); |
| 573 |
|
| 574 |
// reposition on scroll |
| 575 |
jQuery(window).scroll(function () { |
| 576 |
wppbSetPublishMetaBoxPosition(); |
| 577 |
}); |
| 578 |
|
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Position the Publish Meta-Box |
| 583 |
*/ |
| 584 |
function wppbSetPublishMetaBoxPosition() { |
| 585 |
|
| 586 |
if ( wppbCalculateDistanceToTop( settingsContainer ) < 50 ) { |
| 587 |
buttonContainer.addClass('cozmoslabs-publish-metabox-fixed'); |
| 588 |
|
| 589 |
buttonContainer.css({ |
| 590 |
'left' : settingsContainer.offset().left + settingsContainer.outerWidth() + 'px' |
| 591 |
}); |
| 592 |
} else { |
| 593 |
|
| 594 |
buttonContainer.removeClass('cozmoslabs-publish-metabox-fixed'); |
| 595 |
|
| 596 |
buttonContainer.css({ |
| 597 |
'left' : 'unset' |
| 598 |
}); |
| 599 |
} |
| 600 |
|
| 601 |
} |
| 602 |
|
| 603 |
} |
| 604 |
|
| 605 |
/** |
| 606 |
* Reposition Publish Button |
| 607 |
* - PMS CPTs |
| 608 |
* - Custom Pages |
| 609 |
* |
| 610 |
* - works on small/medium screens |
| 611 |
* |
| 612 |
* */ |
| 613 |
function wppbRepositionPublishButton( buttonContainer ) { |
| 614 |
|
| 615 |
buttonContainer.removeClass('cozmoslabs-publish-metabox-fixed'); |
| 616 |
|
| 617 |
if ( buttonContainer.length > 0 ) { |
| 618 |
|
| 619 |
// set initial position |
| 620 |
wppbSetPublishButtonPosition(); |
| 621 |
|
| 622 |
// reposition on scroll |
| 623 |
jQuery(window).on('scroll', function() { |
| 624 |
wppbSetPublishButtonPosition(); |
| 625 |
}); |
| 626 |
|
| 627 |
} |
| 628 |
|
| 629 |
/** |
| 630 |
* Position the Publish Button |
| 631 |
*/ |
| 632 |
function wppbSetPublishButtonPosition() { |
| 633 |
|
| 634 |
let button = buttonContainer.find('input[type="submit"]'); |
| 635 |
|
| 636 |
if ( wppbElementInViewport( buttonContainer ) ) { |
| 637 |
buttonContainer.removeClass('cozmoslabs-publish-button-fixed'); |
| 638 |
|
| 639 |
button.css({ |
| 640 |
'max-width': 'unset', |
| 641 |
'left': 'unset', |
| 642 |
}); |
| 643 |
} |
| 644 |
else { |
| 645 |
buttonContainer.addClass('cozmoslabs-publish-button-fixed'); |
| 646 |
|
| 647 |
button.css({ |
| 648 |
'max-width': buttonContainer.outerWidth() + 'px', |
| 649 |
'left': buttonContainer.offset().left + 'px', |
| 650 |
}); |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
/** |
| 657 |
* Calculate the distance to Top for a specific element |
| 658 |
* |
| 659 |
* */ |
| 660 |
function wppbCalculateDistanceToTop(element) { |
| 661 |
let scrollTop = jQuery(window).scrollTop(), |
| 662 |
elementOffset = element.offset().top; |
| 663 |
|
| 664 |
return elementOffset - scrollTop; |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
/** |
| 669 |
* Check if a specific element is visible on screen |
| 670 |
* |
| 671 |
* */ |
| 672 |
function wppbElementInViewport(element) { |
| 673 |
let elementTop = element.offset().top, |
| 674 |
elementBottom = elementTop + element.outerHeight(), |
| 675 |
viewportTop = jQuery(window).scrollTop(), |
| 676 |
viewportBottom = viewportTop + jQuery(window).height(); |
| 677 |
|
| 678 |
return elementBottom > viewportTop && elementTop < viewportBottom; |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
/** |
| 684 |
* Display initially hidden admin notices, after the scripts have loaded |
| 685 |
* |
| 686 |
* */ |
| 687 |
jQuery( document ).ready(function(){ |
| 688 |
|
| 689 |
let noticeTypes = [ |
| 690 |
".error", |
| 691 |
".notice" |
| 692 |
]; |
| 693 |
|
| 694 |
noticeTypes.forEach(function(notice){ |
| 695 |
let selector = "body[class*='builder_page_'] " + notice + ", " + "body[class*='post-type-wppb-'] " + notice; |
| 696 |
|
| 697 |
jQuery(selector).each(function () { |
| 698 |
jQuery(this).css('display', 'block'); |
| 699 |
}); |
| 700 |
}); |
| 701 |
|
| 702 |
}); |
| 703 |
|
| 704 |
|
| 705 |
/** |
| 706 |
* Function that copies the shortcode from an input |
| 707 |
* |
| 708 |
* */ |
| 709 |
jQuery(document).ready(function() { |
| 710 |
jQuery('.wppb-shortcode_copy').click(function (e) { |
| 711 |
|
| 712 |
e.preventDefault(); |
| 713 |
|
| 714 |
navigator.clipboard.writeText(jQuery(this).val()); |
| 715 |
|
| 716 |
// Show copy message |
| 717 |
var copyMessage = jQuery(this).next('.wppb-copy-message'); |
| 718 |
copyMessage.fadeIn(400).delay(2000).fadeOut(400); |
| 719 |
|
| 720 |
}) |
| 721 |
}); |
| 722 |
|
| 723 |
|
| 724 |
/** |
| 725 |
* Function that copies the shortcode from a text |
| 726 |
* |
| 727 |
* */ |
| 728 |
jQuery(document).ready(function() { |
| 729 |
jQuery('.wppb-shortcode_copy-text').click(function (e) { |
| 730 |
|
| 731 |
e.preventDefault(); |
| 732 |
|
| 733 |
navigator.clipboard.writeText(jQuery(this).text()); |
| 734 |
|
| 735 |
// Show copy message |
| 736 |
var copyMessage = jQuery(this).next('.wppb-copy-message'); |
| 737 |
copyMessage.fadeIn(400).delay(2000).fadeOut(400); |
| 738 |
|
| 739 |
}) |
| 740 |
}); |
| 741 |
|
| 742 |
|
| 743 |
/** |
| 744 |
* Handle extra post meta cleanup |
| 745 |
* |
| 746 |
* - wppb_sc_rf_epf_active |
| 747 |
* - wppb-content-restrict-message-purchasing_restricted |
| 748 |
* - wppb-ul-active-theme |
| 749 |
* - wppb-ul-default-single-user-template |
| 750 |
* - wppb-ul-default-all-user-template |
| 751 |
* |
| 752 |
*/ |
| 753 |
jQuery(document).ready(function() { |
| 754 |
jQuery('.wppb-cleanup-postmeta').click(function (e) { |
| 755 |
e.preventDefault(); |
| 756 |
|
| 757 |
let $button = jQuery(this); |
| 758 |
let originalText = $button.text(); |
| 759 |
|
| 760 |
$button.prop('disabled', true).text('Cleaning...'); |
| 761 |
|
| 762 |
// Function to handle cleanup process |
| 763 |
function processCleanup(step = 1) { |
| 764 |
jQuery.post( ajaxurl, { |
| 765 |
action: 'wppb_cleanup_postmeta', |
| 766 |
nonce : $button.data('nonce'), |
| 767 |
step : step |
| 768 |
}, function( response ) { |
| 769 |
if( response.success ) { |
| 770 |
if( response.data.step === 'done' ) { |
| 771 |
|
| 772 |
$button.text('Cleanup Complete!'); |
| 773 |
|
| 774 |
// If cleanup is complete, hide the button after showing completion message |
| 775 |
if( response.data.hide_button ) { |
| 776 |
setTimeout(function() { |
| 777 |
let wrapper = jQuery($button).closest('.cozmoslabs-form-field-wrapper') |
| 778 |
|
| 779 |
wrapper.fadeOut(400, function() { |
| 780 |
jQuery(this).remove(); |
| 781 |
}); |
| 782 |
}, 2000); |
| 783 |
} else { |
| 784 |
setTimeout(function() { |
| 785 |
$button.text(originalText).prop('disabled', false); |
| 786 |
}, 2000); |
| 787 |
} |
| 788 |
|
| 789 |
} else { |
| 790 |
processCleanup(response.data.step); |
| 791 |
} |
| 792 |
} else { |
| 793 |
$button.text('Error occurred').prop('disabled', false); |
| 794 |
setTimeout(function() { |
| 795 |
$button.text(originalText); |
| 796 |
}, 2000); |
| 797 |
} |
| 798 |
}).fail(function() { |
| 799 |
$button.text('Error occurred').prop('disabled', false); |
| 800 |
setTimeout(function() { |
| 801 |
$button.text(originalText); |
| 802 |
}, 2000); |
| 803 |
}); |
| 804 |
} |
| 805 |
|
| 806 |
// Start the cleanup process |
| 807 |
processCleanup(); |
| 808 |
|
| 809 |
}) |
| 810 |
}); |
| 811 |
|
| 812 |
|
| 813 |
/** |
| 814 |
* Prevent Email Customizer meta-boxes from being moved into the side section |
| 815 |
* |
| 816 |
*/ |
| 817 |
jQuery(function () { |
| 818 |
|
| 819 |
if ( pagenow !== 'profile-builder_page_user-email-customizer' && pagenow !== 'profile-builder_page_admin-email-customizer' ) |
| 820 |
return; |
| 821 |
|
| 822 |
function handleDownArrows() { |
| 823 |
|
| 824 |
// reset all down arrows |
| 825 |
jQuery('.cozmoslabs-email-customizer-section .meta-box-sortables .postbox button.handle-order-lower').attr('aria-disabled', 'false'); |
| 826 |
|
| 827 |
// disable the last down arrow in the main area |
| 828 |
jQuery('.cozmoslabs-email-customizer-section #advanced-sortables .postbox:last-of-type button.handle-order-lower').attr('aria-disabled', 'true'); |
| 829 |
|
| 830 |
} |
| 831 |
|
| 832 |
handleDownArrows(); |
| 833 |
|
| 834 |
// handle down arrows after meta-boxes order change |
| 835 |
jQuery('.handle-order-lower, .handle-order-higher').on('click', handleDownArrows); |
| 836 |
|
| 837 |
}); |
| 838 |
|
| 839 |
|
| 840 |
/** |
| 841 |
* Handle the Profile Builder deactivation popup on the Plugins page |
| 842 |
* |
| 843 |
* - intercepts the plugin deactivation link |
| 844 |
* - validates and stores the selected reason through AJAX before redirecting |
| 845 |
* |
| 846 |
*/ |
| 847 |
jQuery(function () { |
| 848 |
|
| 849 |
if ( typeof jQuery.fn.dialog !== 'function' ) |
| 850 |
return; |
| 851 |
|
| 852 |
const $popup = jQuery('#wppb-deactivation-popup'); |
| 853 |
|
| 854 |
if ( $popup.length === 0 ) |
| 855 |
return; |
| 856 |
|
| 857 |
const $form = $popup.find('.wppb-deactivation-popup-form'); |
| 858 |
const $error = $popup.find('.wppb-deactivation-popup-error'); |
| 859 |
const $actionButtons = $popup.find('.wppb-deactivation-popup-confirm, .wppb-deactivation-popup-skip'); |
| 860 |
const pluginBasename = $popup.data('plugin'); |
| 861 |
let deactivateLink = ''; |
| 862 |
let isRedirecting = false; |
| 863 |
|
| 864 |
$actionButtons.each(function () { |
| 865 |
const $btn = jQuery(this); |
| 866 |
$btn.data('wppbOriginalText', $btn.text().trim()); |
| 867 |
}); |
| 868 |
|
| 869 |
function resetActionButtons() { |
| 870 |
$actionButtons.each(function () { |
| 871 |
const $btn = jQuery(this); |
| 872 |
const original = $btn.data('wppbOriginalText'); |
| 873 |
if (original !== undefined) { |
| 874 |
$btn.text(original); |
| 875 |
} |
| 876 |
$btn.prop('disabled', false); |
| 877 |
}); |
| 878 |
} |
| 879 |
|
| 880 |
$popup.dialog({ |
| 881 |
autoOpen: false, |
| 882 |
modal: true, |
| 883 |
draggable: false, |
| 884 |
resizable: false, |
| 885 |
width: 480 |
| 886 |
}); |
| 887 |
|
| 888 |
function setError(message) { |
| 889 |
if (!message) { |
| 890 |
$error.hide().text(''); |
| 891 |
jQuery('.wppb-deactivation-popup-extra').removeClass('error'); |
| 892 |
return; |
| 893 |
} |
| 894 |
|
| 895 |
$error.text(message).show(); |
| 896 |
jQuery('.wppb-deactivation-popup-extra').addClass('error'); |
| 897 |
} |
| 898 |
|
| 899 |
function toggleExtraFields() { |
| 900 |
const selectedReason = $form.find('input[name="wppb_deactivation_reason"]:checked').val() || ''; |
| 901 |
|
| 902 |
$form.find('.wppb-deactivation-popup-extra').each(function () { |
| 903 |
const $input = jQuery(this); |
| 904 |
const shouldShow = $input.data('reason') === selectedReason; |
| 905 |
|
| 906 |
$input.toggle(shouldShow); |
| 907 |
|
| 908 |
if (!shouldShow) { |
| 909 |
$input.val(''); |
| 910 |
} |
| 911 |
}); |
| 912 |
} |
| 913 |
|
| 914 |
function getPayload(reasonOverride) { |
| 915 |
const payload = { |
| 916 |
action: 'wppb_store_deactivation_reason', |
| 917 |
nonce: (window.wppbDeactivationData && window.wppbDeactivationData.deactivationReasonNonce) ? window.wppbDeactivationData.deactivationReasonNonce : '', |
| 918 |
reason: reasonOverride || ($form.find('input[name="wppb_deactivation_reason"]:checked').val() || '') |
| 919 |
}; |
| 920 |
|
| 921 |
$form.find('.wppb-deactivation-popup-extra').each(function () { |
| 922 |
const $input = jQuery(this); |
| 923 |
|
| 924 |
if ($input.val()) { |
| 925 |
payload[$input.attr('name')] = $input.val(); |
| 926 |
} |
| 927 |
}); |
| 928 |
|
| 929 |
return payload; |
| 930 |
} |
| 931 |
|
| 932 |
function validatePayload(payload) { |
| 933 |
if (payload.reason === 'skip') { |
| 934 |
return true; |
| 935 |
} |
| 936 |
|
| 937 |
if (!payload.reason) { |
| 938 |
setError(window.wppbDeactivationData ? window.wppbDeactivationData.deactivationReasonRequired : ''); |
| 939 |
return false; |
| 940 |
} |
| 941 |
|
| 942 |
if ( |
| 943 |
(payload.reason === 'switched_to_another_plugin' && !payload.switched_to_another_plugin_reason) || |
| 944 |
(payload.reason === 'missing_features' && !payload.missing_features_reason) || |
| 945 |
(payload.reason === 'other' && !payload.other_reason) |
| 946 |
) { |
| 947 |
setError(window.wppbDeactivationData ? window.wppbDeactivationData.deactivationReasonInput : ''); |
| 948 |
return false; |
| 949 |
} |
| 950 |
|
| 951 |
setError(''); |
| 952 |
return true; |
| 953 |
} |
| 954 |
|
| 955 |
function submitReason(payload, $triggerButton) { |
| 956 |
if (!validatePayload(payload) || !deactivateLink || isRedirecting) { |
| 957 |
return; |
| 958 |
} |
| 959 |
|
| 960 |
isRedirecting = true; |
| 961 |
|
| 962 |
if ($triggerButton && $triggerButton.length) { |
| 963 |
$triggerButton.text('Deactivating...'); |
| 964 |
} |
| 965 |
$actionButtons.prop('disabled', true); |
| 966 |
|
| 967 |
jQuery.post(ajaxurl, payload) |
| 968 |
.done(function () { |
| 969 |
window.location.href = deactivateLink; |
| 970 |
}) |
| 971 |
.fail(function () { |
| 972 |
isRedirecting = false; |
| 973 |
resetActionButtons(); |
| 974 |
setError(window.wppbDeactivationData ? window.wppbDeactivationData.deactivationReasonSaveError : ''); |
| 975 |
}); |
| 976 |
} |
| 977 |
|
| 978 |
jQuery(document).on('click', 'tr[data-plugin="' + pluginBasename + '"] .deactivate a', function (e) { |
| 979 |
e.preventDefault(); |
| 980 |
e.stopPropagation(); |
| 981 |
|
| 982 |
deactivateLink = jQuery(this).attr('href'); |
| 983 |
isRedirecting = false; |
| 984 |
resetActionButtons(); |
| 985 |
$form[0].reset(); |
| 986 |
toggleExtraFields(); |
| 987 |
setError(''); |
| 988 |
$popup.dialog('open'); |
| 989 |
}); |
| 990 |
|
| 991 |
$form.on('change', 'input[name="wppb_deactivation_reason"]', function () { |
| 992 |
toggleExtraFields(); |
| 993 |
setError(''); |
| 994 |
}); |
| 995 |
|
| 996 |
$popup.on('click', '.wppb-deactivation-popup-confirm', function (e) { |
| 997 |
e.preventDefault(); |
| 998 |
submitReason(getPayload(), jQuery(this)); |
| 999 |
}); |
| 1000 |
|
| 1001 |
$popup.on('click', '.wppb-deactivation-popup-skip', function (e) { |
| 1002 |
e.preventDefault(); |
| 1003 |
submitReason(getPayload('skip'), jQuery(this)); |
| 1004 |
}); |
| 1005 |
}); |
| 1006 |
|