Skip to content

Commit 754cd26

Browse files
authored
Iframe lazy loading (ITISFoundation#2790)
1 parent 4fe88ae commit 754cd26

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

services/web/client/source/class/osparc/component/widget/PersistentIframe.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ qx.Class.define("osparc.component.widget.PersistentIframe", {
3636

3737
getMaximizeWidgetId: function(maximize) {
3838
return maximize ? "restoreBtn" : "maximizeBtn";
39-
}
39+
},
40+
41+
HIDDEN_TOP: -10000
4042
},
4143

4244
properties: {
@@ -96,7 +98,7 @@ qx.Class.define("osparc.component.widget.PersistentIframe", {
9698
let standin = new qx.html.Element("div");
9799
let appRoot = this.getApplicationRoot();
98100
appRoot.add(iframe, {
99-
top:-10000
101+
top: this.self().HIDDEN_TOP
100102
});
101103
const restartButton = this.__restartButton = new qx.ui.form.Button(null, "@FontAwesome5Solid/redo-alt/14").set({
102104
zIndex: 20,
@@ -112,7 +114,7 @@ qx.Class.define("osparc.component.widget.PersistentIframe", {
112114
}, this);
113115
osparc.utils.Utils.setIdToWidget(restartButton, "iFrameRestartBtn");
114116
appRoot.add(restartButton, {
115-
top:-10000
117+
top: this.self().HIDDEN_TOP
116118
});
117119
let zoomButton = this.__zoomButton = new qx.ui.form.Button(null).set({
118120
icon: this.self().getZoomIcon(false),
@@ -122,7 +124,7 @@ qx.Class.define("osparc.component.widget.PersistentIframe", {
122124
});
123125
osparc.utils.Utils.setIdToWidget(zoomButton, this.self().getMaximizeWidgetId(false));
124126
appRoot.add(zoomButton, {
125-
top:-10000
127+
top: this.self().HIDDEN_TOP
126128
});
127129
zoomButton.addListener("execute", e => {
128130
this.maximizeIFrame(!this.hasState("maximized"));
@@ -133,13 +135,13 @@ qx.Class.define("osparc.component.widget.PersistentIframe", {
133135
});
134136
standin.addListener("disappear", e => {
135137
iframe.setLayoutProperties({
136-
top: -10000
138+
top: this.self().HIDDEN_TOP
137139
});
138140
restartButton.setLayoutProperties({
139-
top: -10000
141+
top: this.self().HIDDEN_TOP
140142
});
141143
zoomButton.setLayoutProperties({
142-
top: -10000
144+
top: this.self().HIDDEN_TOP
143145
});
144146
});
145147
this.addListener("move", e => {

services/web/client/source/class/osparc/data/model/Node.js

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -888,41 +888,32 @@ qx.Class.define("osparc.data.model.Node", {
888888

889889
const iframe = new osparc.component.widget.PersistentIframe();
890890
osparc.utils.Utils.setIdToWidget(iframe, "PersistentIframe");
891-
iframe.addListener("restart", () => {
892-
this.__restartIFrame();
893-
}, this);
891+
iframe.addListener("restart", () => this.__restartIFrame(), this);
894892
this.setIFrame(iframe);
895893
},
896894

897895
__restartIFrame: function() {
898896
if (this.getServiceUrl() !== null) {
899-
this.getIFrame().resetSource();
900-
if (this.getKey().includes("3d-viewer")) {
901-
// HACK: add this argument to only load the defined colorMaps
902-
// https://github.com/Kitware/visualizer/commit/197acaf
903-
const srvUrl = this.getServiceUrl();
904-
let arg = "?serverColorMaps";
905-
if (srvUrl[srvUrl.length - 1] !== "/") {
906-
arg = "/" + arg;
907-
}
908-
this.getIFrame().setSource(srvUrl + arg);
909-
} else {
897+
const loadIframe = () => {
898+
this.getIFrame().resetSource();
910899
this.getIFrame().setSource(this.getServiceUrl());
900+
};
901+
902+
// restart button pushed
903+
if (this.getIFrame().getSource().includes(this.getServiceUrl())) {
904+
loadIframe();
911905
}
912906

913-
if (this.getKey().includes("raw-graphs")) {
914-
// Listen to the postMessage from RawGraphs, posting a new graph
915-
window.addEventListener("message", e => {
916-
const {
917-
id,
918-
imgData
919-
} = e.data;
920-
if (imgData && id === "svgChange") {
921-
const img = document.createElement("img");
922-
img.src = imgData;
923-
this.setThumbnail(img.outerHTML);
924-
}
925-
}, false);
907+
const loadingPage = this.getLoadingPage();
908+
const bounds = loadingPage.getBounds();
909+
const domEle = loadingPage.getContentElement().getDomElement();
910+
const boundsCR = domEle ? domEle.getBoundingClientRect() : null;
911+
if (bounds !== null && boundsCR && boundsCR.width > 0) {
912+
loadIframe();
913+
} else {
914+
// lazy loading
915+
console.debug("lazy load", this.getNodeId());
916+
loadingPage.addListenerOnce("appear", () => loadIframe(), this);
926917
}
927918
}
928919
},

0 commit comments

Comments
 (0)