upskill-event-manager/assets/js/feedback.js
Ben Reed cdc5ea85f4 feat: Add comprehensive CSS, JavaScript and theme asset infrastructure
Add massive collection of CSS, JavaScript and theme assets that were previously excluded:

**CSS Files (681 total):**
- HVAC plugin-specific styles (hvac-*.css): 34 files including dashboard, certificates, registration, mobile nav, accessibility fixes, animations, and welcome popup
- Theme framework files (Astra, builder systems, layouts): 200+ files
- Plugin compatibility styles (WooCommerce, WPForms, Elementor, Contact Form 7): 150+ files
- WordPress core and editor styles: 50+ files
- Responsive and RTL language support: 200+ files

**JavaScript Files (400+ total):**
- HVAC plugin functionality (hvac-*.js): 27 files including menu systems, dashboard enhancements, profile sharing, mobile responsive features, accessibility, and animations
- Framework and library files: jQuery plugins, GSAP, AOS, Swiper, Chart.js, Lottie, Isotope
- Plugin compatibility scripts: WPForms, WooCommerce, Elementor, Contact Form 7, LifterLMS
- WordPress core functionality: customizer, admin, block editor compatibility
- Third-party integrations: Stripe, SMTP, analytics, search functionality

**Assets:**
- Certificate background images and logos
- Comprehensive theme styling infrastructure
- Mobile-responsive design systems
- Cross-browser compatibility assets
- Performance-optimized minified versions

**Updated .gitignore:**
- Fixed asset directory whitelisting patterns to properly include CSS/JS/images
- Added proper directory structure recognition (!/assets/css/, !/assets/js/, etc.)
- Maintains security by excluding sensitive files while including essential assets

This commit provides the complete frontend infrastructure needed for:
- Full theme functionality and styling
- Plugin feature implementations
- Mobile responsiveness and accessibility
- Cross-browser compatibility
- Performance optimization
- Developer workflow support
2025-08-11 16:20:31 -03:00

237 lines
6.7 KiB
JavaScript

( function ( $ ) {
const UserDeactivationPopup = {
slug: '',
skipButton: '',
formWrapper: '',
radioButton: '',
closeButton: '',
buttonAction: '',
feedbackForm: '',
feedbackInput: '',
deactivateUrl: '',
buttonTrigger: '',
deactivateButton: '',
submitDeactivate: '',
/**
* Caches elements for later use.
*/
_cacheElements() {
this.slug = udsVars?._plugin_slug || '';
this.skipButton = $( '.uds-feedback-skip' );
this.submitDeactivate = $( '.uds-feedback-submit' );
this.deactivateButton = $( '#the-list' ).find(
`.row-actions span.deactivate a`
);
this.feedbackForm = $( '.uds-feedback-form' ); // Feedback Form.
this.feedbackInput = $( '.uds-options-feedback' ); // Feedback Textarea.
this.formWrapper = $( '.uds-feedback-form--wrapper' );
this.closeButton = $( '.uds-feedback-form--wrapper .uds-close' );
this.radioButton = $( '.uds-reason-input' );
},
/**
* Shows the feedback popup by adding the 'show' class to the form wrapper.
*
* @param {string} slug - The slug of the plugin.
*/
_showPopup( slug ) {
$( `#deactivation-survey-${ slug }` ).addClass( 'show_popup' );
},
/**
* Hides the feedback popup by removing the 'show' class from the form wrapper.
*/
_hidePopup() {
this.formWrapper.removeClass( 'show_popup' );
},
/**
* Redirects to the deactivate URL if it exists, otherwise reloads the current page.
*/
_redirectOrReload() {
if ( this.deactivateUrl ) {
window.location.href = this.deactivateUrl;
} else {
location.reload();
}
},
/**
* Toggles the visibility of the feedback form and CTA based on the event target's attributes.
*
* @param {Event} event - The event that triggered this function.
*/
_hideShowFeedbackAndCTA( event ) {
const acceptFeedback =
$( event.target ).attr( 'data-accept_feedback' ) === 'true';
const showCta =
$( event.target ).attr( 'data-show_cta' ) === 'true';
$( event.target )
.closest( this.formWrapper )
.find( '.uds-options-feedback' )
.removeClass( 'hide' )
.addClass( acceptFeedback ? 'show' : 'hide' );
$( event.target )
.closest( this.formWrapper )
.find( '.uds-option-feedback-cta' )
.removeClass( 'hide' )
.addClass( showCta ? 'show' : 'hide' );
},
/**
* Changes the placeholder text of the feedback input based on the event target's attribute.
*
* @param {Event} event - The event that triggered this function.
*/
_changePlaceholderText( event ) {
const radioButtonPlaceholder =
event.target.getAttribute( 'data-placeholder' );
$( event.target )
.closest( this.formWrapper )
.find( this.feedbackInput )
.attr( 'placeholder', radioButtonPlaceholder || '' );
this._hideShowFeedbackAndCTA( event );
},
/**
* Submits the feedback form and handles the response.
*
* @param {Event} event - The event that triggered this function.
* @param {Object} self - A reference to the current object.
*/
_submitFeedback( event, self ) {
event.preventDefault();
const currentForm = $( event.target );
const closestForm = currentForm.closest( this.feedbackForm ); // Cache the closest form
// Gather form data.
const formData = {
action: 'uds_plugin_deactivate_feedback',
security: udsVars?._ajax_nonce || '',
reason:
closestForm
.find( this.radioButton.filter( ':checked' ) )
.val() || '', // Get the selected radio button value from the current form.
source: closestForm.find( 'input[name="source"]' ).val() || '',
referer:
closestForm.find( 'input[name="referer"]' ).val() || '',
version:
closestForm.find( 'input[name="version"]' ).val() || '',
feedback: closestForm.find( this.feedbackInput ).val() || '', // Get the feedback input value from the current form.
};
currentForm
.find( '.uds-feedback-' + this.buttonAction )
.text( 'Deactivating.' )
.addClass( 'processing' );
// Prepare AJAX call.
$.ajax( {
url: udsVars?.ajaxurl, // URL to send the request to.
type: 'POST', // HTTP method.
data: formData, // Data to be sent.
success( response ) {
if ( response.success ) {
self._redirectOrReload();
}
self._hidePopup();
},
/* eslint-disable */
error( xhr, status, error ) {
/* eslint-disable */
self._redirectOrReload();
},
} );
},
_handleClick( e ) {
// Close feedback form or show/hide popup if clicked outside and add a click on a Activate button of Theme.
if (
e.target.classList.contains( 'show_popup' ) &&
e.target.closest( '.uds-feedback-form--wrapper' )
) {
this._hidePopup();
} else if ( e.target.classList.contains( 'activate' ) ) {
this.deactivateUrl = e.target.href;
// Don't show for Child Themes.
if (
-1 !==
this.deactivateUrl.indexOf(
`stylesheet=${ udsVars?._current_theme }-child`
)
) {
return;
}
e.preventDefault();
this._showPopup( udsVars?._current_theme );
}
},
/**
* Initializes the feedback popup by caching elements and binding events.
*/
_init() {
this._cacheElements();
this._bind();
},
/**
* Binds event listeners to various elements to handle user interactions.
*/
_bind() {
const self = this; // Store reference to the current object.
// Open the popup when clicked on the deactivate button.
this.deactivateButton.on( 'click', function ( event ) {
let closestTr = $( event.target ).closest( 'tr' );
let slug = closestTr.data( 'slug' );
if ( self.slug.includes( slug ) ) {
event.preventDefault();
// Set the deactivation URL.
self.deactivateUrl = $( event.target ).attr( 'href' );
self._showPopup( slug );
}
} );
// Close the popup on a click of Close button.
this.closeButton.on( 'click', function ( event ) {
event.preventDefault();
self._hidePopup(); // Use self to refer to the UserDeactivationPopup instance.
} );
// Click event on radio button to change the placeholder of textarea.
this.radioButton.on( 'click', function ( event ) {
self._changePlaceholderText( event );
} );
// Combined submit and skip button actions.
this.submitDeactivate
.add( this.skipButton )
.on( 'click', function ( event ) {
event.preventDefault(); // Prevent default button action.
self.buttonAction = $( event.target ).attr( 'data-action' );
$( event.target ).closest( self.feedbackForm ).submit();
} );
this.feedbackForm.on( 'submit', function ( event ) {
self._submitFeedback( event, self );
} );
document.addEventListener( 'click', function ( e ) {
self._handleClick( e );
} );
},
};
$( function () {
UserDeactivationPopup._init();
} );
} )( jQuery );