https://github.com/samthor/iframe-load
Swappable iframe loader
https://github.com/samthor/iframe-load
Last synced: about 1 year ago
JSON representation
Swappable iframe loader
- Host: GitHub
- URL: https://github.com/samthor/iframe-load
- Owner: samthor
- License: apache-2.0
- Created: 2019-11-27T07:04:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-08T11:13:09.000Z (over 5 years ago)
- Last Synced: 2025-01-18T15:52:54.612Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://npmjs.com/iframe-load
- Size: 38.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Swappable iframe loader, inspired by [Santa Tracker](https://santatracker.google.com) 🎅
Provides a JS class which loads and can swap between hosted iframes.
This is useful for sites which are "hosts" for games or other experiences (which can be useful to isolate parts of your site).
# Usage
```js
import {Loader, LoaderHandler} from 'iframe-load';
const handler = new (class extends LoaderHandler {
// optional callbacks here, see main.js
});
const container = document.body; // or somewhere in DOM to place
const loader = new Loader(container, handler);
loader.load('./page.html', context).then((result) => {
if (result === undefined) {
// was preempted by some other load
} else {
// otherwise, the iframe's load event was called (or the frame failed to load)
}
});
```
By default, the loader sets `tabindex="-1"` and a style of `pointer-events: none` on any frame while it is disabled.
This can be overridden (along with other helpers) by subclassing `Loader` and changing its static helpers.
## Advanced
The created loader can have its `.disabled` property set to disable user interaction with its frames.
It also has method `.focus()` and property `.hasFocus`.
# TODO
This readme is fairly sparse.