forked from ibm-js/delite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackgroundIframe.js
66 lines (59 loc) · 1.46 KB
/
BackgroundIframe.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** @module delite/BackgroundIframe */
define([
"dcl/dcl",
"./features"
], function (dcl, has) {
/**
* Cache of iframes.
* @constructor
*/
var Frames = function () {
var queue = [];
this.pop = function () {
var iframe;
if (queue.length) {
iframe = queue.pop();
iframe.style.display = "";
} else {
iframe = document.createElement("iframe");
iframe.src = "javascript:''";
iframe.className = "d-background-iframe";
iframe.setAttribute("role", "presentation");
// Magic to prevent iframe from getting focus on tab keypress - as style didn't work.
iframe.tabIndex = -1;
}
return iframe;
};
this.push = function (iframe) {
iframe.style.display = "none";
queue.push(iframe);
};
};
var _frames = new Frames();
/**
* Makes a background iframe as a child of node. Iframe fills area (and position) of node.
* @param {Element} node
* @class module:delite/BackgroundIframe
*/
return dcl(/** @lends module:delite/BackgroundIframe# */ {
declaredClass: "delite/BackgroundIframe",
constructor: function (node) {
if (has("config-bgIframe")) {
var iframe = (this.iframe = _frames.pop());
node.appendChild(iframe);
iframe.style.width = "100%";
iframe.style.height = "100%";
}
},
/**
* Destroy the iframe.
*/
destroy: function () {
if (this.iframe) {
this.iframe.parentNode.removeChild(this.iframe);
_frames.push(this.iframe);
delete this.iframe;
}
}
});
});