Skip to content

Commit

Permalink
docs: Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
raido committed Jan 21, 2016
1 parent aeb2f2f commit 5e34552
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,54 @@ export default Ember.Route.extend({
});
```

### iFrames, popup windows

If you want to communicate with an iframe or a popup window opened with `window.open`, then you have to register your window instance on the client with matching target name from `config/environment` map.

#### iFrame

```javascript
// app/components/x-frame.js
import Ember from 'ember';

export default Ember.Component.extend({
client: Ember.inject.service('window-messenger-client'),
target: null

didInsertElement() {
this.get('client').addTarget('target-1', this.$().get(0).contentWindow);
},

willDestroyElement() {
this.get('client').removeTarget('target-1');
}
});

```
#### Popup with window.open

```javascript
// app/components/x-frame.js
import Ember from 'ember';

export default Ember.Route.extend({
client: Ember.inject.service('window-messenger-client'),

actions: {
openPopup() {
let win = window.open('/some/path', 'Example popup', 'toolbar=no,resizable=no,width=400,height=400');
this.get('client').addTarget('popup', win);
},

fetchFromPopup() {
this.get('client').fetch('popup:some-data').then((name) => {
this.controller.set('model', name);
});
}
}
});
```

## Installation

* `git clone` this repository
Expand Down

0 comments on commit 5e34552

Please sign in to comment.