Permalink
Browse files

fix(tooltip+popover): Hide tooltip/popover when $route changes (#965)

Addresses issue #964
  • Loading branch information...
tmorehouse committed Aug 30, 2017
1 parent 3adbcb5 commit e403225194161d9ce71e349e6d84508093549eb6
Showing with 26 additions and 0 deletions.
  1. +26 −0 lib/classes/tooltip.js
@@ -115,6 +115,7 @@ class ToolTip {
this.$tip = null;
this.$id = generateId(this.constructor.NAME);
this.$root = $root || null;
this.$routeWatcher = null;
this.updateConfig(config);
}
@@ -518,6 +519,8 @@ class ToolTip {
}, this);
// If we are in a modal, we need to hide when it closes
this.setModalListener(true);
// Watch for route changes
this.setRouteWatcher(true);
}
unListen() {
@@ -527,6 +530,8 @@ class ToolTip {
this.$element.removeEventListener(evt, this);
}, this);
this.setModalListener(false);
// stop watching for route changes
this.setRouteWatcher(false);
}
handleEvent(e) {
@@ -544,6 +549,27 @@ class ToolTip {
}
}
setRouteWatcher(on) {
if (on) {
this.setRouteWatcher(false);
if (this.$root && Boolean(this.$root.$route)) {
this.$routeWatcher = this.$root.$watch('$route', (newVal, oldVal) => {
if (newVal === oldVal) {
return;
}
// If route has changed, we hide the tooltip/popover
this.hide();
});
}
} else {
if (this.$routeWatcher) {
// cancel the route watcher by calling hte stored reference
this.$routeWatcher();
this.$routeWatcher = null;
}
}
}
setModalListener(on) {
const modal = this.$element.closest(MODAL_CLASS);
if (!modal) {

0 comments on commit e403225

Please sign in to comment.