Skip to content

Commit bd85584

Browse files
Add eventlistener to body after DOM is loaded (#38)
1 parent 1d59657 commit bd85584

File tree

7 files changed

+117
-9
lines changed

7 files changed

+117
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Next Release
22
-------------
33

4+
1.7.2
5+
------
6+
* Fix Image resizing for slow loading images by calling on document.
7+
48
1.7.1
59
------
610
* Add Image resizing for slow loading images.

example/initialization/1_d_index.html

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE html>
2+
<html lang="en-us">
3+
<head>
4+
<title>Embedded Content Consuming Site</title>
5+
<meta charset="utf-8" />
6+
<script src="http://localhost:8080/xfc.js"></script>
7+
<style>
8+
iframe {
9+
width: 100%;
10+
border: none;
11+
margin: 0;
12+
padding: 0;
13+
}
14+
html[hidden] { display: none; }
15+
.xfc[data-status='mounted'] {
16+
border: 5px dashed #000;
17+
}
18+
.xfc[data-status='launched'] {
19+
border: 5px dashed #00F;
20+
}
21+
.xfc[data-status='authorized'] {
22+
border: 5px dashed #0F0;
23+
}
24+
.grid {
25+
display: flex;
26+
flex-flow: row wrap;
27+
}
28+
.grid div {
29+
padding: 20px;
30+
}
31+
#c1 {
32+
border: 5px dashed #000;
33+
}
34+
#c2 {
35+
border: 5px dashed #00F;
36+
}
37+
#c3 {
38+
border: 5px dashed #0F0;
39+
}
40+
</style>
41+
</head>
42+
<body>
43+
<div>
44+
<h2>The following are XFC's statuses (mounted, launched, authorized).</h2>
45+
</div>
46+
<div class="grid">
47+
<div id="c1">
48+
<h2>mounted app</h2>
49+
</div>
50+
<p></p>
51+
<div id="c2">
52+
<h2>launched app</h2>
53+
</div>
54+
<p></p>
55+
<div id="c3">
56+
<h2>authorized app</h2>
57+
</div>
58+
</div>
59+
<p>This example shows that the image resizing event is called only after the DOM is loaded</p>
60+
<script>
61+
XFC.Consumer.init()
62+
XFC.Consumer.mount(document.body, 'http://localprovider.com:8080/example/initialization/1_d_provider.html');
63+
</script>
64+
</body>
65+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en-us">
3+
<head>
4+
<title>HealtheLife Trusted Site</title>
5+
<meta charset="utf-8" />
6+
<style>
7+
body {
8+
padding-bottom: 5px;
9+
}
10+
html[hidden] { display: none; }
11+
</style>
12+
<script src="http://localhost:8080/xfc.js"></script>
13+
<script type="text/javascript">
14+
XFC.Provider.init({ acls: ['*'] })
15+
</script>
16+
</head>
17+
<body>
18+
<div>
19+
<h1>1. Initialization</h1>
20+
<p>The image resizing event(imageRequestResize) is called only after the DOM is loaded.</p>
21+
</div>
22+
</body>
23+
</html>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xfc",
3-
"version": "1.7.1",
3+
"version": "1.7.2",
44
"description": "A Cross Frame Container that handles securely embedding web content into a 3rd party domain",
55
"author": "Cerner Corporation",
66
"license": "Apache-2.0",

src/provider/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Application extends EventEmitter {
3232
this.unload = this.unload.bind(this);
3333

3434
// Resize for slow loading images
35-
document.body.addEventListener('load', this.imageRequestResize.bind(this), true);
35+
document.addEventListener('load', this.imageRequestResize.bind(this), true);
3636

3737
// If the document referer (parent frame) origin is trusted, default that
3838
// to the active ACL;

test/application.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ describe('Application', () => {
1717
const application = new Application();
1818

1919
const oldDocument = global.document;
20-
global.document = {referrer: 'http://localhost:8080', createElement: document.createElement.bind(document), body: { addEventListener: () => console.log('mock addEventListener') } };
20+
global.document = {
21+
referrer: 'http://localhost:8080',
22+
createElement: document.createElement.bind(document),
23+
addEventListener: () => console.log('mock addEventListener')
24+
};
2125
application.init({acls, secret, onReady});
2226
global.document = oldDocument;
2327

@@ -27,7 +31,11 @@ describe('Application', () => {
2731

2832
it ("doesn't set activeACL to document referrer if not in ACL", () => {
2933
const insecureApp = new Application();
30-
global.document = {referrer: 'http://evilsite.com', createElement: document.createElement.bind(document), body: { addEventListener: () => console.log('mock addEventListener') } };
34+
global.document = {
35+
referrer: 'http://evilsite.com',
36+
createElement: document.createElement.bind(document),
37+
addEventListener: () => console.log('mock addEventListener')
38+
};
3139
insecureApp.init({acls, secret, onReady});
3240
global.document = oldDocument;
3341

@@ -49,10 +57,10 @@ describe('Application', () => {
4957
it("sets application's JSONRPC", () => {
5058
expect(application.JSONRPC).to.be.an.instanceof(JSONRPC);
5159
});
52-
60+
5361
it("calls addEventListener", sinon.test(function() {
54-
sinon.spy(document.body, 'addEventListener');
55-
expect(document.body.addEventListener.calledOnce);
62+
sinon.spy(document, 'addEventListener');
63+
expect(document.addEventListener.calledOnce);
5664
}));
5765

5866
describe('#trigger(event, detail)', () => {
@@ -298,7 +306,7 @@ describe('Application', () => {
298306
sinon.assert.notCalled(requestResize);
299307
}));
300308
});
301-
309+
302310
describe('#requestResize()', () => {
303311
it("does not resize when resizeConfig is null", sinon.test(function() {
304312
const application = new Application();
@@ -339,9 +347,17 @@ describe('Application', () => {
339347
addEventListener: () => console.log('mock addEventListener'),
340348
top: { length: -1 },
341349
};
350+
const oldDocument = global.document;
351+
global.document = {
352+
referrer: 'http://localhost:8080',
353+
createElement: document.createElement.bind(document),
354+
addEventListener: () => console.log('mock addEventListener'),
355+
body: (function () { return; })()
356+
};
342357

343358
const application = new Application();
344359
application.init({ acls: ['http://localhost:8080'] });
360+
global.document = oldDocument;
345361
sinon.spy(window, 'addEventListener');
346362

347363
application.launch();

0 commit comments

Comments
 (0)