mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Merge pull request #170 from beeglebug/selectors
Phaser.Game parent can now be a HTMLElement
This commit is contained in:
+20
-14
@@ -137,37 +137,43 @@ Phaser.Canvas = {
|
||||
*
|
||||
* @method Phaser.Canvas.addToDOM
|
||||
* @param {HTMLCanvasElement} canvas - The canvas to set the touch action on.
|
||||
* @param {string} parent - The DOM element to add the canvas to. Defaults to ''.
|
||||
* @param {string|HTMLElement} parent - The DOM element to add the canvas to. Defaults to ''.
|
||||
* @param {boolean} overflowHidden - If set to true it will add the overflow='hidden' style to the parent DOM element.
|
||||
* @return {HTMLCanvasElement} Returns the source canvas.
|
||||
*/
|
||||
addToDOM: function (canvas, parent, overflowHidden) {
|
||||
|
||||
parent = parent || '';
|
||||
var target;
|
||||
|
||||
if (typeof overflowHidden === 'undefined') { overflowHidden = true; }
|
||||
|
||||
if (parent !== '')
|
||||
if (parent)
|
||||
{
|
||||
if (document.getElementById(parent))
|
||||
// hopefully an element ID
|
||||
if (typeof parent === 'string')
|
||||
{
|
||||
document.getElementById(parent).appendChild(canvas);
|
||||
target = document.getElementById(parent);
|
||||
}
|
||||
// quick test for a HTMLelement
|
||||
else if (typeof parent === 'object' && parent.nodeType === 1)
|
||||
{
|
||||
target = parent;
|
||||
}
|
||||
|
||||
if (overflowHidden)
|
||||
{
|
||||
document.getElementById(parent).style.overflow = 'hidden';
|
||||
}
|
||||
}
|
||||
else
|
||||
if (overflowHidden)
|
||||
{
|
||||
document.body.appendChild(canvas);
|
||||
target.style.overflow = 'hidden';
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// fallback, covers an invalid ID and a none HTMLelement object
|
||||
if(!target)
|
||||
{
|
||||
document.body.appendChild(canvas);
|
||||
target = document.body;
|
||||
}
|
||||
|
||||
target.appendChild(canvas);
|
||||
|
||||
return canvas;
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user