Skip to content

Commit 8280b84

Browse files
committed
Add compact mode for search results
Keeping this on a separate branch until I have a way to retrieve platform icons without CORS errors
1 parent b1e0dd8 commit 8280b84

5 files changed

Lines changed: 119 additions & 41 deletions

File tree

main.css

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ body {
250250
font-weight: bold;
251251
}
252252
.results-navigate {
253-
margin-left: 24px;
253+
margin-left: 1.2rem;
254254
}
255255
.results-per-page {
256256
font-size: 0.7rem;
@@ -259,18 +259,25 @@ body {
259259
width: 2rem !important;
260260
margin-left: 0.5rem;
261261
}
262+
.results-compact {
263+
position: absolute;
264+
top: 2rem; right: 0;
265+
}
262266
.results-bottom {
263267
text-align: right;
264268
margin-top: 0.5rem;
265269
}
266270

267271
.entry {
268-
height: 6rem;
269272
padding: 0.5rem 0;
270273
border-bottom: 0.15rem solid #0002;
271274
display: flex;
272275
}
273-
.entry-logo {
276+
277+
.entry:not([compact]) {
278+
height: 6rem;
279+
}
280+
.entry:not([compact]) .entry-logo {
274281
height: 100%;
275282
background-position: center;
276283
background-repeat: no-repeat;
@@ -279,33 +286,79 @@ body {
279286
flex: 0 0 8rem;
280287
cursor: pointer;
281288
}
282-
.entry-text {
289+
.entry:not([compact]) .entry-text {
283290
min-width: 0;
284291
display: flex;
285292
flex-direction: column;
286293
flex-grow: 1;
287294
white-space: nowrap;
288295
overflow: hidden;
289296
}
290-
.entry-title {
297+
.entry:not([compact]) .entry-title {
291298
font-family: Tahoma, sans-serif;
292299
font-size: 1.5rem;
293300
}
294-
.entry-developer {
301+
.entry:not([compact]) .entry-developer {
295302
font-size: 0.7rem;
296303
margin-left: 0.1rem;
297304
}
298-
.entry-type,
299-
.entry-tags {
305+
.entry:not([compact]) .entry-type,
306+
.entry:not([compact]) .entry-tags {
300307
font-size: 0.9rem;
301308
}
302-
.entry-tags {
309+
.entry:not([compact]) .entry-tags {
303310
color: #000a;
304311
}
305-
.entry-description {
312+
.entry:not([compact]) .entry-description {
306313
margin-top: 0.5rem;
307314
white-space: normal;
308315
}
316+
.entry:not([compact]) .entry-description[empty] {
317+
color: #000a;
318+
font-style: italic;
319+
}
320+
321+
.entry[compact] {
322+
height: 1rem;
323+
overflow: hidden;
324+
align-items: center;
325+
}
326+
.entry[compact] :not(.entry-platform, .entry-library) {
327+
overflow: hidden;
328+
text-overflow: ellipsis;
329+
white-space: nowrap;
330+
}
331+
.entry[compact] :not(.entry-title) {
332+
font-size: 0.7rem;
333+
}
334+
.entry[compact] :not(.entry-description) {
335+
flex-shrink: 0;
336+
}
337+
.entry[compact] .entry-platform,
338+
.entry[compact] .entry-library {
339+
width: 1.2rem;
340+
height: 1.2rem;
341+
background-size: contain;
342+
background-repeat: no-repeat;
343+
padding-right: 0.2rem;
344+
}
345+
.entry[compact] .entry-title {
346+
font-size: 0.9rem;
347+
padding: 0 0.5rem 0 0.2rem;
348+
max-width: calc(40% - 2.8rem);
349+
}
350+
.entry[compact] .entry-developer {
351+
padding-right: 0.5rem;
352+
max-width: calc(25% - 2.8rem);
353+
}
354+
.entry[compact] .entry-description {
355+
color: #000a;
356+
flex-grow: 1;
357+
}
358+
.entry[compact] .entry-tags {
359+
padding-left: 0.5rem;
360+
max-width: calc(35% - 2.8rem);
361+
}
309362

310363
.viewer {
311364
flex-direction: column;

search/animation.png

355 Bytes
Loading

search/game.png

728 Bytes
Loading

search/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
<input type="text" placeholder="#" class="results-input-page">
5959
<button class="results-go-to-page">Go</button>
6060
</div>
61+
<div class="results-compact">
62+
<input type="checkbox" id="compact"> <label for="compact">Compact View</label>
63+
</div>
6164
</div>
6265
<div class="results-list" hidden></div>
6366
<div class="results-bottom results-navigate" hidden>

search/search.js

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let fpdb = {
22
api: 'https://db-api.unstable.life',
33
images: 'https://infinity.unstable.life/images',
4+
icons: 'https://unstable.life/updater-data/12-1/Data/Logos/',
45
resultsPerPage: 100,
56
metaMap: {
67
title: "Title",
@@ -70,9 +71,6 @@ fetch('fields.json').then(r => r.json()).then(async json => {
7071
fetch('sort.json').then(r => r.json()).then(json => {
7172
fpdb.sortOptions = json;
7273

73-
let options = document.querySelector('.results-sort-options'),
74-
direction = document.querySelector('.results-sort-direction');
75-
7674
for (let sort of json) {
7775
let opt = document.createElement('option');
7876
opt.value = sort.name;
@@ -225,22 +223,12 @@ function loadPage(page) {
225223
});
226224

227225
for (let i = (page - 1) * fpdb.displayedResults; i < Math.min(fpdb.list.length, page * fpdb.displayedResults); i++) {
228-
let entry = document.createElement('div')
226+
let compact = document.querySelector('#compact').checked;
227+
228+
let entry = document.createElement('div');
229229
entry.className = 'entry';
230-
231-
let logo = document.createElement('div');
232-
logo.className = 'entry-logo';
233-
logo.setAttribute('view', i);
234-
logo.setAttribute('lazy-background', `url("${fpdb.images}/Logos/${fpdb.list[i].id.substring(0, 2)}/${fpdb.list[i].id.substring(2, 4)}/${fpdb.list[i].id}.png?type=jpg")`);
235-
logo.addEventListener('click', loadEntry);
236-
logoObserver.observe(logo);
237-
238-
let text = document.createElement('div');
239-
text.className = 'entry-text';
240-
241-
let header = document.createElement('div'),
242-
subHeader = document.createElement('div');
243-
230+
if (compact) entry.setAttribute('compact', 'true');
231+
244232
let title = document.createElement('a');
245233
title.classList.add('entry-title', 'common-activate');
246234
title.setAttribute('view', i);
@@ -255,29 +243,61 @@ function loadPage(page) {
255243
developer.textContent = ' by ' + fpdb.list[i].publisher;
256244
else
257245
developer.hidden = true;
258-
259-
let type = document.createElement('span');
260-
type.className = 'entry-type';
261-
type.textContent = fpdb.list[i].platform.replace(/; /g, '/') + (fpdb.list[i].library == 'arcade' ? ' game' : ' animation');
262-
246+
263247
let tags = document.createElement('span');
264248
tags.className = 'entry-tags';
265-
tags.textContent = ' - ' + fpdb.list[i].tags.join(' - ');
249+
if (compact)
250+
tags.textContent = fpdb.list[i].tags.join(', ');
251+
else
252+
tags.textContent = '\u00A0- ' + fpdb.list[i].tags.join(' - ');
266253

267254
let description = document.createElement('div');
268255
description.className = 'entry-description';
269256
if (fpdb.list[i].originalDescription != '')
270257
description.textContent = fpdb.list[i].originalDescription;
258+
else if (!compact) {
259+
description.textContent = 'No description.';
260+
description.setAttribute('empty', 'true');
261+
}
262+
263+
if (compact) {
264+
let platform = document.createElement('div');
265+
platform.className = 'entry-platform';
266+
let platformName = fpdb.list[i].platform.split('; ')[0];
267+
platform.style.backgroundImage = 'url("' + fpdb.icons + platformName + '.png")';
268+
platform.setAttribute('title', platformName);
269+
270+
let library = document.createElement('div');
271+
library.className = 'entry-library';
272+
library.style.backgroundImage = 'url("' + (fpdb.list[i].library == 'arcade' ? 'game.png' : 'animation.png') + '")';
273+
library.setAttribute('title', fpdb.list[i].library == 'arcade' ? 'Game' : 'Animation');
274+
275+
entry.append(platform, library, title, developer, description, tags);
276+
}
271277
else {
272-
description.textContent = 'No description.'
273-
description.style.color = '#000a';
274-
description.style.fontStyle = 'italic';
278+
let logo = document.createElement('div');
279+
logo.className = 'entry-logo';
280+
logo.setAttribute('view', i);
281+
logo.setAttribute('lazy-background', `url("${fpdb.images}/Logos/${fpdb.list[i].id.substring(0, 2)}/${fpdb.list[i].id.substring(2, 4)}/${fpdb.list[i].id}.png?type=jpg")`);
282+
logo.addEventListener('click', loadEntry);
283+
logoObserver.observe(logo);
284+
285+
let text = document.createElement('div');
286+
text.className = 'entry-text';
287+
288+
let header = document.createElement('div'),
289+
subHeader = document.createElement('div');
290+
291+
let type = document.createElement('span');
292+
type.className = 'entry-type';
293+
type.textContent = fpdb.list[i].platform.replace(/; /g, '/') + (fpdb.list[i].library == 'arcade' ? ' game' : ' animation');
294+
295+
header.append(title, developer);
296+
subHeader.append(type, tags);
297+
text.append(header, subHeader, description);
298+
entry.append(logo, text);
275299
}
276300

277-
header.append(title, developer);
278-
subHeader.append(type, tags);
279-
text.append(header, subHeader, description);
280-
entry.append(logo, text);
281301
htmlList.append(entry);
282302
}
283303
}
@@ -435,6 +455,8 @@ function backToResults() {
435455

436456
document.querySelector('.search-button').addEventListener('click', performSearch);
437457

458+
document.querySelector('#compact').addEventListener('change', () => loadPage(fpdb.currentPage));
459+
438460
document.querySelectorAll('.results-first-page').forEach(elem => elem.addEventListener('click', () => { if (fpdb.currentPage > 1) loadPage(1); }));
439461
document.querySelectorAll('.results-back-page').forEach(elem => elem.addEventListener('click', () => { if (fpdb.currentPage > 1) loadPage(fpdb.currentPage - 1); }));
440462
document.querySelectorAll('.results-forward-page').forEach(elem => elem.addEventListener('click', () => { if (fpdb.currentPage < fpdb.pages) loadPage(fpdb.currentPage + 1); }));

0 commit comments

Comments
 (0)