diff --git a/doc/events.md b/doc/events.md index 28dd322..1bc1129 100644 --- a/doc/events.md +++ b/doc/events.md @@ -4,7 +4,19 @@ Fired when a panorama finishes loading. + ## `scenechange` Fired when a scene change is initiated. A `load` event will be fired when the new scene finishes loading. + + +## `error` + +Fired when an error occured. The error message string is passed to the +event listener. + + +## `errorcleared` + +Fired when an error is cleared. diff --git a/src/js/pannellum.js b/src/js/pannellum.js index 8c3f454..2c5a405 100644 --- a/src/js/pannellum.js +++ b/src/js/pannellum.js @@ -501,20 +501,19 @@ function parseGPanoXMP(image) { /** * Displays an error message. * @private - * @param {string} error - Error message to display. If not specified, a + * @param {string} errorMsg - Error message to display. If not specified, a * generic WebGL error is displayed. */ -function anError(error) { - if (error !== undefined) { - infoDisplay.errorMsg.innerHTML = '

' + error + '

'; - } else { - infoDisplay.errorMsg.innerHTML = '

Your browser does not have the necessary WebGL support to display this panorama.

'; - } +function anError(errorMsg) { + if (errorMsg === undefined) + errorMsg = 'Your browser does not have the necessary WebGL support to display this panorama.'; + infoDisplay.errorMsg.innerHTML = '

' + errorMsg + '

'; controls.load.style.display = 'none'; infoDisplay.load.box.style.display = 'none'; infoDisplay.errorMsg.style.display = 'table'; error = true; renderContainer.style.display = 'none'; + fireEvent('error', errorMsg); } /** @@ -522,9 +521,12 @@ function anError(error) { * @private */ function clearError() { - infoDisplay.load.box.style.display = 'none'; - infoDisplay.errorMsg.style.display = 'none'; - error = false; + if (error) { + infoDisplay.load.box.style.display = 'none'; + infoDisplay.errorMsg.style.display = 'none'; + error = false; + fireEvent('errorcleared'); + } } /** @@ -2143,7 +2145,7 @@ this.off = function(type, listener) { function fireEvent(type) { if (type in externalEventListeners) { for (var i = 0; i < externalEventListeners[type].length; i++) { - externalEventListeners[type][i].call(); + externalEventListeners[type][i].apply(null, [].slice.call(arguments, 1)); } } }