Better embeding support + example

This commit is contained in:
Michael Wyraz 2021-11-02 22:03:48 +01:00
parent e76c9910d0
commit 4be1964c56
4 changed files with 35 additions and 1 deletions

View File

@ -1,6 +1,6 @@
module.exports = function (gulp, plugins, config) {
return function copy() {
gulp.src(['html/*.html', 'assets/favicon/*'])
gulp.src(['html/*.html', 'html/*.js', 'assets/favicon/*'])
.pipe(gulp.dest(config.build));
gulp.src(['assets/logo.svg', 'service-worker.js'])
.pipe(gulp.dest(config.build));

6
html/embed.html Normal file
View File

@ -0,0 +1,6 @@
<html>
<iframe src="./index.html" style="border: 1px solid red; width: 95%; height: 95%" id="meshviewer-embedded"></iframe>
<script type="text/javascript" src="./embed.js" />
</html>

24
html/embed.js Normal file
View File

@ -0,0 +1,24 @@
(function() {
var iframe=document.getElementById("meshviewer-embedded")
if (!iframe) {
console.log("IFrame 'meshviewer-embedded' not found")
return;
}
if (!iframe.contentWindow) {
console.log("Element 'meshviewer-embedded' seems not to be a valid iframe")
return;
}
if (document.location.hash) {
window.setTimeout(function() {
iframe.contentWindow.location.hash = document.location.hash;
}, 0);
}
iframe.contentWindow.addEventListener("message", (event) => {
if (event && event.data && event.data.hash) {
window.location.hash = event.data.hash;
}
}, false);
window.onhashchange = function () {
iframe.contentWindow.location.hash = document.location.hash;
};
}) ();

View File

@ -71,6 +71,10 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'],
};
}
window.onhashchange = function () {
window.postMessage({hash: window.location.hash}, '*');
};
var language = new Language();
window.router = new Router(language);