Skip to content

Commit 545ea88

Browse files
committed
Addressing comments
1 parent f06a976 commit 545ea88

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

static/js/main.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ window.shark = window.shark || {};
44

55
window.shark.info = window.shark.info || {};
66
window.shark.screenshots = window.shark.screenshots || {};
7-
8-
var screenshot_counter = 0;
7+
window.shark.screenshot_counter = 0;
98

109
function goToLoadingScreen() {
1110
document.querySelector('.file-upload-screen').style.display = 'none';
@@ -244,12 +243,12 @@ function addScreenshot(screenshot) {
244243
</div>
245244
<div>
246245
<span>
247-
<button onclick='flipScreenshot("${screenshot.id}", axis="x")'>Vertical Flip</button>
248-
<button onclick='flipScreenshot("${screenshot.id}", axis="y")'>Horizontal Flip</button>
246+
<button onclick='flipScreenshot("${screenshot.id}", "x")'>Vertical Flip</button>
247+
<button onclick='flipScreenshot("${screenshot.id}", "y")'>Horizontal Flip</button>
249248
</span>
250249
</div>
251250
<div>
252-
<button onclick='delete_screenshot("${screenshot.id}")'>Delete</button>
251+
<button onclick='deleteScreenshot("${screenshot.id}")'>Delete</button>
253252
</div>
254253
</div>
255254
</div>
@@ -259,7 +258,7 @@ function addScreenshot(screenshot) {
259258
}
260259

261260
// Flip a screenshot by adding it the the canvas flipped horizontally or vertically.
262-
function flipScreenshot(screenshot_id, axis='y') {
261+
function flipScreenshot(screenshot_id, axis) {
263262
// Find correct image, add to canvas to flip.
264263
let img = document.querySelector(`.screenshot[data-id="${screenshot_id}"] img`);
265264

@@ -268,31 +267,25 @@ function flipScreenshot(screenshot_id, axis='y') {
268267
canvas.height = img.naturalHeight;
269268

270269
let context = canvas.getContext('2d');
271-
272-
// Horizontal flip.
270+
271+
let direction = ''
273272
if (axis === 'y') {
273+
direction = 'flipped_horizontally';
274274
context.scale(-1, 1);
275275
context.drawImage(img, -img.naturalWidth, 0);
276-
277-
// Draw the canvas to the image area.
278-
img.src = canvas.toDataURL('image/jpeg');
279-
280-
// Update image metadata.
281-
window.shark.screenshots[screenshot_id]['flipped_horizontally'] = !Boolean(window.shark.screenshots[screenshot_id]['flipped_horizontally']);
282-
}
283-
284-
// Vertical flip.
285-
if (axis === 'x') {
276+
} else if (axis === 'x') {
277+
direction = 'flipped_vertically';
286278
context.scale(1, -1);
287279
context.drawImage(img, 0, -img.naturalHeight);
280+
} else {
281+
throw("Invalid flip axis.")
282+
}
288283

289-
// Draw the canvas to the image area.
290-
img.src = canvas.toDataURL('image/jpeg');
284+
// Draw the canvas to the image area.
285+
img.src = canvas.toDataURL('image/jpeg');
291286

292-
// Update image metadata.
293-
window.shark.screenshots[screenshot_id]['flipped_vertically'] = !Boolean(window.shark.screenshots[screenshot_id]['flipped_vertically']);
294-
}
295-
287+
// Update image metadata.
288+
window.shark.screenshots[screenshot_id][direction] = !Boolean(window.shark.screenshots[screenshot_id][direction]);
296289
window.shark.screenshots[screenshot_id]['dataURL'] = canvas.toDataURL('image/jpeg');
297290
}
298291

@@ -364,8 +357,8 @@ function takeVideoScreenshot(query, xPercent, yPercent, widthPercent, heightPerc
364357
let id = randomHex();
365358

366359
// Get screenshot counter value and update counter.
367-
let index_string = String(screenshot_counter).padStart(3, '0');
368-
screenshot_counter += 1;
360+
let index_string = String(window.shark.screenshot_counter).padStart(3, '0');
361+
window.shark.screenshot_counter ++;
369362

370363
let name = window.shark.info['video'].name + "_" + index_string;
371364

@@ -404,12 +397,11 @@ function takeScreenshot(source, x, y, width, height, format = 'image/jpeg') {
404397
return canvas.toDataURL(format);
405398
}
406399

407-
// Delete a screenshot, it is no longer displayed or saved.
408-
function delete_screenshot(screenshot_id) {
400+
function deleteScreenshot(screenshot_id) {
409401
// Find screenshot area to remove.
410402
let screenshot_area = document.querySelector(`.screenshot[data-id="${screenshot_id}"]`);
411403
screenshot_area.remove();
412-
// Update screenshots metadata to remove flipped image.
404+
413405
delete window.shark.screenshots[screenshot_id];
414406
}
415407

0 commit comments

Comments
 (0)