30
30
import osjs from 'osjs' ;
31
31
import { name as applicationName } from './metadata.json' ;
32
32
33
- const createSimpleIframe = ( core , proc ) => ( $content , win ) => {
34
- const iframe = document . createElement ( 'iframe' ) ;
35
- iframe . style . width = '100%' ;
36
- iframe . style . height = '100%' ;
37
- iframe . setAttribute ( 'border' , '0' ) ;
38
-
39
- const src = proc . resource ( '/data/index.html' ) ;
40
- iframe . src = src ;
41
-
42
- $content . appendChild ( iframe ) ;
43
- } ;
44
-
45
- const createIframe = ( core , proc ) => ( $content , win ) => {
46
-
47
- // Create a new bus for our messaging
48
- const bus = core . make ( 'osjs/event-handler' , 'MyIframeApplicationWindow' ) ;
49
-
50
- // Get path to iframe content
51
- const src = proc . resource ( '/data/index.html' ) ;
52
-
53
- // Create DOM element
54
- const iframe = document . createElement ( 'iframe' ) ;
55
- iframe . style . width = '100%' ;
56
- iframe . style . height = '100%' ;
57
- iframe . setAttribute ( 'border' , '0' ) ;
58
-
59
- iframe . addEventListener ( 'load' , ( ) => {
60
- const ref = iframe . contentWindow ;
61
-
62
- // This will proxy the window focus events to iframe
63
- win . on ( 'focus' , ( ) => ref . focus ( ) ) ;
64
- win . on ( 'blur' , ( ) => ref . blur ( ) ) ;
65
-
66
- // Create message sending wrapper
67
- const sendMessage = msg => ref . postMessage ( msg , window . location . href ) ;
68
-
69
- // After connection is established, this handler will process
70
- // all events coming from iframe.
71
- proc . on ( 'message' , data => {
72
- console . warn ( '[Application' , 'Iframe sent' , data ) ;
73
- bus . emit ( data . method , sendMessage , ...data . args ) ;
74
- } ) ;
75
-
76
- bus . on ( 'yo' , ( send , args ) => sendMessage ( {
77
- method : 'yo' ,
78
- args : [ 'MyIframeApplication says hello' ]
79
- } ) ) ;
80
-
81
- // Send the process ID to our iframe to establish communication
82
- sendMessage ( {
83
- method : 'init' ,
84
- args : [ proc . pid ]
85
- } ) ;
86
- } ) ;
87
-
88
- // Finally set the source and attach
89
- iframe . src = src ;
90
-
91
- // Attach
92
- $content . appendChild ( iframe ) ;
93
- } ;
94
-
95
33
// Creates the internal callback function when OS.js launches an application
96
34
// Note the first argument is the 'name' taken from your metadata.json file
97
35
const register = ( core , args , options , metadata ) => {
@@ -111,12 +49,14 @@ const register = (core, args, options, metadata) => {
111
49
position : { left : 700 , top : 200 }
112
50
} )
113
51
. on ( 'destroy' , ( ) => proc . destroy ( ) )
114
-
115
- // Create an iframe with messaging etc
116
- . render ( createIframe ( core , proc ) ) ;
117
-
118
- // Or just a simple standard iframe
119
- // .render(createIframe(core, proc));
52
+ . render ( $content => {
53
+ const iframe = document . createElement ( 'iframe' ) ;
54
+ iframe . style . width = '100%' ;
55
+ iframe . style . height = '100%' ;
56
+ iframe . src = proc . resource ( '/data/index.html' ) ;
57
+ iframe . setAttribute ( 'border' , '0' ) ;
58
+ $content . appendChild ( iframe ) ;
59
+ } ) ;
120
60
121
61
return proc ;
122
62
} ;
0 commit comments