Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Feature/embedding #317

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,26 @@ Standalone: https://regensburg.freifunk.net/meshviewer/
- [POEditor](https://poeditor.com/join/project/VZBjPNNic9) for providing an easy non-developer translation environment

These tools need a lot of infrastructures and provide a free account for open source software.

## Building / Running

Required tools:
* yarn
* gulp

1st install the dependencies by running
```
yarn
```

Then you can start a development server with
```
gulp serve
```

To build a release, run
```
gulp
```

The result will be in the "build" folder afterwards.
2 changes: 1 addition & 1 deletion gulp/tasks/copy.js
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
6 changes: 6 additions & 0 deletions html/embed.html
Original file line number Diff line number Diff line change
@@ -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>
35 changes: 35 additions & 0 deletions html/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(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;
}

function updateIframeHash() { // see https://gist.github.com/manufitoussi/7529fa882ff0b737f257
if(iframe.contentWindow.location.host !== "") {
// iframe already loaded.
iframe.contentWindow.location.hash = window.location.hash;
} else {
// iframe is just starting.
var newHash = window.location.hash;
var srcStr = iframe.getAttribute('src');
var words = srcStr.split('#');
var href = words[0];
var newSrc = href + newHash;
iframe.setAttribute('src', newSrc);
}
};

updateIframeHash();
iframe.contentWindow.addEventListener("message", (event) => {
if (event && event.data && event.data.hash) {
window.location.replace(event.data.hash);
}
}, false);
window.onhashchange = updateIframeHash;
}) ();
4 changes: 4 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down