-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
105 lines (95 loc) · 3.31 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<html>
<head>
<title>Auto Grid examples</title>
<script type="module">
import AutoGrid from './index.js'
window.addEventListener('load', function () {
// Image
const getImage = function () {
const image = document.createElement('img');
image.src = './hamster.JPG';
return image;
}
// Video
/**
* @param {MediaStream} stream
*/
const streamToVideo = function (stream) {
const video = document.createElement('video');
video.autoplay = true;
video.srcObject = stream;
return video;
}
const getVideo = function () {
if (window.stream) {
return Promise.resolve(streamToVideo(stream));
} else {
return navigator.mediaDevices.getUserMedia({ video: true })
.then(function (stream) {
window.stream = stream;
return streamToVideo(stream);
});
}
}
window.autoGrid = new AutoGrid({
wrapper: document.querySelector('#wrapper')
});
/**
* @param {'color'|'image'|'webcam'} type
**/
function _add(type) {
if (type === 'color') {
autoGrid.addMock();
} else if (type === 'image') {
autoGrid.add(getImage());
} else if (type === 'webcam') {
getVideo()
.then(function (video) {
autoGrid.add(video);
});
}
}
window.add = function () {
const el = document.getElementById('type');
const type = el.options[el.selectedIndex].value;
_add(type)
}
window.remove = autoGrid.remove;
window.update = function () {
autoGrid.update([
getImage(),
getImage(),
getImage()
], { type: 'exact' })
}
});
</script>
</head>
<body>
<div>
<h1>Auto Grid examples</h1>
<div>
Automatically create grids with fixed sized parent element.<br>
Sizing is performed using CSS3 grid + other css.
</div>
<form style="margin-top:5px;">
<div>
<select id="type">
<option value="color">Color</option>
<option value="image">Image</option>
<option value="webcam">Webcam</option>
</select>
<input type="button" value="Add" onclick="add()">
|
<input type="button" value="Remove" onclick="remove()">
</div>
<div style="margin-top:5px;">
<input type="button" value="Update" onclick="update()"> Updates to 3 images.
</div>
</form>
<div id="wrapper" style="width:300px;height:300px;border:1px solid #BBB;">
<!-- CELLS ADDED HERE -->
</div>
</div>
</body>
</html>