forked from leMaik/rs-sphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewer.html
68 lines (64 loc) · 2.03 KB
/
viewer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html style="margin: 0; padding: 0; overflow: hidden; height: 100%">
<head lang="en">
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=no"
/>
<title></title>
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link
rel="import"
href="bower_components/rs-sphere/rs-sphere-viewer.html"
/>
</head>
<body style="margin: 0; padding: 0; height: 100%">
<form onsubmit="show();return false">
<input type="file" id="left" />
<input type="file" id="right" />
<input type="submit" value="show" />
</form>
<rs-sphere-viewer style="width: 100%; height: 100%"></rs-sphere-viewer>
</body>
<script>
var viewer = document.getElementsByTagName("rs-sphere-viewer")[0];
function fileToBlob(file) {
return new Promise((resolve) => {
var reader = new FileReader();
reader.addEventListener("load", (event) =>
resolve(event.target.result)
);
reader.readAsDataURL(file);
});
}
async function load() {
var left = document.getElementById("left");
var right = document.getElementById("right");
if (left.files.length > 0) {
viewer.setAttribute("src", await fileToBlob(left.files[0]));
} else {
viewer.setAttribute("src", "");
}
if (right.files.length > 0) {
viewer.setAttribute("src-right", await fileToBlob(right.files[0]));
} else {
viewer.setAttribute("src-right", "");
}
document.getElementsByTagName("form")[0].remove();
}
function show() {
load();
return false;
}
var params = new URLSearchParams(new URL(window.location.href).search);
if (params.has("left")) {
viewer.setAttribute("src", params.get("left"));
if (params.has("right")) {
viewer.setAttribute("src-right", params.get("right"));
} else {
viewer.setAttribute("src-right", "");
}
}
</script>
</html>