From ca0ec737bc70e15b04756f3be15a0ea8cd40c036 Mon Sep 17 00:00:00 2001 From: Jason Adams Date: Thu, 5 Nov 2020 17:05:44 -0800 Subject: [PATCH 1/3] fix: separate even listener to avoid duplicate listeners --- src/DoubleTheDonation/Assets.php | 12 +++++++++--- src/DoubleTheDonation/DonationForm.php | 7 ++----- .../js/frontend/give-double-the-donation.js | 5 +++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/DoubleTheDonation/Assets.php b/src/DoubleTheDonation/Assets.php index 049be20..68fd5a6 100644 --- a/src/DoubleTheDonation/Assets.php +++ b/src/DoubleTheDonation/Assets.php @@ -32,18 +32,24 @@ public static function loadBackendAssets() { * @return void */ public static function loadFrontendAssets() { - wp_enqueue_script( - 'give-double-the-donation-style-script', + 'give-double-the-donation-script', 'https://doublethedonation.com/api/js/ddplugin.js', [] ); + wp_enqueue_style( 'give-double-the-donation-style', 'https://doublethedonation.com/api/css/ddplugin.css', [] ); - + wp_enqueue_script( + 'give-double-the-donation-script-backend', + GIVE_DTD_URL . 'public/js/give-double-the-donation.js', + ['give-double-the-donation-script'], + GIVE_DTD_VERSION, + true + ); } } diff --git a/src/DoubleTheDonation/DonationForm.php b/src/DoubleTheDonation/DonationForm.php index 3ab537c..770bc59 100644 --- a/src/DoubleTheDonation/DonationForm.php +++ b/src/DoubleTheDonation/DonationForm.php @@ -33,16 +33,13 @@ public function employerMatchField( $form_id ) { ?>
> + +
- -
{ + window.doublethedonation.plugin.load_streamlined_input(); + } ); +} From 5bf85c3758720166c6066a1daee9b4087416b85f Mon Sep 17 00:00:00 2001 From: Jason Adams Date: Thu, 5 Nov 2020 17:24:53 -0800 Subject: [PATCH 2/3] fix: check if input is initialized for multi-step --- src/DoubleTheDonation/Assets.php | 2 +- src/DoubleTheDonation/DonationForm.php | 6 +++--- .../resources/js/frontend/give-double-the-donation.js | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/DoubleTheDonation/Assets.php b/src/DoubleTheDonation/Assets.php index 68fd5a6..a26166c 100644 --- a/src/DoubleTheDonation/Assets.php +++ b/src/DoubleTheDonation/Assets.php @@ -45,7 +45,7 @@ public static function loadFrontendAssets() { ); wp_enqueue_script( - 'give-double-the-donation-script-backend', + 'give-double-the-donation-script-frontend', GIVE_DTD_URL . 'public/js/give-double-the-donation.js', ['give-double-the-donation-script'], GIVE_DTD_VERSION, diff --git a/src/DoubleTheDonation/DonationForm.php b/src/DoubleTheDonation/DonationForm.php index 770bc59..ae36aea 100644 --- a/src/DoubleTheDonation/DonationForm.php +++ b/src/DoubleTheDonation/DonationForm.php @@ -25,9 +25,9 @@ public function employerMatchField( $form_id ) { } // Do not handle legacy donation form. - $labelStyle = ! FormUtils::isLegacyForm() ? 'style="display: block !important; font-size: 14px;"' : ''; - $divStyle = ! FormUtils::isLegacyForm() ? 'style="margin: 0 0 20px;"' : ''; - + $isLegacyForm = FormUtils::isLegacyForm(); + $labelStyle = ! $isLegacyForm ? 'style="display: block !important; font-size: 14px;"' : ''; + $divStyle = ! $isLegacyForm ? 'style="margin: 0 0 20px;"' : ''; $dtdLabel = give_get_meta( $form_id, 'give_dtd_label', true, esc_html__( 'See if your company will match your donation!', 'give-double-the-donation' ) ); ?> diff --git a/src/DoubleTheDonation/resources/js/frontend/give-double-the-donation.js b/src/DoubleTheDonation/resources/js/frontend/give-double-the-donation.js index 5395c2c..6d78584 100644 --- a/src/DoubleTheDonation/resources/js/frontend/give-double-the-donation.js +++ b/src/DoubleTheDonation/resources/js/frontend/give-double-the-donation.js @@ -1,5 +1,9 @@ if ( window.doublethedonation ) { document.addEventListener( 'give_gateway_loaded', () => { - window.doublethedonation.plugin.load_streamlined_input(); + const input = document.getElementById( 'dd-company-name-input' ); + + if ( ! input.hasAttribute( 'data-doublethedonation-widget-id' ) ) { + window.doublethedonation.plugin.load_streamlined_input(); + } } ); } From 512bfd61b799a1540d89d7e390bd1cd20aeefd5c Mon Sep 17 00:00:00 2001 From: Jason Adams Date: Thu, 5 Nov 2020 17:38:39 -0800 Subject: [PATCH 3/3] feature: use class instead of id to support multiple legacy forms --- src/DoubleTheDonation/DonationForm.php | 2 +- .../js/frontend/give-double-the-donation.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/DoubleTheDonation/DonationForm.php b/src/DoubleTheDonation/DonationForm.php index ae36aea..6b54b7a 100644 --- a/src/DoubleTheDonation/DonationForm.php +++ b/src/DoubleTheDonation/DonationForm.php @@ -34,7 +34,7 @@ public function employerMatchField( $form_id ) {
> -
+