Skip to content

Commit 1fc8930

Browse files
authored
Merge pull request #78 from SpringRoll/develop
Develop
2 parents 535131b + b3860f3 commit 1fc8930

File tree

10 files changed

+30
-13
lines changed

10 files changed

+30
-13
lines changed

.github/workflows/npm-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- name: build
2424
run: |
25-
npm run build:full
25+
npm run build
2626
env:
2727
CI: true
2828

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ container.openPath('local/path/to/game.html');
4242
### Opening a Game Hosted at Another Domain
4343

4444
```javascript
45-
const container = new Container({
46-
iframeSelector: '#game'
47-
});
45+
const container = new Container('#game');
4846

4947
container.openLocal('https://example.com/path/to/game.html');
5048
```
@@ -72,6 +70,20 @@ const container = new Container('#game', {
7270
container.openPath('path/to/game.html');
7371
```
7472

73+
### Opening a Game with a Dynamically Created Iframe
74+
In some cases, you may have an existing [HTMLIframeElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement) rather than a CSS selector.
75+
You can also instantiate a container from the DOM element as well:
76+
77+
```javascript
78+
import { Container } from 'springroll-container';
79+
80+
const iframe = document.createElement('iframe');
81+
document.body.appendChild(iframe);
82+
83+
const container = new Container(iframe);
84+
container.openPath('/path/to/game.html');
85+
```
86+
7587
## Plugins
7688
This section provides instructions on how to use the built-in plugins for SpringRoll Container. For writing or updating older plugins, see the [Plugin Authoring Guide](https://github.com/SpringRoll/SpringRollContainer/tree/main/src/plugins).
7789

dist/SpringRoll-Container-umd.js

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

dist/SpringRoll-Container-umd.js.map

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

dist/index.js

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

dist/index.js.map

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-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": "springroll-container",
3-
"version": "2.0.3",
3+
"version": "2.1.0",
44
"description": "The iframe controller for interacting with SpringRoll applications",
55
"main": "./dist/index.js",
66
"license": "MIT",

src/Container.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ export class Container extends PluginManager {
1919
/**
2020
*Creates an instance of Container.
2121
* @param {object} config
22-
* @param {string} iframeSelector
22+
* @param {string | HTMLIFrameElement} iframeOrSelector
2323
* @param {Array<BasePlugin> | null} [config.plugins=[]]
2424
* @memberof Container
2525
*/
26-
constructor(iframeSelector, { plugins } = {}) {
26+
constructor(iframeOrSelector, { plugins } = {}) {
2727
super({ plugins });
2828

29-
this.iframe = document.querySelector(iframeSelector);
29+
this.iframe = iframeOrSelector instanceof HTMLIFrameElement ? iframeOrSelector : document.querySelector(iframeOrSelector);
3030

3131
if (null === this.iframe) {
3232
throw new Error('No iframe was found with the provided selector');
3333
}
34+
3435
this.loaded = false;
3536
this.loading = false;
3637
this.release = null;

src/Container.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ describe('Container', () => {
1414
expect(container).to.be.instanceof(Container);
1515
});
1616

17+
it('should contruct with a Iframe DOM element', () => {
18+
new Container(iframe);
19+
});
20+
1721
it('.onLoadDone()', () => {
1822
container.onLoadDone();
1923
expect(container.loading).to.be.false;

0 commit comments

Comments
 (0)