From a4ac22c9416297a8f8d53069c2b61ac7dfe84689 Mon Sep 17 00:00:00 2001 From: Flowtter Date: Thu, 5 Jan 2023 10:17:26 +0100 Subject: [PATCH] Add html property in zones --- core/client/scenes/scene-world.js | 7 ++++--- core/client/url-opener.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/client/scenes/scene-world.js b/core/client/scenes/scene-world.js index bc494be7..2ae58800 100644 --- a/core/client/scenes/scene-world.js +++ b/core/client/scenes/scene-world.js @@ -11,22 +11,23 @@ const zoomConfig = Meteor.settings.public.zoom; const onZoneEntered = e => { const { zone } = e.detail; - const { targetedLevelId, inlineURL, url, disableCommunications, style } = zone; + const { targetedLevelId, inlineURL, url, disableCommunications, style, html } = zone; if (targetedLevelId) levelManager.loadLevel(targetedLevelId); else if (inlineURL) characterPopIns.initFromZone(zone); + if (html) URLOpener.openHtml(html, zone.fullscreen, style); if (url) URLOpener.open(url, zone.fullscreen, style); if (disableCommunications) userManager.setUserInDoNotDisturbMode(true); }; const onZoneLeft = e => { const { zone } = e.detail; - const { popInConfiguration, disableCommunications, url } = zone; + const { popInConfiguration, disableCommunications, url, html } = zone; if (!popInConfiguration?.autoOpen) characterPopIns.destroyPopIn(`${Meteor.userId()}-${zone._id}`); - if (url) { + if (url || html) { updateViewport(game.scene.keys.WorldScene, viewportModes.fullscreen); URLOpener.close(); } diff --git a/core/client/url-opener.js b/core/client/url-opener.js index 972eb4b4..d3cc793e 100644 --- a/core/client/url-opener.js +++ b/core/client/url-opener.js @@ -21,6 +21,18 @@ const urlOpener = { webpageContainer: undefined, webpageIframeContainer: undefined, + openHtml(html, fullscreen = false, style = {}) { + var iframe = this.getIframeElement(); + iframe.contentWindow.document.write(html); + iframe.style = new String(Object.keys(style).map(key => `${key}: ${style[key]}`).join(';')); + + this.getWebpageElement().classList.add('show'); + + toggleResizable('.resizableWebpage', true); + updateViewport(game.scene.keys.WorldScene, fullscreen ? viewportModes.small : viewportModes.splitScreen); + updateViewport(game.scene.keys.UIScene, fullscreen ? viewportModes.small : viewportModes.splitScreen); + }, + open(url, fullscreen = false, style = {}) { const allowAttributesRequired = isYoutubeURL(url); const urlToLoad = allowAttributesRequired ? generateEmbeddedYoutubeURL(url) : url;