Skip to content

Commit

Permalink
First working version
Browse files Browse the repository at this point in the history
  • Loading branch information
renaatdemuynck committed Feb 27, 2018
1 parent a5cfd4e commit 23bf449
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# LTI-IFrame-Autoresizer
Automatically resize the iframe of an LTI tool
# LTI IFrame Autoresizer
Automatically resizes the iframe of an LTI tool

## Installation

From NPM:

```sh
npm install lti-iframe-autoresizer
```

From Yarn:

```sh
yarn add lti-iframe-autoresizer
```

## Usage Example

```javascript
import LtiResizer from 'lti-iframe-autoresizer';

LtiResizer.init();
```
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "LTI-IFrame-Autoresizer",
"version": "1.0.0",
"description": "Automatically resize the iframe of an LTI tool",
"main": "src/autoresizer.js",
"repository": "https://github.com/renaatdemuynck/LTI-IFrame-Autoresizer.git",
"author": "Renaat De Muynck <[email protected]>",
"license": "MIT"
}
27 changes: 27 additions & 0 deletions src/autoresizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file Automatically resize the iframe of an LTI tool
* @author Renaat De Muynck <[email protected]>
* @license MIT
*/

import ResizeObserver from 'resize-observer-polyfill';
import Messenger from 'lti-messaging';

export default {

init: function () {
// Don't run if not in iframe
if (window.parent === window) return;

document.addEventListener('DOMContentLoaded', function () {
const resizeObserver = new ResizeObserver(Messenger.frameResize);

// Request iframe resize when content is loaded
Messenger.frameResize();

// Request iframe resize when body changes size
resizeObserver.observe(document.body);
});
}

};

0 comments on commit 23bf449

Please sign in to comment.