27
27
* @author Anders Evenrud <andersevenrud@gmail.com>
28
28
* @licence Simplified BSD License
29
29
*/
30
+ import osjs from 'osjs' ;
31
+ import { name as applicationName } from './metadata.json' ;
30
32
31
- const createIframe = ( bus , proc , win , cb ) => {
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
32
54
const iframe = document . createElement ( 'iframe' ) ;
33
55
iframe . style . width = '100%' ;
34
56
iframe . style . height = '100%' ;
@@ -51,15 +73,28 @@ const createIframe = (bus, proc, win, cb) => {
51
73
bus . emit ( data . method , sendMessage , ...data . args ) ;
52
74
} ) ;
53
75
54
- cb ( sendMessage ) ;
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
+ } ) ;
55
86
} ) ;
56
87
57
- return iframe ;
88
+ // Finally set the source and attach
89
+ iframe . src = src ;
90
+
91
+ // Attach
92
+ $content . appendChild ( iframe ) ;
58
93
} ;
59
94
60
95
// Creates the internal callback function when OS.js launches an application
61
96
// Note the first argument is the 'name' taken from your metadata.json file
62
- OSjs . make ( 'osjs/packages' ) . register ( 'MyIframeApplication' , ( core , args , options , metadata ) => {
97
+ const register = ( core , args , options , metadata ) => {
63
98
64
99
// Create a new Application instance
65
100
const proc = core . make ( 'osjs/application' , {
@@ -76,33 +111,14 @@ OSjs.make('osjs/packages').register('MyIframeApplication', (core, args, options,
76
111
position : { left : 700 , top : 200 }
77
112
} )
78
113
. on ( 'destroy' , ( ) => proc . destroy ( ) )
79
- . render ( ( $content , win ) => {
80
- // Create a new bus for our messaging
81
- const bus = core . make ( 'osjs/event-handler' , 'MyIframeApplicationWindow' ) ;
82
-
83
- // Get path to iframe content
84
- const src = proc . resource ( '/data/index.html' ) ;
85
-
86
- // Create DOM element
87
- const iframe = createIframe ( bus , proc , win , send => {
88
- bus . on ( 'yo' , ( send , args ) => send ( {
89
- method : 'yo' ,
90
- args : [ 'MyIframeApplication says hello' ]
91
- } ) ) ;
92
-
93
- // Send the process ID to our iframe to establish communication
94
- send ( {
95
- method : 'init' ,
96
- args : [ proc . pid ]
97
- } ) ;
98
- } ) ;
99
-
100
- // Finally set the source and attach
101
- iframe . src = src ;
102
-
103
- // Attach
104
- $content . appendChild ( iframe ) ;
105
- } ) ;
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));
106
120
107
121
return proc ;
108
- } ) ;
122
+ } ;
123
+
124
+ osjs . register ( applicationName , register ) ;
0 commit comments