@@ -26,6 +26,28 @@ qx.Class.define("osparc.widget.PersistentIframe", {
2626 */
2727 construct : function ( source , el ) {
2828 this . base ( arguments , source ) ;
29+
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 ) ;
2951 } ,
3052
3153 statics : {
@@ -87,7 +109,14 @@ qx.Class.define("osparc.widget.PersistentIframe", {
87109 // override
88110 _createContentElement : function ( ) {
89111 let iframe = this . __iframe = new qx . ui . embed . Iframe ( this . getSource ( ) ) ;
90- iframe . addListener ( "load" , ( ) => this . fireEvent ( "load" ) ) ;
112+ const persistentIframe = this ;
113+ iframe . addListener ( "load" , ( ) => {
114+ const currentTheme = qx . theme . manager . Meta . getInstance ( ) . getTheme ( ) ;
115+ if ( currentTheme && persistentIframe . postThemeSwitch ) {
116+ persistentIframe . postThemeSwitch ( currentTheme . name ) ;
117+ }
118+ this . fireEvent ( "load" ) ;
119+ } ) ;
91120 iframe . addListener ( "navigate" , e => this . fireDataEvent ( "navigate" , e . getData ( ) ) ) ;
92121
93122 let standin = new qx . html . Element ( "div" ) ;
@@ -251,5 +280,6 @@ qx.Class.define("osparc.widget.PersistentIframe", {
251280 this . __iframe . exclude ( ) ;
252281 this . __iframe . dispose ( ) ;
253282 this . __iframe = undefined ;
283+ qx . event . message . Bus . getInstance ( ) . unsubscribe ( "themeSwitch" , this . themeSwitchHandler ) ;
254284 }
255285} ) ;
0 commit comments