Skip to content

Commit

Permalink
Move escapeHandler outside so that it can be removed in mouseleave an…
Browse files Browse the repository at this point in the history
…d fix bug where the "if" check was detecting every key, not just escape (issue #1114)
  • Loading branch information
JohnSmith-LT committed Jun 11, 2022
1 parent 9215632 commit 39ce9ac
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions modules/xerte/parent_templates/Nottingham/common_html5/js/xenith.js
Expand Up @@ -4385,22 +4385,23 @@ var XENITH = (function ($, parent) { var self = parent.GLOSSARY = {};
);
});

//var $tooltip;
// Handle the closing of glossary bubble with escape key
var $activeTooltip, escapeHandler = function(e) {
e = e || window.event; //IE
if ((e.keyCode ? e.keyCode : e.which) === 27) { // Escape
$activeTooltip.trigger("mouseleave");
e.stopPropagation();
}
};

$x_pageDiv
.on("mouseenter", ".x_glossary", function(e) {
$tooltip = $(this);
$tooltip.trigger("mouseleave");
$activeTooltip = $(this);
$activeTooltip.trigger("mouseleave");

document.body.addEventListener('keydown', function escapeHandler(e) {
e = e || window.event;
if (e.keyCode ? e.keyCode : e.which === 27) { // Escape
$tooltip.trigger("mouseleave");
e.stopPropagation();
document.body.removeEventListener('keydown', escapeHandler);
}
});
window.addEventListener('keydown', escapeHandler);

var myText = $tooltip.text().replace(/(\s| )+/g, " ").trim(),
var myText = $activeTooltip.text().replace(/(\s| )+/g, " ").trim(),
myDefinition, i, len;

for (i=0, len=x_glossary.length; i<len; i++) {
Expand All @@ -4417,8 +4418,8 @@ var XENITH = (function ($, parent) { var self = parent.GLOSSARY = {};
$x_glossaryHover
.html(myDefinition)
.css({
"left" :$tooltip.offset().left + 20,
"top" :$tooltip.offset().top + 20
"left" :$activeTooltip.offset().left + 20,
"top" :$activeTooltip.offset().top + 20
});

// Queue reparsing of MathJax - fails if no network connection
Expand All @@ -4432,8 +4433,8 @@ var XENITH = (function ($, parent) { var self = parent.GLOSSARY = {};
})
.on("mouseleave", ".x_glossary", function(e) {
$x_mainHolder.off("click.glossary");

$x_glossaryHover.hide();
window.removeEventListener('keydown', escapeHandler);
})
.on("mousemove", ".x_glossary", function(e) {
var leftPos,
Expand Down

0 comments on commit 39ce9ac

Please sign in to comment.