@@ -27,27 +27,7 @@ qx.Class.define("osparc.widget.PersistentIframe", {
2727 construct : function ( source , el ) {
2828 this . base ( arguments , source ) ;
2929
30- this . themeSwitchHandler = msg => {
31- this . postThemeSwitch ( msg . getData ( ) ) ;
32- } ;
33-
34- this . postThemeSwitch = theme => {
35- const iframe = this . _getIframeElement ( ) ;
36- if ( this . _getIframeElement ( ) ) {
37- const iframeDomEl = iframe . getDomElement ( ) ;
38- const iframeSource = iframe . getSource ( ) ;
39- if ( iframeDomEl && iframeSource ) {
40- const msg = "osparc;theme=" + theme ;
41- try {
42- iframeDomEl . contentWindow . postMessage ( msg , iframeSource ) ;
43- } catch ( err ) {
44- console . log ( `Failed posting message ${ msg } to iframe ${ iframeSource } \n${ err . message } ` ) ;
45- }
46- }
47- }
48- } ;
49-
50- qx . event . message . Bus . getInstance ( ) . subscribe ( "themeSwitch" , this . themeSwitchHandler ) ;
30+ this . __attacheIframeMessageHanders ( ) ;
5131 } ,
5232
5333 statics : {
@@ -265,6 +245,30 @@ qx.Class.define("osparc.widget.PersistentIframe", {
265245 this . __iframe . setSource ( newValue ) ;
266246 } ,
267247
248+ __attacheIframeMessageHanders : function ( ) {
249+ // post messages
250+ this . postThemeSwitch = theme => {
251+ const iframe = this . _getIframeElement ( ) ;
252+ if ( iframe ) {
253+ const iframeDomEl = iframe . getDomElement ( ) ;
254+ const iframeSource = iframe . getSource ( ) ;
255+ if ( iframeDomEl && iframeSource ) {
256+ const msg = "osparc;theme=" + theme ;
257+ try {
258+ iframeDomEl . contentWindow . postMessage ( msg , iframeSource ) ;
259+ } catch ( err ) {
260+ console . log ( `Failed posting message ${ msg } to iframe ${ iframeSource } \n${ err . message } ` ) ;
261+ }
262+ }
263+ }
264+ } ;
265+
266+ this . themeSwitchHandler = msg => {
267+ this . postThemeSwitch ( msg . getData ( ) ) ;
268+ } ;
269+ qx . event . message . Bus . getInstance ( ) . subscribe ( "themeSwitch" , this . themeSwitchHandler ) ;
270+ } ,
271+
268272 // override
269273 _getIframeElement : function ( ) {
270274 return this . __iframe . _getIframeElement ( ) ; // eslint-disable-line no-underscore-dangle
0 commit comments