Skip to content

Commit a763e53

Browse files
committed
fix(iframe): Try out the iframe approach
1 parent e81afc0 commit a763e53

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Angular 2 decorators and services
3+
*/
4+
import {Component, Input, OnInit, ElementRef, Injector} from '@angular/core';
5+
import * as path from 'path';
6+
7+
/*
8+
* App Component
9+
* Top Level Component
10+
*/
11+
@Component({
12+
// The selector is what angular internally uses
13+
selector: 'cb-iframe', // <app></app>
14+
// The template for our app
15+
template: `<iframe scrolling="no" frameBorder="0" style="width: '100%', height: '100%'"></iframe>
16+
`
17+
})
18+
export class IframeComponent implements OnInit {
19+
@Input() basePath: string;
20+
userBundle: string;
21+
element: HTMLElement;
22+
iframe: any;
23+
24+
constructor(private _ref: ElementRef) {
25+
}
26+
27+
ngOnInit() {
28+
//console.log(this.basePath);
29+
//this.userBundle = path.join(this.basePath, 'user-bundle.js');
30+
this.userBundle = '';
31+
this.element = this._ref.nativeElement;
32+
this.iframe = this.element.children[0];
33+
console.log(this.iframe);
34+
const doc = this.iframe.contentDocument;
35+
doc.open();
36+
// eslint-disable-next-line max-len
37+
doc.write(this.createHTML(this.userBundle));
38+
doc.close();
39+
}
40+
41+
createHTML(userbundle) {
42+
return `<!DOCTYPE html>
43+
<html style="height: 100%; width: 100%; margin: 0; padding: 0;">
44+
<head>
45+
</head>
46+
<body style="height: 100%; width: 100%; margin: 0; padding: 0;">
47+
<div
48+
id="root"
49+
style="
50+
display: flex;
51+
justify-content: center;
52+
align-items: center;
53+
height: 100vh;
54+
">
55+
<cb-app>
56+
<div class="new-element">
57+
<cb-button [text]="Loading Component" [isRed]="false"></cb-button>
58+
</div>
59+
</cb-app>
60+
61+
</div>
62+
<script type="text/javascript" src="http://localhost:3000/main.js"></script></body>
63+
</body>
64+
</html>`;
65+
}
66+
}

frontend/src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { customMetadataFormComponent } from './app/components/customMetadataForm
2929
import { Playlist } from './app/components/playlist/playlist.component.ts';
3030
import { PlaylistList } from './app/components/playlistList/playlistList.component.ts';
3131
import { DynamicOutlet } from './app/components/dynamicOutlet/dynamicOutlet.component.ts';
32+
import { IframeComponent } from './app/components/iframe/iframe.component.ts';
3233
import { EditVariationFormComponent } from './app/components/editVariationForm/editVariationForm.component.ts';
3334

3435
@NgModule({
@@ -44,6 +45,7 @@ import { EditVariationFormComponent } from './app/components/editVariationForm/e
4445
Playlist,
4546
PlaylistList,
4647
DynamicOutlet,
48+
IframeComponent,
4749
EditVariationFormComponent,
4850
],
4951
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpModule],

0 commit comments

Comments
 (0)