From e75c7a5cb28307509b68c2a0832d704abdd7c565 Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 7 Feb 2014 17:58:57 +0100 Subject: store current snapshot/testbild locally on enter. --- js/cctv-control.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/cctv-control.js b/js/cctv-control.js index c79346d..3d5fa68 100644 --- a/js/cctv-control.js +++ b/js/cctv-control.js @@ -34,10 +34,10 @@ function changeCam() { if (cam <= 7 && cam >= 0) { camDisplay = cam + 1; display.innerHTML = '

' + camDisplay + '

'; - display.innerHTML += ''; + display.innerHTML += ''; } else { - display.innerHTML = ''; + display.innerHTML = ''; } } @@ -51,6 +51,47 @@ function controlCam(direction) { } } +//save current screenshot in local storage +function saveImage() { + + var storageFiles = {}, //local storage object + xhr = new XMLHttpRequest(), + blob, + fileReader = new FileReader(), + snapShot = new Image(), //dummy-object to display snapshot + imgCanvas = document.createElement("canvas"), + imgContext = imgCanvas.getContext("2d"); + + + xhr.open("GET", 'img/testbild-' + camDisplay + '.png', true); + xhr.responseType = "arraybuffer"; + + xhr.addEventListener("load", function () { + if (xhr.status === 200) { + + blob = new Blob([xhr.response], {type: "image/png"}); + + + fileReader.onload = function (evt) { + var result = evt.target.result; + + snapShot.src = result; + + try { + localStorage.setItem("snapShot", result); + } + catch (e) { + console.log("Storage failed: " + e); + } + }; + + fileReader.readAsDataURL(blob); + } + }, false); + + xhr.send(); +} + function keyDown(event) { switch(event.keyCode) { @@ -98,5 +139,8 @@ function keyDown(event) { case 40: // arrow down controlCam("down"); break; - } + case 13: //enter + saveImage(); + break; + } } -- cgit v1.2.1