-
Notifications
You must be signed in to change notification settings - Fork 1
Hook up global alerts for New Homepage using current sitewide alert system #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Check to see if the current page is a v2 page. If it is, we'll use v2 alert markup and load a v2 close button in the respective functions. If not, we'll use v1. | ||
| var isV2page = document.body.classList.contains('v2-page'); | ||
|
|
||
| // Loads alert-level posts on the top of all pages | ||
| function filterAlerts(posts) { | ||
| // This processes an array of posts for valid, confirmed, alerts | ||
|
|
@@ -56,12 +59,26 @@ function renderAlert(markup,id) { | |
| } | ||
|
|
||
| function setClosable(alert_ID) { | ||
| // Add a Close icon/svg/button | ||
| $('.posts--preview--alerts .post').append('<a href="#0" id="close" class="action-close"><span class="sr">Dismiss</span><i class="fa fa-circle-xmark" aria-hidden="true"></i></a>'); | ||
| // On click | ||
| // Add a Close button. We use v2 markup only for pages that are v2 pages. Otherwise, we'll use v1 markup. | ||
| if(isV2page) { | ||
| // v2 close button markup | ||
| $('#global-alert').append('<a id="close" href="#" class="dismiss"><i class="fa-sharp fa-light fa-xmark"></i></a>'); | ||
| } else { | ||
| // v1 close button markup | ||
| $('.posts--preview--alerts .post').append('<a href="#0" id="close" class="action-close"><span class="sr">Dismiss</span><i class="fa fa-circle-xmark" aria-hidden="true"></i></a>'); | ||
| } | ||
|
|
||
| // On click of the link with the close id | ||
| $('#close').click(function(){ | ||
| // Add the necessary transition hide class | ||
| $(this).closest('.posts--preview--alerts').addClass('transition-vertical--hide'); | ||
|
|
||
| // Apply relevant logic based on v1 or v2 alert. Add relevant class to hide the alert. | ||
| if(isV2page) { | ||
| // v2 | ||
| $(this).closest('#global-alert').addClass('hidden'); | ||
| } else { | ||
| // v1 | ||
| $(this).closest('.posts--preview--alerts').addClass('transition-vertical--hide'); | ||
| } | ||
| // Bump the hours calendar down, if it is present. | ||
| moveCalendar(-152); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking comment: This is also something to consider, as the hours page migrates, whether we need separate // If this is a closable alert
if (true === alert_posts_arr[i].meta.closable) {
if (isV2page) {
setClosableV2(alert_ID);
} else {
setClosableV1(alert_ID);
}
}(This introduces a separate maintenance concern as we'd be maintaining two functions in parallel, but I'd rather that than a single function that branches more than twice - or maybe there's another more efficient mechanism somehow, if we prototype a bit more) |
||
| // If localStorage | ||
|
|
@@ -92,15 +109,32 @@ function showAlerts(json) { | |
| // Check for empty title | ||
| alert_title = ('' === alert_posts_arr[i].title.rendered) ? 'Alert!' : alert_posts_arr[i].title.rendered; | ||
|
|
||
| // Alert HTML template | ||
| alert_template = '<div class="posts--preview--alerts transition-vertical transition-vertical--hide">' + | ||
| '<div class="post alert--critical flex-container">' + | ||
| '<i class="fa fa-circle-exclamation" aria-hidden="true"></i>' + | ||
| '<div class="content-post alertText">' + | ||
| '<h3>' + alert_title + '</h3> ' + alert_posts_arr[i].content.rendered + | ||
| // If this is a v2 page, use the v2 alert markup. Otherwise, use the v1 markup. | ||
| if (isV2page) { | ||
| // Alert HTML template (v2) | ||
| alert_template = '<section id="global-alert">' + | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment: I do suspect that the use of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also realizing as I look at the code here again, that we already have a duplicate ID problem since for for both v1 and v2 alerts we're adding a link with This doesn't happen very often, but when I tested multiple alerts the I'm going to leave this as a future-us thing we fix with whatever longer term solution we come to for Alerts. |
||
| '<div class="content-wrapper">' + | ||
| '<div class="global-alert-message">' + | ||
| '<i class="fa-solid fa-triangle-exclamation"></i>' + | ||
| '<header>' + | ||
| '<h2>' + alert_title + '</h2>' + | ||
| '<p>' + alert_posts_arr[i].content.rendered + '</p>' + | ||
| '</header>' + | ||
| '</div>' + | ||
| '</div>' | ||
| '</section>'; | ||
|
|
||
| } else { | ||
| // Alert HTML template (v1) | ||
| alert_template = '<div class="posts--preview--alerts transition-vertical transition-vertical--hide">' + | ||
| '<div class="post alert--critical flex-container">' + | ||
| '<i class="fa fa-circle-exclamation" aria-hidden="true"></i>' + | ||
| '<div class="content-post alertText">' + | ||
| '<h3>' + alert_title + '</h3> ' + alert_posts_arr[i].content.rendered + | ||
| '</div>' + | ||
| '</div>' + | ||
| '</div>' + | ||
| '</div>'; | ||
| '</div>'; | ||
| } | ||
|
|
||
| renderAlert(alert_template,alert_ID); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking comment:
This is probably a good candidate for a constant, rather than a variable (although a variable that is known to be a unique name like this is also probably fine.
The question I'm grappling with is whether a read-only javascript constant like this might be useful in other contexts, for any other javascript-based feature that will need to be operational through the transition between v1 and v2 pages. The first candidates that come to mind are the map and the calendar, but those are each only on a single page - so any issues we run into with those features can be bundled into the migration of those templates.
The various hours widgets will need to run simultaneously on v1 and v2 pages, so depending on whether those widgets change significantly that's a candidate.
For the moment, this is likely fine - but as we get deeper into the transition this line might be something that we should move to
functions.phpand to spit out a constant as in https://github.com/MITLibraries/mitlib-wp-network/blob/master/web/app/themes/mitlib-parent/functions.php#L238 .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh interesting... Maybe we couple moving this to a constant with whatever the next feature is that needs to check for this condition. I haven't seen that "create a JS const via PHP" mechanism before!