diff --git a/src/level/LevelRender.js b/src/level/LevelRender.js index fa08758..62b66f6 100644 --- a/src/level/LevelRender.js +++ b/src/level/LevelRender.js @@ -151,6 +151,7 @@ module.exports = Class( 'LevelRender', 'private _getObjCanvas': function() { const canvas = this._ctx.canvas, + document = this._getDocument( canvas ), canvas_obj = document.createElement( 'canvas' ); // mimic the dimensions and positions of the original canvas @@ -167,6 +168,25 @@ module.exports = Class( 'LevelRender', }, + /** + * Get HTMLDocument node from element ELEMENT + * + * ELEMENT must be on a DOM. This allows us to always reference the + * proper document node without being coupled with the browser's + * window.document, which may not be what we're interested in. + * + * @param {HTMLElement} element reference element + * + * @return {HTMLDocument} document node + */ + 'private _getDocument': function( element ) + { + return ( element.parentElement === null ) + ? element.parentNode + : this._getDocument( element.parentElement ); + }, + + /** * Render the provided level *