forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddToDOM.js
More file actions
49 lines (42 loc) · 1.03 KB
/
Copy pathAddToDOM.js
File metadata and controls
49 lines (42 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* [description]
*
* @function Phaser.Dom.AddToDOM
* @since 3.0.0
*
* @param {any} element - [description]
* @param {any} parent - [description]
* @param {boolean} [overflowHidden=true] - [description]
*
* @return {any} [description]
*/
var AddToDOM = function (element, parent, overflowHidden)
{
if (overflowHidden === undefined) { overflowHidden = true; }
var target;
if (parent)
{
if (typeof parent === 'string')
{
// Hopefully an element ID
target = document.getElementById(parent);
}
else if (typeof parent === 'object' && parent.nodeType === 1)
{
// Quick test for a HTMLelement
target = parent;
}
}
// Fallback, covers an invalid ID and a non HTMLelement object
if (!target)
{
target = document.body;
}
if (overflowHidden && target.style)
{
target.style.overflow = 'hidden';
}
target.appendChild(element);
return element;
};
module.exports = AddToDOM;