Skip to content

Commit 449853e

Browse files
committed
switch theme driven by the iframe
1 parent 4860602 commit 449853e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

services/static-webserver/client/source/class/osparc/widget/PersistentIframe.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)