PLAT-1198 Reduce risk of losing navigation events

This commit is contained in:
Jeremy Bowman
2017-03-23 11:00:40 -04:00
parent d19fbca17c
commit d1f256124c
3 changed files with 23 additions and 10 deletions

View File

@@ -339,7 +339,7 @@
// `direction` can be 'previous' or 'next'
Sequence.prototype._change_sequential = function(direction, event) {
var analyticsEventName, isBottomNav, newPosition, offset, widgetPlacement;
var analyticsEventName, isBottomNav, newPosition, offset, targetUrl, widgetPlacement;
// silently abort if direction is invalid.
if (direction !== 'previous' && direction !== 'next') {
@@ -355,19 +355,27 @@
widgetPlacement = 'top';
}
if ((direction === 'next') && (this.position >= this.contents.length)) {
targetUrl = this.nextUrl;
} else if ((direction === 'previous') && (this.position === 1)) {
targetUrl = this.prevUrl;
}
// Formerly known as seq_next and seq_prev
Logger.log(analyticsEventName, {
id: this.id,
current_tab: this.position,
tab_count: this.num_contents,
widget_placement: widgetPlacement
}).always(function() {
if (targetUrl) {
// Wait to load the new page until we've attempted to log the event
window.location.href = targetUrl;
}
});
if ((direction === 'next') && (this.position >= this.contents.length)) {
window.location.href = this.nextUrl;
} else if ((direction === 'previous') && (this.position === 1)) {
window.location.href = this.prevUrl;
} else {
// If we're staying on the page, no need to wait for the event logging to finish
if (!targetUrl) {
// If the bottom nav is used, scroll to the top of the page on change.
if (isBottomNav) {
$.scrollTo(0, 150);