Skip to content

Commit b99ec3b

Browse files
committed
- Load form data and clear log on resume
- Use global imageUrl variable - Fix grammatical error "it's" -> "its"
1 parent a58814f commit b99ec3b

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

image-sequence-viewer.html

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
let mouseDown = false;
100100
let clickX;
101101
let clickY;
102+
let imageUrl;
102103
let previousImageUrl;
103104
let frameLoadStartTime;
104105
const imgElement = document.getElementById("img");
@@ -152,20 +153,21 @@
152153
}
153154

154155
function playPause() {
155-
currentIndex = parseInt(currentIndexInput.value);
156156
if (!playbackStopped) {
157157
playbackStopped = true;
158158
} else {
159+
clearLog();
159160
playbackStopped = false;
161+
loadFormData();
160162
changeFrame();
161163
}
162164
}
163165

164166
function changeFrame() {
165167
frameLoadStartTime = Date.now();
166168
currentIndex += indexLeap;
167-
const imageUrl = getImageUrl();
168-
previousImageUrl = imgElement.getAttribute("src");
169+
previousImageUrl = imageUrl;
170+
imageUrl = getImageUrl();
169171
console.log(imageUrl);
170172
imgElement.setAttribute("src", imageUrl);
171173
currentIndexInput.value = currentIndex;
@@ -193,17 +195,18 @@
193195

194196
imgElement.onerror = function() {
195197
if (!playbackStopped) {
196-
log("error loading image at " + imgElement.getAttribute("src"));
198+
log("error loading image at " + imageUrl);
197199
playbackStopped = true;
198-
imgElement.setAttribute("src", previousImageUrl);
200+
imageUrl = previousImageUrl;
201+
imgElement.setAttribute("src", imageUrl);
199202
}
200203
}
201204

202205
firstImageInput.onchange = function() {
203206
const imageName = this.files[0].name;
204207
const match = /\d+(?!.*\d)/g.exec(imageName);
205208
if (match === null) {
206-
alert("File doesn't have a numeric index in it's name.")
209+
alert("The selected image file doesn't have a numeric index in its name.")
207210
} else {
208211
const firstIndex = match[0];
209212
const prefix = imageName.substring(0, match.index);
@@ -214,7 +217,9 @@
214217
currentIndexInput.value = firstIndex;
215218
loadFormData();
216219
if (path) {
217-
imgElement.setAttribute("src", getImageUrl());
220+
previousImageUrl = imageUrl;
221+
imageUrl = getImageUrl();
222+
imgElement.setAttribute("src", imageUrl);
218223
}
219224
}
220225
};
@@ -224,11 +229,13 @@
224229
if (path) {
225230
path = "file:///" + path;
226231
}
232+
previousImageUrl = imageUrl;
227233
if (path && currentIndex !== null) {
228-
imgElement.setAttribute("src", getImageUrl());
234+
imageUrl = getImageUrl();
229235
} else {
230-
imgElement.setAttribute("src", "");
236+
imageUrl = "";
231237
}
238+
imgElement.setAttribute("src", imageUrl);
232239
};
233240

234241
flipUpsideDownInput.onchange = function() {
@@ -278,12 +285,16 @@
278285
switch (key) {
279286
case 37: //left
280287
currentIndex -= parseInt(indexLeapInput.value);
281-
imgElement.setAttribute("src", getImageUrl());
288+
previousImageUrl = imageUrl;
289+
imageUrl = getImageUrl();
290+
imgElement.setAttribute("src", imageUrl);
282291
currentIndexInput.value = currentIndex;
283292
break;
284-
case 39://right
293+
case 39: //right
285294
currentIndex += parseInt(indexLeapInput.value);
286-
imgElement.setAttribute("src", getImageUrl());
295+
previousImageUrl = imageUrl;
296+
imageUrl = getImageUrl();
297+
imgElement.setAttribute("src", imageUrl);
287298
currentIndexInput.value = currentIndex;
288299
break;
289300
}
@@ -293,7 +304,8 @@
293304
//init
294305
loadFormData();
295306
if (path && currentIndex !== null) {
296-
imgElement.setAttribute("src", getImageUrl());
307+
imageUrl = getImageUrl();
308+
imgElement.setAttribute("src", imageUrl);
297309
}
298310

299311
</script>

0 commit comments

Comments
 (0)