[deploy] Only run JS on appropriate Articles (#9191)

This commit is contained in:
Alex 2020-07-07 21:10:14 -04:00 committed by GitHub
parent ab56a1eb85
commit c8081294eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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