Commit 5b461fd9 authored by Zac Wood's avatar Zac Wood

Merge branch 'alerts' into 'master'

Added alert functionality

See merge request !92
parents d3f11b7b aa69b2fa
Pipeline #5382 passed with stages
in 59 seconds
# Write as
# - title: [Text just gets copied into a boostrap alert (so HTML tags could be used)] What gets displayed
# start: [ISO 8601 Date/Time format] When it will start being displayed
# end: [ISO 8601 Date/Time format] When it will stop being displayed
- title: If you're coming to our first meeting (Monday, February 3rd), please click <a href="https://go.gmu.edu/srctintro" target="_blank" class="alert-link stretched-link">here</a> to RSVP
start: 2020-01-29
end: 2020-02-03T18:30:00
\ No newline at end of file
......@@ -38,5 +38,13 @@
{% endfor %}
</ul>
</div>
</div>
</div>
</nav>
{% for alert in site.data.alerts %}
<div class="alert alert-primary" role="alert" style="margin-bottom: 0px;border-radius: 0px;display:none;" start="{{ alert.start }}" end="{{ alert.end }}">
<div class="container">
&#x1f6c8; {{alert.title}}
</div>
</div>
{% endfor %}
......@@ -3,6 +3,8 @@ function checkDate() {
month = '' + (d.getMonth() + 1),
day = '' + d.getDate()
year = '' + d.getYear();
loadAlerts(d);
// Mason Pride Week
......@@ -74,4 +76,37 @@ function checkDate() {
}
}
// The fact JavaScript does not have this function built in is the reason I'm sad at night
function ISOStringToDate(str) {
const re = /\d+/g;
results = str.match(re);
results = results.map(Number)
// We've been supplied a day, month, year
if (results.length == 3) {
return new Date(results[0], results[1] - 1, results[2], 0, 0, 0, 0);
// We've been supplied a day, month, year, hour, minute, second
// This is 7 long because Liquid's YAML parser adds the timezone offset as
// +XXXX on the right. We just ignore it.
} else if (results.length == 7) {
return new Date(results[0], results[1] - 1, results[2], results[3], results[4], results[5]);
} else {
return new Date();
}
}
// Make the alerts visible that need to be made visible
function loadAlerts(date) {
$('.alert').each(function(index) {
start = ISOStringToDate($(this).attr("start"));
end = ISOStringToDate($(this).attr("end"));
if (date > start && date < end)
$(this).slideDown();
});
}
window.onload = checkDate
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment