@@ -14,29 +14,12 @@ const referenceImagesNames = [];
14
14
15
15
let filterStrings = [ ] ;
16
16
17
- async function getFile ( ) {
18
- // open file picker
19
- [ fileHandle ] = await window . showOpenFilePicker ( ) ;
20
-
21
- if ( fileHandle . kind === 'file' ) {
22
- // run file code
23
- } else if ( fileHandle . kind === 'directory' ) {
24
- // run directory code
25
- }
26
- }
17
+ let currentIMGElement ;
18
+ let referenceIMGElement ;
27
19
28
- const pickerOpts = {
29
- types : [
30
- {
31
- description : 'Images' ,
32
- accept : {
33
- 'image/*' : [ '.png' , '.gif' , '.jpeg' , '.jpg' ] ,
34
- } ,
35
- } ,
36
- ] ,
37
- excludeAcceptAllOption : true ,
38
- multiple : false ,
39
- } ;
20
+ const SIDE_BY_SIDE = 0 ;
21
+ const OVERLAY = 1 ;
22
+ let viewMode = SIDE_BY_SIDE ;
40
23
41
24
async function openTheFolder ( ) {
42
25
// Ask the user to choose a folder.
@@ -70,6 +53,24 @@ function addListeners() {
70
53
}
71
54
}
72
55
} ) ;
56
+
57
+ document . addEventListener ( 'keydown' , ( e ) => {
58
+ e = e || window . event ;
59
+ switch ( e . key ) {
60
+ case 'Enter' :
61
+ openTheFolder ( ) ;
62
+ break ;
63
+ case 'ArrowLeft' :
64
+ case 'ArrowRight' :
65
+ flipBetweenImages ( ) ;
66
+ break ;
67
+ case ' ' : // SPACE BAR
68
+ toggleViewMode ( ) ;
69
+ break ;
70
+ default :
71
+ break ;
72
+ }
73
+ } ) ;
73
74
}
74
75
75
76
async function listDirectoryContents ( dirHandle ) {
@@ -186,10 +187,57 @@ async function showImages(selectedImageFileName) {
186
187
}
187
188
188
189
// Add the two new images.
189
- const imgC = document . createElement ( 'img' ) ;
190
- imgC . src = cURL ;
191
- imagesContainer . appendChild ( imgC ) ;
192
- const imgR = document . createElement ( 'img' ) ;
193
- imgR . src = rURL ;
194
- imagesContainer . appendChild ( imgR ) ;
190
+ currentIMGElement = document . createElement ( 'img' ) ;
191
+ currentIMGElement . id = 'currentImage' ;
192
+ currentIMGElement . src = cURL ;
193
+ currentIMGElement . style . zIndex = 1 ;
194
+ imagesContainer . appendChild ( currentIMGElement ) ;
195
+
196
+ referenceIMGElement = document . createElement ( 'img' ) ;
197
+ referenceIMGElement . id = 'referenceImage' ;
198
+ referenceIMGElement . src = rURL ;
199
+ referenceIMGElement . style . zIndex = - 1 ;
200
+ imagesContainer . appendChild ( referenceIMGElement ) ;
201
+
202
+ updateImagesForViewMode ( ) ;
203
+ updateLabelsForViewMode ( ) ;
204
+ }
205
+
206
+ function flipBetweenImages ( ) {
207
+ currentIMGElement . style . zIndex = - 1 * currentIMGElement . style . zIndex ;
208
+ referenceIMGElement . style . zIndex = - 1 * referenceIMGElement . style . zIndex ;
209
+ updateLabelsForViewMode ( ) ;
210
+ }
211
+
212
+ function toggleViewMode ( ) {
213
+ viewMode = 1 - viewMode ;
214
+ updateImagesForViewMode ( ) ;
215
+ updateLabelsForViewMode ( ) ;
216
+ }
217
+
218
+ function updateImagesForViewMode ( ) {
219
+ if ( viewMode === SIDE_BY_SIDE ) {
220
+ currentIMGElement . style . position = 'static' ;
221
+ referenceIMGElement . style . position = 'static' ;
222
+ } else {
223
+ currentIMGElement . style . position = 'absolute' ;
224
+ referenceIMGElement . style . position = 'absolute' ;
225
+ }
226
+ }
227
+
228
+ function updateLabelsForViewMode ( ) {
229
+ if ( viewMode === SIDE_BY_SIDE ) {
230
+ document . getElementById ( 'labelCurrent' ) . style . opacity = 1 ;
231
+ document . getElementById ( 'labelReference' ) . style . opacity = 1 ;
232
+ } else {
233
+ if ( currentIMGElement . style . zIndex > referenceIMGElement . style . zIndex ) {
234
+ console . log ( 'CURRENT!!!' ) ;
235
+ document . getElementById ( 'labelCurrent' ) . style . opacity = 1 ;
236
+ document . getElementById ( 'labelReference' ) . style . opacity = 0.4 ;
237
+ } else {
238
+ console . log ( 'REFERENCE' ) ;
239
+ document . getElementById ( 'labelCurrent' ) . style . opacity = 0.4 ;
240
+ document . getElementById ( 'labelReference' ) . style . opacity = 1 ;
241
+ }
242
+ }
195
243
}
0 commit comments