-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
151 lines (135 loc) · 5.51 KB
/
bundle.js
File metadata and controls
151 lines (135 loc) · 5.51 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
window.addEventListener('load', startup, false)
let titleSubmit = document.querySelector('.title-submit')
let printButton = document.querySelector('.print-button')
let filters = Array.from(document.querySelectorAll('.filter-button'))
let newFilter
let newTitleValue
let startButton = document.querySelector('#startbutton')
let saveButton = document.querySelector('.save-button')
let restartButton = document.querySelector('.restart-button')
let camera = document.querySelector('.camera')
function startup() {
localStorage.clear()
if(!!window.performance && window.performance.navigation.type == 2) {
window.location.reload();
}
let width = 420
let height = 400
let streaming = false
let video = document.getElementById('video')
startButton = document.getElementById('startbutton');
navigator.getMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia)
navigator.getMedia(
{
video: true,
audio: false,
},
function(stream) {
if (navigator.mozGetUserMedia) {
video.mozSrcObject = stream
} else {
let vendorURL = window.URL || window.webkitURL
video.src = vendorURL.createObjectURL(stream)
}
video.play()
},
function(err) {
console.log("An error occured! " + err)
}
)
video.addEventListener('canplay', function(ev){
if (!streaming) {
height = video.videoHeight / (video.videoWidth/width)
if (isNaN(height)) {
height = width / (4/3)
}
video.setAttribute('width', width)
video.setAttribute('height', height)
streaming = true
}
}, false)
const changeFilter = (event) => {
console.log('in change filter')
let photos = Array.from(document.querySelectorAll('.photos'))
newFilter = event.target.dataset.filter
photos.forEach(function(photo) {
photo.classList.remove("sepia")
photo.classList.remove("grayscale")
photo.classList.remove("none")
photo.classList.add(newFilter)
})
}
filters.forEach(element => element.addEventListener('click', changeFilter))
titleSubmit.addEventListener('submit', function(event) {
let paragraph = document.querySelector('.photo-title')
let titleValue = document.querySelector('.title-value')
event.preventDefault()
newTitleValue = titleValue.value
paragraph.innerText = titleValue.value
})
let reload = false
startButton.addEventListener('click', function(ev){
if(reload === true){
index = 0
window.setTimeout(function() { takePicture(currentPhoto) }, 1000)
ev.preventDefault();
currentPhoto.canvas.classList.add('d-none')
index++
}else{
window.setTimeout(function() { takePicture(currentPhoto) }, 1000)
ev.preventDefault();
currentPhoto.canvas.classList.add('d-none')
index++
reload = true
}
}, true);
printButton.addEventListener('click', function(event) {
window.localStorage.setItem('filter', newFilter)
window.localStorage.setItem('newTitleValue', newTitleValue)
})
saveButton.addEventListener('click', function(event) {
window.localStorage.setItem('filter', newFilter)
window.localStorage.setItem('newTitleValue', newTitleValue)
})
restartButton.addEventListener('click', function(){
location.reload()
})
}
let photoData = [{ canvas : document.querySelector("#canvas1"), photo : document.querySelector("#photo1") },
{ canvas : document.querySelector("#canvas2"), photo : document.querySelector("#photo2") },
{ canvas : document.querySelector("#canvas3"), photo : document.querySelector("#photo3") },
{ canvas : document.querySelector("#canvas4"), photo : document.querySelector("#photo4") }]
let index = 0
let currentPhoto = photoData[index]
function takePicture(currentPhoto) {
if( index <= 4){
flashToggle()
videoToggle()
currentPhoto.photo.classList.remove("d-none")
let context = currentPhoto.canvas.getContext('2d')
context.drawImage(video,50,50,700,650,0,0,400,220)
let data = currentPhoto.canvas.toDataURL(`image${index}/png`)
currentPhoto.photo.setAttribute('src', data)
localStorage.setItem(`image${index}`, data.replace(/^data:image\/(png|jpg);base64,/, ""))
currentPhoto = photoData[index]
currentPhoto.canvas.classList.add('d-none')
index++
window.setTimeout(function () { takePicture(currentPhoto) }, 1000)
}
console.log('end of function');
}
function handleChange(input){
if (newTitleValue === null) {alert("Value should be between 0 - 100")
}
}
function flashToggle() {
camera.classList.toggle('flash');
}
function videoToggle(){
video.classList.toggle('flash')
}
},{}]},{},[1]);