Broader try-catch for handling impress-console-button disappearance (#652)

The previous attempt at merely reading a property of event.target was
incorrect. It worked at first but errors reappeared later, so must
have been a reace.

This wraps the entire navigation event handlers in the try-catch, and
then checks for the very specific error and suppresses it. Other errors
are rethrown as is.
This commit is contained in:
Henrik Ingo
2018-01-01 16:03:13 +02:00
parent 784a6d245b
commit 8b14eda98f
2 changed files with 86 additions and 68 deletions

View File

@@ -2965,16 +2965,6 @@
// check if event target (or any of its parents is a link) // check if event target (or any of its parents is a link)
var target = event.target; var target = event.target;
try { try {
// For example, when clicking on the button to launch speaker console, the button
// is immediately deleted from the DOM. In this case target is a DOM element when
// we get it, but turns out to be null if you try to actually do anything with it.
var foo = target.id; // jshint ignore:line
}
catch ( err ) {
return;
}
while ( ( target.tagName !== "A" ) && while ( ( target.tagName !== "A" ) &&
( target !== document.documentElement ) ) { ( target !== document.documentElement ) ) {
target = target.parentNode; target = target.parentNode;
@@ -2993,17 +2983,24 @@
event.stopImmediatePropagation(); event.stopImmediatePropagation();
event.preventDefault(); event.preventDefault();
} }
}
catch ( err ) {
// For example, when clicking on the button to launch speaker console, the button
// is immediately deleted from the DOM. In this case target is a DOM element when
// we get it, but turns out to be null if you try to actually do anything with it.
if ( err instanceof TypeError &&
err.message === "target is null" ) {
return;
}
throw err;
}
}, false ); }, false );
// Delegated handler for clicking on step elements // Delegated handler for clicking on step elements
gc.addEventListener( document, "click", function( event ) { gc.addEventListener( document, "click", function( event ) {
var target = event.target; var target = event.target;
try { try {
var foo = target.id; // jshint ignore:line
}
catch ( err ) {
return;
}
// Find closest step element that is not active // Find closest step element that is not active
while ( !( target.classList.contains( "step" ) && while ( !( target.classList.contains( "step" ) &&
@@ -3015,6 +3012,18 @@
if ( api.goto( target ) ) { if ( api.goto( target ) ) {
event.preventDefault(); event.preventDefault();
} }
}
catch ( err ) {
// For example, when clicking on the button to launch speaker console, the button
// is immediately deleted from the DOM. In this case target is a DOM element when
// we get it, but turns out to be null if you try to actually do anything with it.
if ( err instanceof TypeError &&
err.message === "target is null" ) {
return;
}
throw err;
}
}, false ); }, false );
// Add a line to the help popup // Add a line to the help popup

View File

@@ -125,16 +125,6 @@
// check if event target (or any of its parents is a link) // check if event target (or any of its parents is a link)
var target = event.target; var target = event.target;
try { try {
// For example, when clicking on the button to launch speaker console, the button
// is immediately deleted from the DOM. In this case target is a DOM element when
// we get it, but turns out to be null if you try to actually do anything with it.
var foo = target.id; // jshint ignore:line
}
catch ( err ) {
return;
}
while ( ( target.tagName !== "A" ) && while ( ( target.tagName !== "A" ) &&
( target !== document.documentElement ) ) { ( target !== document.documentElement ) ) {
target = target.parentNode; target = target.parentNode;
@@ -153,17 +143,24 @@
event.stopImmediatePropagation(); event.stopImmediatePropagation();
event.preventDefault(); event.preventDefault();
} }
}
catch ( err ) {
// For example, when clicking on the button to launch speaker console, the button
// is immediately deleted from the DOM. In this case target is a DOM element when
// we get it, but turns out to be null if you try to actually do anything with it.
if ( err instanceof TypeError &&
err.message === "target is null" ) {
return;
}
throw err;
}
}, false ); }, false );
// Delegated handler for clicking on step elements // Delegated handler for clicking on step elements
gc.addEventListener( document, "click", function( event ) { gc.addEventListener( document, "click", function( event ) {
var target = event.target; var target = event.target;
try { try {
var foo = target.id; // jshint ignore:line
}
catch ( err ) {
return;
}
// Find closest step element that is not active // Find closest step element that is not active
while ( !( target.classList.contains( "step" ) && while ( !( target.classList.contains( "step" ) &&
@@ -175,6 +172,18 @@
if ( api.goto( target ) ) { if ( api.goto( target ) ) {
event.preventDefault(); event.preventDefault();
} }
}
catch ( err ) {
// For example, when clicking on the button to launch speaker console, the button
// is immediately deleted from the DOM. In this case target is a DOM element when
// we get it, but turns out to be null if you try to actually do anything with it.
if ( err instanceof TypeError &&
err.message === "target is null" ) {
return;
}
throw err;
}
}, false ); }, false );
// Add a line to the help popup // Add a line to the help popup