File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
services/static-webserver/client/source/class/osparc/widget Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,41 @@ qx.Class.define("osparc.widget.PersistentIframe", {
267267 this . postThemeSwitch ( msg . getData ( ) ) ;
268268 } ;
269269 qx . event . message . Bus . getInstance ( ) . subscribe ( "themeSwitch" , this . themeSwitchHandler ) ;
270+
271+ // listen to messages
272+ this . __iframe . addListener ( "load" , ( ) => {
273+ const iframe = this . _getIframeElement ( ) ;
274+ if ( iframe ) {
275+ const iframeDomEl = iframe . getDomElement ( ) ;
276+ if ( iframeDomEl ) {
277+ const iframeWindow = iframe . getDomElement ( ) . contentWindow ;
278+ window . addEventListener ( 'message' , message => {
279+ if ( message . source === iframeWindow ) {
280+ const data = message . data ;
281+ if ( data ) {
282+ this . __handleIframeMessage ( data ) ;
283+ }
284+ }
285+ } ) ;
286+ }
287+ }
288+ } , this ) ;
289+ } ,
290+
291+ __handleIframeMessage : function ( data ) {
292+ // switch theme driven by the iframe
293+ if ( data [ "type" ] && data [ "type" ] === "theme" ) {
294+ const message = data [ "message" ] ;
295+ console . log ( message ) ;
296+ if ( message . includes ( "osparc;theme=" ) ) {
297+ const themeName = message . replace ( "osparc;theme=" , "" ) ;
298+ const validThemes = osparc . ui . switch . ThemeSwitcher . getValidThemes ( ) ;
299+ const themeFound = validThemes . find ( theme => theme . basename === themeName ) ;
300+ if ( themeFound ) {
301+ qx . theme . manager . Meta . getInstance ( ) . setTheme ( themeFound ) ;
302+ }
303+ }
304+ }
270305 } ,
271306
272307 // override
You can’t perform that action at this time.
0 commit comments