1
0
Fork 0

Decouple LevelRender from window.document

master
Mike Gerwitz 2015-12-22 00:48:21 -05:00
parent 2240a61ac2
commit 3b1ac2c78c
1 changed files with 20 additions and 0 deletions

View File

@ -151,6 +151,7 @@ module.exports = Class( 'LevelRender',
'private _getObjCanvas': function() 'private _getObjCanvas': function()
{ {
const canvas = this._ctx.canvas, const canvas = this._ctx.canvas,
document = this._getDocument( canvas ),
canvas_obj = document.createElement( 'canvas' ); canvas_obj = document.createElement( 'canvas' );
// mimic the dimensions and positions of the original 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 * Render the provided level
* *