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:
@@ -2965,33 +2965,35 @@
|
|||||||
// 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 {
|
||||||
|
while ( ( target.tagName !== "A" ) &&
|
||||||
|
( target !== document.documentElement ) ) {
|
||||||
|
target = target.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( target.tagName === "A" ) {
|
||||||
|
var href = target.getAttribute( "href" );
|
||||||
|
|
||||||
|
// If it's a link to presentation step, target this step
|
||||||
|
if ( href && href[ 0 ] === "#" ) {
|
||||||
|
target = document.getElementById( href.slice( 1 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( api.goto( target ) ) {
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( err ) {
|
||||||
|
|
||||||
// For example, when clicking on the button to launch speaker console, the button
|
// 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
|
// 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.
|
// 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
|
if ( err instanceof TypeError &&
|
||||||
}
|
err.message === "target is null" ) {
|
||||||
catch ( err ) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( ( target.tagName !== "A" ) &&
|
|
||||||
( target !== document.documentElement ) ) {
|
|
||||||
target = target.parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( target.tagName === "A" ) {
|
|
||||||
var href = target.getAttribute( "href" );
|
|
||||||
|
|
||||||
// If it's a link to presentation step, target this step
|
|
||||||
if ( href && href[ 0 ] === "#" ) {
|
|
||||||
target = document.getElementById( href.slice( 1 ) );
|
|
||||||
}
|
}
|
||||||
}
|
throw err;
|
||||||
|
|
||||||
if ( api.goto( target ) ) {
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
}
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
@@ -2999,21 +3001,28 @@
|
|||||||
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
|
|
||||||
|
// Find closest step element that is not active
|
||||||
|
while ( !( target.classList.contains( "step" ) &&
|
||||||
|
!target.classList.contains( "active" ) ) &&
|
||||||
|
( target !== document.documentElement ) ) {
|
||||||
|
target = target.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( api.goto( target ) ) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( err ) {
|
catch ( err ) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find closest step element that is not active
|
// For example, when clicking on the button to launch speaker console, the button
|
||||||
while ( !( target.classList.contains( "step" ) &&
|
// is immediately deleted from the DOM. In this case target is a DOM element when
|
||||||
!target.classList.contains( "active" ) ) &&
|
// we get it, but turns out to be null if you try to actually do anything with it.
|
||||||
( target !== document.documentElement ) ) {
|
if ( err instanceof TypeError &&
|
||||||
target = target.parentNode;
|
err.message === "target is null" ) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if ( api.goto( target ) ) {
|
throw err;
|
||||||
event.preventDefault();
|
|
||||||
}
|
}
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
|
|||||||
@@ -125,33 +125,35 @@
|
|||||||
// 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 {
|
||||||
|
while ( ( target.tagName !== "A" ) &&
|
||||||
|
( target !== document.documentElement ) ) {
|
||||||
|
target = target.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( target.tagName === "A" ) {
|
||||||
|
var href = target.getAttribute( "href" );
|
||||||
|
|
||||||
|
// If it's a link to presentation step, target this step
|
||||||
|
if ( href && href[ 0 ] === "#" ) {
|
||||||
|
target = document.getElementById( href.slice( 1 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( api.goto( target ) ) {
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( err ) {
|
||||||
|
|
||||||
// For example, when clicking on the button to launch speaker console, the button
|
// 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
|
// 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.
|
// 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
|
if ( err instanceof TypeError &&
|
||||||
}
|
err.message === "target is null" ) {
|
||||||
catch ( err ) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( ( target.tagName !== "A" ) &&
|
|
||||||
( target !== document.documentElement ) ) {
|
|
||||||
target = target.parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( target.tagName === "A" ) {
|
|
||||||
var href = target.getAttribute( "href" );
|
|
||||||
|
|
||||||
// If it's a link to presentation step, target this step
|
|
||||||
if ( href && href[ 0 ] === "#" ) {
|
|
||||||
target = document.getElementById( href.slice( 1 ) );
|
|
||||||
}
|
}
|
||||||
}
|
throw err;
|
||||||
|
|
||||||
if ( api.goto( target ) ) {
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
}
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
@@ -159,21 +161,28 @@
|
|||||||
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
|
|
||||||
|
// Find closest step element that is not active
|
||||||
|
while ( !( target.classList.contains( "step" ) &&
|
||||||
|
!target.classList.contains( "active" ) ) &&
|
||||||
|
( target !== document.documentElement ) ) {
|
||||||
|
target = target.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( api.goto( target ) ) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( err ) {
|
catch ( err ) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find closest step element that is not active
|
// For example, when clicking on the button to launch speaker console, the button
|
||||||
while ( !( target.classList.contains( "step" ) &&
|
// is immediately deleted from the DOM. In this case target is a DOM element when
|
||||||
!target.classList.contains( "active" ) ) &&
|
// we get it, but turns out to be null if you try to actually do anything with it.
|
||||||
( target !== document.documentElement ) ) {
|
if ( err instanceof TypeError &&
|
||||||
target = target.parentNode;
|
err.message === "target is null" ) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if ( api.goto( target ) ) {
|
throw err;
|
||||||
event.preventDefault();
|
|
||||||
}
|
}
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user