From 3b1ac2c78c45d9bfd56ed353913a3cd3c6c145d3 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 22 Dec 2015 00:48:21 -0500 Subject: [PATCH] Decouple LevelRender from window.document --- src/level/LevelRender.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 *