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