Skip to content

Commit

Permalink
- Load form data and clear log on resume
Browse files Browse the repository at this point in the history
- Use global imageUrl variable
- Fix grammatical error "it's" -> "its"
  • Loading branch information
JaumeRibas committed Sep 21, 2024
1 parent a58814f commit b99ec3b
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions image-sequence-viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
let mouseDown = false;
let clickX;
let clickY;
let imageUrl;
let previousImageUrl;
let frameLoadStartTime;
const imgElement = document.getElementById("img");
Expand Down Expand Up @@ -152,20 +153,21 @@
}

function playPause() {
currentIndex = parseInt(currentIndexInput.value);
if (!playbackStopped) {
playbackStopped = true;
} else {
clearLog();
playbackStopped = false;
loadFormData();
changeFrame();
}
}

function changeFrame() {
frameLoadStartTime = Date.now();
currentIndex += indexLeap;
const imageUrl = getImageUrl();
previousImageUrl = imgElement.getAttribute("src");
previousImageUrl = imageUrl;
imageUrl = getImageUrl();
console.log(imageUrl);
imgElement.setAttribute("src", imageUrl);
currentIndexInput.value = currentIndex;
Expand Down Expand Up @@ -193,17 +195,18 @@

imgElement.onerror = function() {
if (!playbackStopped) {
log("error loading image at " + imgElement.getAttribute("src"));
log("error loading image at " + imageUrl);
playbackStopped = true;
imgElement.setAttribute("src", previousImageUrl);
imageUrl = previousImageUrl;
imgElement.setAttribute("src", imageUrl);
}
}

firstImageInput.onchange = function() {
const imageName = this.files[0].name;
const match = /\d+(?!.*\d)/g.exec(imageName);
if (match === null) {
alert("File doesn't have a numeric index in it's name.")
alert("The selected image file doesn't have a numeric index in its name.")
} else {
const firstIndex = match[0];
const prefix = imageName.substring(0, match.index);
Expand All @@ -214,7 +217,9 @@
currentIndexInput.value = firstIndex;
loadFormData();
if (path) {
imgElement.setAttribute("src", getImageUrl());
previousImageUrl = imageUrl;
imageUrl = getImageUrl();
imgElement.setAttribute("src", imageUrl);
}
}
};
Expand All @@ -224,11 +229,13 @@
if (path) {
path = "file:///" + path;
}
previousImageUrl = imageUrl;
if (path && currentIndex !== null) {
imgElement.setAttribute("src", getImageUrl());
imageUrl = getImageUrl();
} else {
imgElement.setAttribute("src", "");
imageUrl = "";
}
imgElement.setAttribute("src", imageUrl);
};

flipUpsideDownInput.onchange = function() {
Expand Down Expand Up @@ -278,12 +285,16 @@
switch (key) {
case 37: //left
currentIndex -= parseInt(indexLeapInput.value);
imgElement.setAttribute("src", getImageUrl());
previousImageUrl = imageUrl;
imageUrl = getImageUrl();
imgElement.setAttribute("src", imageUrl);
currentIndexInput.value = currentIndex;
break;
case 39://right
case 39: //right
currentIndex += parseInt(indexLeapInput.value);
imgElement.setAttribute("src", getImageUrl());
previousImageUrl = imageUrl;
imageUrl = getImageUrl();
imgElement.setAttribute("src", imageUrl);
currentIndexInput.value = currentIndex;
break;
}
Expand All @@ -293,7 +304,8 @@
//init
loadFormData();
if (path && currentIndex !== null) {
imgElement.setAttribute("src", getImageUrl());
imageUrl = getImageUrl();
imgElement.setAttribute("src", imageUrl);
}

</script>
Expand Down

0 comments on commit b99ec3b

Please sign in to comment.