mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
f70e1b1e29
no issue - Added billing update button to navigation menu. Ghost-Admin communicates with billing iframe and displays this button based on the plan data that iframe returns - Ghost-Admin communicates with an iframe using same mechanism as with token exchange - throu `window.postMessage` API
26 lines
945 B
JavaScript
26 lines
945 B
JavaScript
import Component from '@ember/component';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default Component.extend({
|
|
billing: service(),
|
|
config: service(),
|
|
ghostPaths: service(),
|
|
ajax: service(),
|
|
|
|
didRender() {
|
|
let iframe = this.element.querySelector('#billing-frame');
|
|
window.addEventListener('message', (event) => {
|
|
if (event && event.data && event.data.request === 'token') {
|
|
const ghostIdentityUrl = this.get('ghostPaths.url').api('identities');
|
|
|
|
this.ajax.request(ghostIdentityUrl).then((response) => {
|
|
const token = response && response.identities && response.identities[0] && response.identities[0].token;
|
|
iframe.contentWindow.postMessage({
|
|
request: 'token',
|
|
response: token
|
|
}, '*');
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|