Rename "canvas" to "img"

"canvas" isn't a good variable name for an <img> element
This commit is contained in:
Samuel Sloniker 2021-07-16 16:47:31 -07:00
parent 19fdad9153
commit d2d3a7c13c
2 changed files with 12 additions and 12 deletions

View File

@ -18,7 +18,7 @@
</div> </div>
<div id=holder style="display:none"> <div id=holder style="display:none">
<div id=errorbox style="width: 800px; height: 480px">Loading...</div> <div id=errorbox style="width: 800px; height: 480px">Loading...</div>
<img id=canvas width=800 height=480 style="width: 800px; height: 480px; display: none"></canvas> <img id=img width=800 height=480 style="width: 800px; height: 480px; display: none"></canvas>
</div> </div>
<script src=js/main.js></script> <script src=js/main.js></script>
</body> </body>

View File

@ -11,8 +11,8 @@ function resize() {
displayWidth = Math.round(maxWidth) displayWidth = Math.round(maxWidth)
displayHeight = Math.round(maxWidth * 0.6) displayHeight = Math.round(maxWidth * 0.6)
} }
canvas.style.width = displayWidth + 'px' img.style.width = displayWidth + 'px'
canvas.style.height = displayHeight + 'px' img.style.height = displayHeight + 'px'
errorbox.style.width = displayWidth + 'px' errorbox.style.width = displayWidth + 'px'
errorbox.style.height = displayHeight + 'px' errorbox.style.height = displayHeight + 'px'
} }
@ -22,22 +22,22 @@ function setup() {
ws = new WebSocket(localStorage.getItem('url')) ws = new WebSocket(localStorage.getItem('url'))
ws.onmessage = function(e) { ws.onmessage = function(e) {
window.m = e window.m = e
let type, pos, x, y, data, img, code, msg let type, data, code, msg
type = e.data.split('%')[0] type = e.data.split('%')[0]
if (type == 'ver') { if (type == 'ver') {
ws.send('pass ' + localStorage.getItem('password')) ws.send('pass ' + localStorage.getItem('password'))
setInterval(function(){ws.send('ack')}, 3000) setInterval(function(){ws.send('ack')}, 3000)
} else if ( type == 'pic' ) { } else if ( type == 'pic' ) {
data = e.data.split('%')[2] data = e.data.split('%')[2]
canvas.src = data img.src = data
errorbox.style.display = 'none' errorbox.style.display = 'none'
canvas.style.display = 'block' img.style.display = 'block'
} else if ( type == 'err' ) { } else if ( type == 'err' ) {
code = e.data.split('%')[1] code = e.data.split('%')[1]
msg = e.data.split('%')[2] msg = e.data.split('%')[2]
errorbox.textContent = msg errorbox.textContent = msg
errorbox.style.display = 'block' errorbox.style.display = 'block'
canvas.style.display = 'none' img.style.display = 'none'
console.error('Server reported error: ' + code + ': ' + msg) console.error('Server reported error: ' + code + ': ' + msg)
if (code[0] == '*') { if (code[0] == '*') {
errorbox.innerHTML = msg + '<br>Please refresh page' errorbox.innerHTML = msg + '<br>Please refresh page'
@ -51,12 +51,12 @@ function setup() {
ws.onerror = function(e){ ws.onerror = function(e){
errorbox.innerHTML = 'Connection lost<br>Please refresh page' errorbox.innerHTML = 'Connection lost<br>Please refresh page'
errorbox.style.display = 'block' errorbox.style.display = 'block'
canvas.style.display = 'none' img.style.display = 'none'
} }
ws.onclose = function(e){ ws.onclose = function(e){
errorbox.innerHTML = 'Connection lost<br>Please refresh page' errorbox.innerHTML = 'Connection lost<br>Please refresh page'
errorbox.style.display = 'block' errorbox.style.display = 'block'
canvas.style.display = 'none' img.style.display = 'none'
} }
ws.onopen = function(e) { ws.onopen = function(e) {
ws.send('maxver 1') ws.send('maxver 1')
@ -93,7 +93,7 @@ function connect(e) {
} }
let canvas = document.querySelector('#canvas') let img = document.querySelector('#img')
let errorbox = document.querySelector('#errorbox') let errorbox = document.querySelector('#errorbox')
let login = document.querySelector('#login') let login = document.querySelector('#login')
@ -114,7 +114,7 @@ let ws
resize() resize()
window.onresize = resize window.onresize = resize
canvas.onmousedown = touch img.onmousedown = touch
canvas.onmouseup = release img.onmouseup = release
start.onclick = connect start.onclick = connect