From c8081294eb6efbf0fcc0e76c84deff48f389dc29 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 7 Jul 2020 21:10:14 -0400 Subject: [PATCH] [deploy] Only run JS on appropriate Articles (#9191) --- app/liquid_tags/user_subscription_tag.rb | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/liquid_tags/user_subscription_tag.rb b/app/liquid_tags/user_subscription_tag.rb index 1b8767fc3..3eb034897 100644 --- a/app/liquid_tags/user_subscription_tag.rb +++ b/app/liquid_tags/user_subscription_tag.rb @@ -277,18 +277,22 @@ class UserSubscriptionTag < LiquidTagBase }); } - // The markup defaults to signed out UX - if (isUserSignedIn()) { - showSignedIn(); - addConfirmationModalClickHandlers(); + // We load this JS on every Article. This is to only run it on Articles + // where the UserSubscription liquid tag is present + if (document.getElementById('user-subscription-tag')) { + // The markup defaults to signed out UX + if (isUserSignedIn()) { + showSignedIn(); + addConfirmationModalClickHandlers(); - // We need access to some DOM elements (i.e. csrf token, article id, userData, etc.) - document.addEventListener('DOMContentLoaded', function() { - checkIfSubscribed(); - }); - } else { - showSignedOut(); - addSignInClickHandler(); + // We need access to some DOM elements (i.e. csrf token, article id, userData, etc.) + document.addEventListener('DOMContentLoaded', function() { + checkIfSubscribed(); + }); + } else { + showSignedOut(); + addSignInClickHandler(); + } } JAVASCRIPT