HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/wpforms-pdf/assets/js/modules/theme.js
/* global WPFormsPDFBuilder */

/**
 * WPForms PDF: Theme module.
 *
 * @since 1.0.0
 *
 * @param {Object} document Document object.
 * @param {Object} window   Window object.
 * @param {jQuery} $        jQuery object.
 *
 * @return {Object} Public functions and properties.
 */
export default function( document, window, $ ) { // eslint-disable-line no-unused-vars
	/**
	 * Elements holder.
	 *
	 * @since 1.0.0
	 *
	 * @type {Object}
	 */
	const el = {};

	/**
	 * Public functions and properties.
	 *
	 * @since 1.0.0
	 */
	const app = {

		/**
		 * Start the engine.
		 *
		 * @since 1.0.0
		 */
		init() {
			app.setup();
			app.events();
		},

		/**
		 * Setup.
		 *
		 * @since 1.0.0
		 */
		setup() {
			el.$builder = $( '#wpforms-builder' );
		},

		/**
		 * Setup.
		 *
		 * @since 1.0.0
		 */
		events() {
			el.$builder
				.on( 'click', '.wpforms-field-pdf-theme-edit button', app.toggleThemeEditor );
		},

		/**
		 * Toggle theme editor.
		 *
		 * @since 1.0.0
		 */
		toggleThemeEditor() {
			const $button = $( this );
			const $editor = $button.closest( '.wpforms-pdf-appearance-group' ).find( '.wpforms-pdf-theme-color-editor' );

			$button.toggleClass( 'active' );

			const isActive = $button.hasClass( 'active' );

			$editor.toggleClass( 'wpforms-hidden', ! isActive );

			if ( isActive ) {
				const pdfId = $button.data( 'pdf-id' );
				app.updateEditorColors( pdfId );
				WPFormsPDFBuilder.appearance.loadColorPickers( $( `#wpforms-panel-field-pdfs-${ pdfId }-theme-wrap` ) );
			}
		},

		/**
		 * Update editor colors.
		 *
		 * @since 1.0.0
		 *
		 * @param {number} pdfId PDF ID.
		 */
		updateEditorColors( pdfId ) {
			const themeData = app.getPdfThemeData( pdfId );

			if ( ! themeData?.colors ) {
				return;
			}

			// Update editor colors.
			Object.entries( themeData.colors ).forEach( ( [ key, color ] ) => {
				const $input = $( `#wpforms-panel-field-pdfs-${ pdfId }-theme_color_${ key }` );

				$input.val( color );
				WPFormsPDFBuilder.preview.updateElement( $input, '', false );
			} );
		},

		/**
		 * Get the PDF theme data.
		 *
		 * @since 1.0.0
		 *
		 * @param {number} pdfId PDF ID.
		 *
		 * @return {Object|null} Theme data.
		 */
		getPdfThemeData( pdfId ) {
			const themeSlug = $( `#wpforms-panel-field-pdfs-${ pdfId }-theme` ).val();

			return WPFormsPDFBuilder.appearance.getThemeData( themeSlug );
		},
	};

	return app;
}