hotspots.js: Do not place_popover if icon is not visible.

Attempting to do so throws an exception if hotspot.location.element can't be
found.
This commit is contained in:
Rishi Gupta 2017-08-30 19:35:32 -07:00 committed by Tim Abbott
parent 836a2c502e
commit 9f7b310a3e
1 changed files with 11 additions and 9 deletions

View File

@ -52,7 +52,7 @@ exports.post_hotspot_as_read = function (hotspot_name) {
function place_icon(hotspot) { function place_icon(hotspot) {
if ($(hotspot.location.element).length === 0) { if ($(hotspot.location.element).length === 0) {
$('#hotspot_' + hotspot.name + '_icon').css('display', 'none'); $('#hotspot_' + hotspot.name + '_icon').css('display', 'none');
return; return false;
} }
var offset = { var offset = {
@ -69,10 +69,11 @@ function place_icon(hotspot) {
!$(hotspot.location.element).is(':visible') || !$(hotspot.location.element).is(':visible') ||
$(hotspot.location.element).is(':hidden')) { $(hotspot.location.element).is(':hidden')) {
$('#hotspot_' + hotspot.name + '_icon').css('display', 'none'); $('#hotspot_' + hotspot.name + '_icon').css('display', 'none');
} else { return false;
}
$('#hotspot_' + hotspot.name + '_icon').css('display', 'block'); $('#hotspot_' + hotspot.name + '_icon').css('display', 'block');
$('#hotspot_' + hotspot.name + '_icon').css(placement); $('#hotspot_' + hotspot.name + '_icon').css(placement);
} return true;
} }
function place_popover(hotspot) { function place_popover(hotspot) {
@ -188,17 +189,18 @@ function insert_hotspot_into_DOM(hotspot) {
setTimeout(function () { setTimeout(function () {
$('body').prepend(hotspot_icon_HTML); $('body').prepend(hotspot_icon_HTML);
place_icon(hotspot);
$('body').prepend(hotspot_overlay_HTML); $('body').prepend(hotspot_overlay_HTML);
if (place_icon(hotspot)) {
place_popover(hotspot); place_popover(hotspot);
}
// reposition on any event that might update the UI // reposition on any event that might update the UI
['resize', 'scroll', 'onkeydown', 'click'] ['resize', 'scroll', 'onkeydown', 'click']
.forEach(function (event_name) { .forEach(function (event_name) {
window.addEventListener(event_name, _.debounce(function () { window.addEventListener(event_name, _.debounce(function () {
place_icon(hotspot); if (place_icon(hotspot)) {
place_popover(hotspot); place_popover(hotspot);
}
}, 10), true); }, 10), true);
}); });
}, (hotspot.delay * 100)); }, (hotspot.delay * 100));