-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
484 lines (472 loc) · 21.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<html>
<head>
<style>
body {
background-color: #ddd;
width: 99%;
border:0px;
}
nav.upper {
width: 100%;
position: sticky;
top: 0;
background-color: rgba(204, 204, 204, 0.75);
z-index: 10;
padding-top: 10px;
padding-bottom: 10px;
}
nav.lower {
width: 100%;
position: sticky;
bottom: 5%;
background-color: rgba(204, 204, 204, 0.75);
z-index: 10;
padding-top: 10px;
padding-bottom: 10px;
text-align: left;
}
#image-container {
width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
}
div.centerImg {
height: 200px;
width: 200px;
vertical-align: middle;
align-items: center;
display: flex;
}
img {
width: 100%;
max-width: 200px;
max-height: 200px;
}
nav {
width: 100%;
}
.search-box {
width: 40%;
}
.search-button {
width: 10%;
text-align: center;
padding-top: 5px;
color:#d39393;
font-family: 'Courier New', Courier, monospace;
font-weight: bold;
text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.75);
}
/* Default style */
.search-meta, .search-categories,.search-filename,.ai,.ps,.copy {
width: 4%;
background-color: #f8f9fa;
color: #333;
border: 1px solid #ced4da;
padding: 5px 10px;
cursor: pointer;
border-radius: 4px;
}
/* AHK side Function Buttons */
.ai {
background-color: #330000;
border: 3px solid #ff9a00;
color:#ff9a00;
font-weight: bold;
}
.ps {
background-color: #001e36;
border: 3px solid #31a8ff;
color:#31a8ff;
font-weight: bold;
}
.copy {
background-color: #333;
border: 3px solid #55FF55;
color:#55FF55;
}
/* Style when toggled */
.search-meta[data-toggled="true"], .search-categories[data-toggled="true"], .search-filename[data-toggled="true"] {
background-color: #217521;
color: #fff;
border-color: #55FF55;
box-shadow: inset 5px 5px 5px rgba(0, 0, 0, 0.33);
}
.search-categories[data-toggled="false"] {
background-color: #b2ccf3 !important;
}
#button-container button[data-toggled="true"],.search-categories[data-toggled="true"] {
background-color: #b2ccf3 !important;
border: 1px solid #0080ff !important;
color:black !important;
}
#button-container button[data-toggled="true"]
{
box-shadow: inset 5px 5px 5px rgba(0, 0, 0, 0.33);
}
.ai[data-toggled="true"] {
box-shadow: inset 5px 5px 3px rgba(0, 0, 0, 0.5);
border: 3px dashed #ff9a00;
}
.ps[data-toggled="true"] {
box-shadow: inset 5px 5px 3px rgba(0, 0, 0, 0.5);
border: 3px dashed #31a8ff;
}
.copy[data-toggled="true"] {
box-shadow: inset 5px 5px 3px rgba(0, 0, 0, 0.5);
border: 3px dashed #686b6e;
}
button[data-toggled="true"].copy {
box-shadow: inset 5px 5px 5px rgba(0, 0, 0, 0.33);
background-color: #333;
border: 2px solid #55FF55;
color:#55FF55;
}
button:not(nav.lower button) {
border-radius: 4px;
}
button#next-button {
left:41%;
}
#button-container {
width: 100%;
display: flex;
justify-content: space-between;
}
#button-container button {
flex: 1;
margin: 0 1px;
background-color: #b2ccf3;
border: 1px solid #0080ff;
}
</style>
<script src="C:\\tmp\\logos\\imageSourcesCategoriesMeta.js"></script>
<script>
var imagesPerPage = 36; // Change this to display more or fewer images per page
var currentPage = 1;
var container;
var filteredImagesBy_categories;
var searchBox;
function hideImages() {
container.innerHTML = '';
}
function paginateImages(currentPage, imagesPerPage) {
// Calculate the start and end indices for the images to display
var start = (currentPage - 1) * imagesPerPage;
var end = start + imagesPerPage;
return imageSourcesCategoriesMeta.data.slice(start, end);
}
function triggerInputEvent() {
searchBox.dispatchEvent(new Event('input'));
}
document.addEventListener("DOMContentLoaded", function() {
searchBox = document.querySelector('.search-box');
container = document.getElementById('image-container');
processImages(paginateImages(currentPage, imagesPerPage)); // Display the first page of images
document.querySelector('#page-count').innerText = currentPage + ' of ' + Math.ceil(imageSourcesCategoriesMeta.data.length / imagesPerPage);
var categories = ["flex", "Gas-Convenience", "auto", "grocery", "QSR", "cell", "roads", "hardware", "medical", "uncommon", "mall", "gym", "furniture", "bank", "home", "service", "hotel-motel", "brokerage", "RX", "clothing", "DollarStores", "big-box", "banks", "retail", "landmark"];
var buttoncontainer = document.getElementById('button-container');
categories.forEach(function(category) {
var button = document.createElement('button');
button.id = category + '-button';
button.textContent = category;
buttoncontainer.appendChild(button);
button.setAttribute('data-toggled', 'false');
button.addEventListener('click', function(event) {
var category = event.target.textContent;
// Filter the images by category
filteredImagesBy_categories = imageSourcesCategoriesMeta.data.filter(function(image) {
return image.metadata && image.metadata.categories && image.metadata.categories.toLowerCase().includes(category.toLowerCase());
});
hideImages(); // Clear the image container
processImages(filteredImagesBy_categories);
// Get all buttons
var buttons = document.querySelectorAll('button');
// Set all buttons' data-toggled attribute to false
buttons.forEach(function(otherButton) {
otherButton.setAttribute('data-toggled', 'false');
});
// Set the clicked button's data-toggled attribute to true
this.setAttribute('data-toggled', 'true');
});
});
function showNotification(message) {
var notification = document.getElementById('notification');
notification.innerText = message;
notification.style.display = 'block';
setTimeout(function() {
notification.style.display = 'none';
}, 1500); // Hide the notification after 1.5 seconds
}
// Event listener for first button
document.getElementById('first-button').addEventListener('click', function() {
if (currentPage!=1) {
hideImages();
currentPage=1;
processImages(paginateImages(currentPage, imagesPerPage));
}
else {
showNotification("You are already on the first page");
}
});
// Event listener for prev button
document.getElementById('prev-button').addEventListener('click', function() {
if (currentPage > 1) {
hideImages();
currentPage--;
processImages(paginateImages(currentPage, imagesPerPage));
}
else {
showNotification("You are already on the first page");
}
});
// Event listener for next button
document.getElementById('next-button').addEventListener('click', function() {
if (currentPage <= Math.ceil(imageSourcesCategoriesMeta.data.length / imagesPerPage) - 1) {
hideImages();
currentPage++;
processImages(paginateImages(currentPage, imagesPerPage));
}
else {
showNotification("You are already on the last page.");
}
});
// Event listener for last button
document.getElementById('last-button').addEventListener('click', function() {
if (currentPage!=Math.ceil(imageSourcesCategoriesMeta.data.length / imagesPerPage)) {
hideImages();
currentPage=Math.ceil(imageSourcesCategoriesMeta.data.length / imagesPerPage);
processImages(paginateImages(currentPage, imagesPerPage));
}
else {
showNotification("You are already on the last page.");
}
});
searchBox.focus();
searchBox.addEventListener('focus', function(event) {
if (this.value == 'Search...') {
this.value = '';
}
});
function processImages(images) {
images.forEach(function(image) {
var div = document.createElement('div');
div.className = 'centerImg';
var img = document.createElement('img');
img.src = image.src;
img.alt = image.metadata.search;
img.title = image.metadata.search;
// Add data-affiliatedFile attribute if affiliated_file exists
if (image.metadata.affiliated_file) {
var filePath = image.metadata.affiliated_file;
// Replace backslashes with slashes and encode the file path
var encodedFilePath = 'file:///' + encodeURI(filePath.replace(/\\/g, '/'));
img.setAttribute('data-affiliatedFile', encodedFilePath);
}
var categories = image.metadata.categories;
//split on space to get array of categories if any
var categoriesArray = (categories || '').split(' ');
// join them back with commas
var categories = categoriesArray.map(function(word) {
return word;
}).join(',');
// Add the modified categories string as a class if defined
(categories) ? img.classList.add(categories) : "";
div.appendChild(img);
let debounceTimer;
let isFirstClick = true;
div.addEventListener('click', function(event) {
if (isFirstClick) {
// processEvent(event);
console.log("processEvent started [Date.now()]:\n");
isFirstClick = false;
debounceTimer = setTimeout(() => {
isFirstClick = true;
}, 800);
}
});
container.appendChild(div);
});
}
function processEvent(event) {
// console.log("processEvent started [Date.now()]:\n");
// console.log(Date.now());
obj = window.chrome.webview.hostObjects.ahk;
// Get the src of the img contained within the div
var target = event.target;
var src = target.getAttribute('data-affiliatedFile') || target.src;
if (!src && target.firstChild) {
src = target.firstChild.getAttribute('data-affiliatedFile') || target.firstChild.src;
}
searchBox.value = '';
// triggerInputEvent(); //this will end up showing all images again
hideImages();
processImages(paginateImages(currentPage, imagesPerPage));
// If the PS button is toggled, call the AHK function to place the image in Photoshop, likewise in Ai and Copy
if (document.querySelector('.ps').getAttribute('data-toggled') === 'true') {
obj.func(src,"Photoshop");
}
else if (document.querySelector('.ai').getAttribute('data-toggled') === 'true') {
obj.func(src,"Illustrator");
}
else if (document.querySelector('.copy').getAttribute('data-toggled') === 'true') {
obj.func(src,"Copy");
}
else {
console.log("No function selected");
}
// console.log("processEvent ended [Date.now()]:\n");
// console.log(Date.now());
//whole function had like a 4ms delta so this aint the problem
}
searchBox.addEventListener('input', function(event) {
//default to src
var filteredImagesBy_src = imageSourcesCategoriesMeta.data.filter(function(image) {
return image.src && image.src.toLowerCase().includes(searchBox.value.toLowerCase());
});
//if checkbox is checked, search metadata
var filteredImagesBy_search = imageSourcesCategoriesMeta.data.filter(function(image) {
return image.metadata && image.metadata.search && image.metadata.search.toLowerCase().includes(searchBox.value.toLowerCase());
});
//if checkbox is checked, search categories
filteredImagesBy_categories = imageSourcesCategoriesMeta.data.filter(function(image) {
return image.metadata && image.metadata.categories && image.metadata.categories.toLowerCase().includes(searchBox.value.toLowerCase());
});
// Clear the image container defined above
container.innerHTML = '';
// Display the filtered images depending on state of pressed input buttons, search-meta, search-categories, search-filename
var imagesToProcess;
if (document.querySelector(".search-meta").getAttribute('data-toggled') === 'true') {
imagesToProcess = filteredImagesBy_search;
} else if (document.querySelector(".search-categories").getAttribute('data-toggled') === 'true') {
imagesToProcess = filteredImagesBy_categories;
} else {
imagesToProcess = filteredImagesBy_src; // default to src search-filename
}
processImages(imagesToProcess);
});
function toggleButton(buttonClass, otherButtonClasses,noUpdate=false) {
var button = document.querySelector(buttonClass);
button.setAttribute('data-toggled', 'true');
otherButtonClasses.forEach(function(otherButtonClass) {
var otherButton = document.querySelector(otherButtonClass);
otherButton.setAttribute('data-toggled', 'false');
});
//we can check if the search box is empty and if so, don't triggerInputEvent() to keep pagination
(noUpdate || searchBox.value == '') ? "" : triggerInputEvent(); //forces search type switch to update
}
// Event listener for AHK function buttons
document.querySelector('.ps').addEventListener('click', function() {
toggleButton('.ps', ['.ai', '.copy'],true);
});
document.querySelector('.ai').addEventListener('click', function() {
toggleButton('.ai', ['.ps', '.copy'],true);
});
document.querySelector('.copy').addEventListener('click', function() {
toggleButton('.copy', ['.ps', '.ai'],true);
});
// Event listener for search modes
document.querySelector('.search-meta').addEventListener('click', function() {
toggleButton('.search-meta', ['.search-categories', '.search-filename']);
});
document.querySelector('.search-categories').addEventListener('click', function() {
toggleButton('.search-categories', ['.search-meta', '.search-filename']);
});
document.querySelector('.search-filename').addEventListener('click', function() {
toggleButton('.search-filename', ['.search-meta', '.search-categories']);
});
document.addEventListener('keydown', function(event) {
var searchBox = document.querySelector('.search-box');
// if (document.activeElement !== searchBox) {
// // Ignore special keys
// if (event.key.length === 1 || event.key === 'Backspace') {
// searchBox.focus();
// searchBox.value += event.key;
// event.preventDefault();
// triggerInputEvent();
// }
// }
//event.key === 'Delete'
if (document.activeElement !== searchBox) {
if (event.key === 'ArrowLeft') {
document.getElementById('prev-button').click();
event.preventDefault();
}
if (event.key === 'ArrowRight') {
document.getElementById('next-button').click();
event.preventDefault();
}
}
// If Escape key is pressed, clear the searchBox
if (event.key === 'Escape') {
searchBox.value = '';
triggerInputEvent();
//set pagination back up, dont issue a click, use functions
hideImages();
currentPage=1;
processImages(paginateImages(currentPage, imagesPerPage));
document.querySelectorAll('nav.lower button').forEach(function(button) {
button.setAttribute('data-toggled', 'false');
});
}
// If Alt + F is pressed
if (event.altKey && event.key === 'f') {
document.querySelector('.search-filename').click();
}
// If Alt + T is pressed
if (event.altKey && event.key === 't') {
document.querySelector('.search-meta').click();
}
// If Alt + C is pressed
if (event.altKey && event.key === 'c') {
document.querySelector('.search-categories').click();
}
// If Alt + P is pressed
if (event.altKey && event.key === 'p') {
document.querySelector('.ps').click();
}
// If Alt + A is pressed
if (event.altKey && event.key === 'a') {
document.querySelector('.ai').click();
}
// If Alt + O is pressed
if (event.altKey && event.key === 'o') {
document.querySelector('.copy').click();
}
// If Enter is pressed, check if there is only one result, then dispatch a click action
});
});
</script>
</head>
<body>
<nav class="upper">
<span>Search:</span>
<input type="input" value="" class="search-box" />
<span class="search-button">just start typing!</span>
<span style="margin-left: 5%;"><em>Search by only one of the following: </em></span>
<input type="button" value="File" class="search-filename" title="Click here to search by file name matching only" data-toggled="true"/>
<input type="button" value="Terms" class="search-meta" title="Click here to search only by hidden search terms - hover over an image to see its search terms" data-toggled="false"/>
<input type="button" value="Cat." class="search-categories" title="Click here to search only by categories, among those you see at the bottom in blue" data-toggled="false"/>
<!-- begin AHK side function buttons -->
<input type="button" value="Ps" class="PS" title="Select to place in Adobe Photoshop" data-toggled="true"/>
<input type="button" value="Ai" class="AI" title="Select to place in Adobe Illustrator" data-toggled="false"/>
<input type="button" value="PathOnly" class="Copy" title="Select to copy image path to clipboard" data-toggled="false"/>
</nav>
<div id="image-container"></div>
<nav class="lower">
<button id="first-button">First</button>
<button id="prev-button">Previous</button>
<button id="next-button">Next</button>
<button id="last-button">Last</button>
<span id="page-count">1</span>
<span style="margin-left:5%;font-style: italic;">Categories below - themantic:</span>
<div id="button-container"></div>
<span style="font-weight: bold;">Just hit esc to start over</span>
</nav>
<div id="notification" style="display: none; position: fixed; bottom: 20px; right: 20px; padding: 10px; background-color: #f44336; color: white;">
This is a notification.
</div>
</body>
</html>