2020-10-09 22:32:12 +02:00
|
|
|
/* global CodeMirror window document Set */
|
2017-09-02 21:26:30 +02:00
|
|
|
/* eslint-disable no-implicit-globals */
|
2017-07-28 23:07:09 +02:00
|
|
|
|
2017-01-20 17:59:59 +01:00
|
|
|
// CodeMirror
|
2023-04-23 16:30:20 +02:00
|
|
|
const editor = CodeMirror.fromTextArea(document.getElementById('code'), {
|
2019-06-10 10:18:45 +02:00
|
|
|
lineNumbers: true,
|
|
|
|
styleActiveLine: true,
|
|
|
|
matchBrackets: true,
|
|
|
|
theme: 'pastel-on-dark',
|
2022-12-28 16:05:30 +01:00
|
|
|
lineWrapping: true,
|
2017-01-20 17:59:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// CodeMirror theme selector
|
2023-04-23 16:30:20 +02:00
|
|
|
const input = document.getElementById('select-theme');
|
2017-09-02 21:26:30 +02:00
|
|
|
|
2023-04-23 16:30:20 +02:00
|
|
|
let font_data;
|
|
|
|
const filters = {
|
2022-12-28 16:05:30 +01:00
|
|
|
style: false,
|
|
|
|
rendering: false,
|
|
|
|
liga: false,
|
|
|
|
zerostyle: false,
|
|
|
|
author: 'all',
|
|
|
|
name: '',
|
2019-06-10 14:58:21 +02:00
|
|
|
};
|
2019-06-10 11:04:48 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
const selectTheme = () => {
|
2023-04-23 16:30:20 +02:00
|
|
|
let theme = 'monokai';
|
2017-09-02 21:26:30 +02:00
|
|
|
|
2019-06-10 10:18:45 +02:00
|
|
|
if (input.selectedIndex > -1) {
|
|
|
|
theme = input.options[input.selectedIndex].innerHTML;
|
|
|
|
}
|
|
|
|
editor.setOption('theme', theme);
|
2022-12-28 16:05:30 +01:00
|
|
|
document.cookie = `theme=${theme};max-age=172800`;
|
2022-12-28 16:46:17 +01:00
|
|
|
};
|
2017-01-20 17:59:59 +01:00
|
|
|
|
|
|
|
// ProgrammingFonts font selector
|
2022-12-28 16:05:30 +01:00
|
|
|
const selectFont = () => {
|
2023-04-23 16:30:20 +02:00
|
|
|
let font = window.location.hash.substring(1);
|
|
|
|
const status_msg = document.querySelector('footer .subtitle');
|
|
|
|
const code_mirror = document.querySelector('.CodeMirror');
|
2019-06-10 10:18:45 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
if (!font) {
|
2020-01-12 18:31:00 +01:00
|
|
|
font = 'cartograph';
|
2020-10-09 21:20:52 +02:00
|
|
|
status_msg.innerHTML = 'Test drive all the programming fonts!';
|
2020-10-09 22:32:12 +02:00
|
|
|
} else if (typeof font_data !== 'undefined') {
|
2022-12-28 16:46:17 +01:00
|
|
|
status_msg.innerHTML = `Test drive <a rel="external" href="${font_data[font].website}">${font_data[font].name}!</a>`;
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 22:32:12 +02:00
|
|
|
if (typeof font_data !== 'undefined' && font_data[font].rendering === 'bitmap') {
|
2020-10-09 21:20:52 +02:00
|
|
|
code_mirror.classList.add('no-smooth');
|
2019-06-10 11:40:44 +02:00
|
|
|
} else {
|
2020-10-09 21:20:52 +02:00
|
|
|
code_mirror.classList.remove('no-smooth');
|
2019-06-10 11:40:44 +02:00
|
|
|
}
|
2019-06-10 11:04:48 +02:00
|
|
|
|
2019-06-10 10:18:45 +02:00
|
|
|
if (font === 'input') {
|
2020-10-09 21:20:52 +02:00
|
|
|
code_mirror.style.fontFamily = 'Input Mono, monospace';
|
2022-12-28 16:46:17 +01:00
|
|
|
code_mirror.querySelectorAll('pre, textarea').forEach((element) => {
|
2020-10-09 21:20:52 +02:00
|
|
|
element.style.fontFamily = 'Input Mono, monospace';
|
|
|
|
});
|
2019-06-10 10:18:45 +02:00
|
|
|
} else {
|
2022-12-28 16:05:30 +01:00
|
|
|
code_mirror.style.fontFamily = `${font}, monospace`;
|
2022-12-28 16:46:17 +01:00
|
|
|
code_mirror.querySelectorAll('pre, textarea').forEach((element) => {
|
2022-12-28 16:05:30 +01:00
|
|
|
element.style.fontFamily = `${font}, monospace`;
|
2020-10-09 21:20:52 +02:00
|
|
|
});
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
2020-10-09 21:20:52 +02:00
|
|
|
|
2022-12-28 16:46:17 +01:00
|
|
|
document.querySelectorAll('#select-font [data-alias]').forEach((element) => {
|
2020-10-09 21:20:52 +02:00
|
|
|
element.classList.remove('active');
|
|
|
|
});
|
2022-12-28 16:46:17 +01:00
|
|
|
document.querySelectorAll(`#select-font [data-alias='${font}']`).forEach((element) => {
|
2020-10-09 21:20:52 +02:00
|
|
|
element.classList.add('active');
|
|
|
|
});
|
2019-06-10 10:18:45 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document.cookie = `font=${font};max-age=172800`;
|
2022-12-28 16:46:17 +01:00
|
|
|
};
|
2017-01-20 17:59:59 +01:00
|
|
|
|
2017-07-28 23:07:09 +02:00
|
|
|
window.onhashchange = selectFont;
|
|
|
|
|
2017-01-20 17:59:59 +01:00
|
|
|
function setSize() {
|
2023-04-23 16:30:20 +02:00
|
|
|
const size = document.getElementById('size').value;
|
2017-09-02 21:26:30 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document.querySelector('.CodeMirror').style.fontSize = `${size}px`;
|
|
|
|
document.cookie = `size=${size};max-age=172800`;
|
2023-01-08 03:37:22 +01:00
|
|
|
editor.refresh();
|
2017-01-20 17:59:59 +01:00
|
|
|
}
|
|
|
|
function setSpacing() {
|
2023-04-23 16:30:20 +02:00
|
|
|
const spacing = document.getElementById('spacing').value;
|
2017-09-02 21:26:30 +02:00
|
|
|
|
2020-10-09 21:20:52 +02:00
|
|
|
document.querySelector('.CodeMirror').style.lineHeight = spacing;
|
2022-12-28 16:05:30 +01:00
|
|
|
document.cookie = `spacing=${spacing};max-age=172800`;
|
2023-01-08 03:37:22 +01:00
|
|
|
editor.refresh();
|
2017-01-20 17:59:59 +01:00
|
|
|
}
|
|
|
|
function selectLanguage() {
|
2023-04-23 16:30:20 +02:00
|
|
|
const lang = document.getElementById('select-language').value;
|
2017-09-02 21:26:30 +02:00
|
|
|
|
2019-06-10 10:18:45 +02:00
|
|
|
editor.setOption('mode', lang.toLowerCase());
|
2022-12-28 16:05:30 +01:00
|
|
|
document.cookie = `language=${lang};max-age=172800`;
|
2017-01-20 17:59:59 +01:00
|
|
|
}
|
2019-06-10 20:58:18 +02:00
|
|
|
function setCounter(amount) {
|
2023-04-23 16:30:20 +02:00
|
|
|
const counter_element = document.querySelector('h1 a:first-child');
|
2019-06-10 20:58:18 +02:00
|
|
|
if (amount === 1) {
|
2022-12-28 16:05:30 +01:00
|
|
|
counter_element.innerHTML = `${amount} Programming Font`;
|
2019-06-10 20:58:18 +02:00
|
|
|
} else {
|
2022-12-28 16:05:30 +01:00
|
|
|
counter_element.innerHTML = `${amount} Programming Fonts`;
|
2019-06-10 20:58:18 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-20 17:59:59 +01:00
|
|
|
|
2019-10-27 18:35:01 +01:00
|
|
|
function applyFilters() {
|
2023-04-23 16:30:20 +02:00
|
|
|
let count = 0;
|
2019-10-27 18:35:01 +01:00
|
|
|
|
2022-12-28 16:46:17 +01:00
|
|
|
Object.keys(filters).forEach((filter) => {
|
2023-04-23 16:30:20 +02:00
|
|
|
const button = document.querySelector(`button[value="${filter}"]`);
|
2022-12-28 16:05:30 +01:00
|
|
|
if (!button) {
|
2020-10-07 22:25:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (filters[filter]) {
|
|
|
|
button.classList.add('selected');
|
2022-12-28 16:46:17 +01:00
|
|
|
button.querySelectorAll('svg').forEach((image) => {
|
2020-10-07 22:25:17 +02:00
|
|
|
image.classList.remove('selected');
|
|
|
|
});
|
2022-12-28 16:05:30 +01:00
|
|
|
button.querySelector(`svg[alt="${filters[filter]}"]`).classList.add('selected');
|
2020-10-07 22:25:17 +02:00
|
|
|
} else {
|
|
|
|
button.classList.remove('selected');
|
2022-12-28 16:46:17 +01:00
|
|
|
button.querySelectorAll('svg').forEach((image) => {
|
2020-10-07 22:25:17 +02:00
|
|
|
image.classList.remove('selected');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-08-29 00:17:20 +02:00
|
|
|
|
2022-12-28 16:46:17 +01:00
|
|
|
document.querySelectorAll('.entry[data-alias]').forEach((element) => {
|
2023-04-23 16:30:20 +02:00
|
|
|
const data = font_data[element.dataset.alias];
|
2019-10-27 18:35:01 +01:00
|
|
|
if (
|
|
|
|
(!filters.style || data.style === filters.style) &&
|
|
|
|
(!filters.rendering || data.rendering === filters.rendering) &&
|
2022-12-28 16:05:30 +01:00
|
|
|
(!filters.liga ||
|
|
|
|
(data.ligatures === false && filters.liga === 'no') ||
|
|
|
|
(data.ligatures === true && filters.liga === 'yes')) &&
|
2020-08-29 00:17:20 +02:00
|
|
|
(!filters.zerostyle || data.zerostyle === filters.zerostyle) &&
|
2019-10-27 18:35:01 +01:00
|
|
|
(filters.author === 'all' || data.author === filters.author) &&
|
|
|
|
(!filters.name || data.name.toLowerCase().indexOf(filters.name) > -1)
|
|
|
|
) {
|
2020-10-09 21:20:52 +02:00
|
|
|
element.classList.remove('filtered-out');
|
2019-10-27 18:35:01 +01:00
|
|
|
count++;
|
|
|
|
} else {
|
2020-10-09 21:20:52 +02:00
|
|
|
element.classList.add('filtered-out');
|
2019-10-27 18:35:01 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setCounter(count);
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:45:16 +01:00
|
|
|
function renderSelectList() {
|
2023-04-23 16:30:20 +02:00
|
|
|
const icon =
|
2022-12-28 16:05:30 +01:00
|
|
|
'<svg class="octicon" viewBox="0 0 12 14" version="1.1" width="12" height="14" aria-hidden="true"><path fill-rule="evenodd" d="M11 10h1v3c0 .55-.45 1-1 1H1c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h3v1H1v10h10v-3zM6 2l2.25 2.25L5 7.5 6.5 9l3.25-3.25L12 8V2H6z"></path></svg>';
|
2023-04-23 16:30:20 +02:00
|
|
|
const pinIcon =
|
2022-12-28 16:05:30 +01:00
|
|
|
'<svg class="octicon octicon-pin" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M10 1.2V2l.5 1L6 6H2.2c-.44 0-.67.53-.34.86L5 10l-4 5 5-4 3.14 3.14a.5.5 0 0 0 .86-.34V10l3-4.5 1 .5h.8c.44 0 .67-.53.34-.86L10.86.86a.5.5 0 0 0-.86.34z"></path></svg>';
|
2023-04-23 16:30:20 +02:00
|
|
|
let favoritesMap = {};
|
|
|
|
let favorites = [];
|
|
|
|
const ajax = new XMLHttpRequest();
|
2019-06-10 10:18:45 +02:00
|
|
|
|
2020-10-09 21:20:52 +02:00
|
|
|
document.getElementById('select-font').innerHTML = '';
|
2019-06-10 10:18:45 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
favorites = JSON.parse(localStorage.getItem('favorites')) || [];
|
2022-12-28 16:05:30 +01:00
|
|
|
favoritesMap = favorites.reduce((acc, alias) => {
|
2019-06-10 10:18:45 +02:00
|
|
|
acc[alias] = true;
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
} catch (err) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error('could not render favorites', err);
|
|
|
|
}
|
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
ajax.onreadystatechange = () => {
|
2023-04-23 16:30:20 +02:00
|
|
|
const fonts = [];
|
|
|
|
const authors = [];
|
2020-10-09 22:32:12 +02:00
|
|
|
if (ajax.readyState === 4 && ajax.status === 200) {
|
|
|
|
font_data = ajax.response;
|
|
|
|
|
2022-12-28 16:46:17 +01:00
|
|
|
Object.keys(font_data).forEach((key) => {
|
2023-04-23 16:30:20 +02:00
|
|
|
const v = font_data[key];
|
2020-10-09 22:32:12 +02:00
|
|
|
v.alias = key;
|
|
|
|
fonts.push(v);
|
|
|
|
if (authors.indexOf(v.author) < 0) {
|
|
|
|
authors.push(v.author);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-06-10 20:29:47 +02:00
|
|
|
|
|
|
|
authors.sort();
|
2022-12-28 16:05:30 +01:00
|
|
|
fonts.sort((a, b) => {
|
|
|
|
if (favoritesMap[a.alias] && !favoritesMap[b.alias]) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!favoritesMap[a.alias] && favoritesMap[b.alias]) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
|
|
|
return 1;
|
|
|
|
}
|
2019-06-10 10:18:45 +02:00
|
|
|
return 0;
|
|
|
|
});
|
2019-06-10 11:04:48 +02:00
|
|
|
|
2022-12-28 16:46:17 +01:00
|
|
|
authors.forEach((author) => {
|
2023-04-23 16:30:20 +02:00
|
|
|
const option = document.createElement('option');
|
2020-10-09 22:32:12 +02:00
|
|
|
option.innerHTML = author;
|
|
|
|
document.getElementById('authors-list').querySelector('.other').appendChild(option);
|
|
|
|
});
|
|
|
|
|
2022-12-28 16:46:17 +01:00
|
|
|
fonts.forEach((v) => {
|
2023-04-23 16:30:20 +02:00
|
|
|
const option = document.createElement('div');
|
2019-06-10 10:18:45 +02:00
|
|
|
|
2020-10-09 22:32:12 +02:00
|
|
|
option.classList.add('entry');
|
|
|
|
if (favoritesMap[v.alias]) {
|
|
|
|
option.classList.add('pinned');
|
|
|
|
}
|
2020-10-14 19:51:46 +02:00
|
|
|
|
2020-10-09 22:32:12 +02:00
|
|
|
option.setAttribute('data-alias', v.alias);
|
2022-12-28 16:46:17 +01:00
|
|
|
option.innerHTML = `<a href="#${v.alias}" data-style="${v.style}"><span class="name">${v.name}</span><span class="details">${v.year} — ${v.author}</span></a><a class="favoritelink" onclick="toggleFavorite(\'${v.alias}\')">${pinIcon}</a><a class="website" href="${v.website}" rel="external"> <span>Website</span>${icon}</a>`;
|
2020-10-09 22:32:12 +02:00
|
|
|
|
|
|
|
document.getElementById('select-font').appendChild(option);
|
2019-06-10 10:18:45 +02:00
|
|
|
});
|
2020-10-09 22:32:12 +02:00
|
|
|
|
2019-06-10 10:18:45 +02:00
|
|
|
selectFont();
|
2019-10-27 18:35:01 +01:00
|
|
|
applyFilters();
|
2020-10-09 22:32:12 +02:00
|
|
|
};
|
|
|
|
ajax.responseType = 'json';
|
|
|
|
ajax.open('GET', 'fonts.json', true);
|
|
|
|
ajax.send();
|
2019-01-22 19:45:16 +01:00
|
|
|
}
|
|
|
|
|
2019-06-10 10:18:45 +02:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-01-22 19:45:16 +01:00
|
|
|
function toggleFavorite(alias) {
|
2019-06-10 10:18:45 +02:00
|
|
|
try {
|
2023-04-23 16:30:20 +02:00
|
|
|
let favorites = JSON.parse(localStorage.getItem('favorites')) || [];
|
2019-06-10 10:18:45 +02:00
|
|
|
if (favorites.indexOf(alias) > -1) {
|
2022-12-28 16:46:17 +01:00
|
|
|
favorites = favorites.filter((v) => {
|
2019-06-10 10:18:45 +02:00
|
|
|
return v !== alias;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
favorites.push(alias);
|
|
|
|
}
|
|
|
|
localStorage.setItem('favorites', JSON.stringify(Array.from(new Set(favorites))));
|
|
|
|
} catch (err) {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error('could not save favorite', err);
|
|
|
|
}
|
|
|
|
renderSelectList();
|
|
|
|
return false;
|
2019-01-22 19:45:16 +01:00
|
|
|
}
|
|
|
|
|
2020-10-09 20:32:03 +02:00
|
|
|
function walk(direction) {
|
2023-04-23 16:30:20 +02:00
|
|
|
const activeEntry = document.querySelector('.entry.active');
|
|
|
|
let target = null;
|
|
|
|
let next = direction === 'up' ? activeEntry.previousElementSibling : activeEntry.nextElementSibling;
|
2020-10-09 20:32:03 +02:00
|
|
|
|
|
|
|
while (target === null) {
|
|
|
|
if (next) {
|
|
|
|
if (next.matches('.entry:not(.filtered-out)')) {
|
|
|
|
target = next;
|
|
|
|
} else {
|
2020-10-09 21:20:52 +02:00
|
|
|
next = direction === 'up' ? next.previousElementSibling : next.nextElementSibling;
|
2020-10-09 20:32:03 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target = false;
|
|
|
|
}
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
2019-01-23 21:08:51 +01:00
|
|
|
|
2021-03-01 20:47:07 +01:00
|
|
|
function isVisible(el) {
|
2023-04-23 16:30:20 +02:00
|
|
|
const offset = document.getElementById('filters').getBoundingClientRect().height;
|
|
|
|
const container = document.querySelector('section.select-list').getBoundingClientRect().height;
|
2021-03-01 20:47:07 +01:00
|
|
|
if (direction === 'up') {
|
|
|
|
if (el.getBoundingClientRect().top < offset) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (el.getBoundingClientRect().bottom > offset + container) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-09 20:32:03 +02:00
|
|
|
if (target) {
|
|
|
|
target.querySelector('a').click();
|
2022-12-28 16:05:30 +01:00
|
|
|
if (!isVisible(target)) {
|
2021-03-01 20:47:07 +01:00
|
|
|
target.scrollIntoView();
|
|
|
|
}
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
2019-01-23 21:08:51 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 21:18:30 +01:00
|
|
|
function increaseFontSize() {
|
2023-04-23 16:30:20 +02:00
|
|
|
const sizeEl = document.getElementById('size');
|
2019-01-23 21:18:30 +01:00
|
|
|
sizeEl.value = Number(sizeEl.value) + 1;
|
|
|
|
sizeEl.onchange();
|
|
|
|
}
|
|
|
|
|
|
|
|
function decreaseFontSize() {
|
2023-04-23 16:30:20 +02:00
|
|
|
const sizeEl = document.getElementById('size');
|
2019-01-23 21:18:30 +01:00
|
|
|
sizeEl.value = Number(sizeEl.value) - 1;
|
|
|
|
sizeEl.onchange();
|
|
|
|
}
|
|
|
|
|
2020-10-07 22:25:17 +02:00
|
|
|
function toggleFilter(filter) {
|
|
|
|
// cycle through the possible values for each filter
|
|
|
|
// and set the filters[filter] value,
|
|
|
|
// or at the end of the cycle set it to false
|
2023-04-23 16:30:20 +02:00
|
|
|
const options = {
|
2022-12-28 16:05:30 +01:00
|
|
|
style: [false, 'sans', 'serif'],
|
|
|
|
rendering: [false, 'vector', 'bitmap'],
|
|
|
|
liga: [false, 'yes', 'no'],
|
|
|
|
zerostyle: [false, 'slashed', 'dotted', 'empty'],
|
2020-10-07 22:25:17 +02:00
|
|
|
};
|
|
|
|
|
2023-04-23 16:30:20 +02:00
|
|
|
const current_index = options[filter].indexOf(filters[filter]);
|
|
|
|
const next = current_index + 1;
|
2020-10-07 22:25:17 +02:00
|
|
|
if (next < options[filter].length) {
|
|
|
|
filters[filter] = options[filter][next];
|
|
|
|
} else {
|
|
|
|
filters[filter] = options[filter][0];
|
2019-06-10 14:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
applyFilters();
|
|
|
|
}
|
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
2023-04-23 16:30:20 +02:00
|
|
|
const cookieValueSpacing = document.cookie.replace(/(?:(?:^|.*;\s*)spacing\s*=\s*([^;]*).*$)|^.*$/, '$1');
|
|
|
|
const cookieValueSize = document.cookie.replace(/(?:(?:^|.*;\s*)size\s*=\s*([^;]*).*$)|^.*$/, '$1');
|
|
|
|
const cookieValueTheme = document.cookie.replace(/(?:(?:^|.*;\s*)theme\s*=\s*([^;]*).*$)|^.*$/, '$1');
|
|
|
|
const cookieValueLanguage = document.cookie.replace(/(?:(?:^|.*;\s*)language\s*=\s*([^;]*).*$)|^.*$/, '$1');
|
2019-06-10 10:18:45 +02:00
|
|
|
|
|
|
|
if (cookieValueSpacing !== '') {
|
2020-10-09 21:20:52 +02:00
|
|
|
document.getElementById('spacing').value = cookieValueSpacing;
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
|
|
|
if (cookieValueSize !== '') {
|
2020-10-09 21:20:52 +02:00
|
|
|
document.getElementById('size').value = cookieValueSize;
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
|
|
|
if (cookieValueTheme !== '') {
|
2020-10-09 21:20:52 +02:00
|
|
|
document.getElementById('select-theme').value = cookieValueTheme;
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
|
|
|
if (cookieValueLanguage !== '') {
|
2020-10-09 21:20:52 +02:00
|
|
|
document.getElementById('select-language').value = cookieValueLanguage;
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
|
|
|
|
2019-06-10 20:58:18 +02:00
|
|
|
renderSelectList();
|
2019-06-10 10:18:45 +02:00
|
|
|
selectTheme();
|
|
|
|
setSize();
|
|
|
|
setSpacing();
|
|
|
|
selectLanguage();
|
|
|
|
|
2020-10-09 21:20:52 +02:00
|
|
|
function walkThemes(direction) {
|
2023-04-23 16:30:20 +02:00
|
|
|
const select = document.getElementById('select-theme');
|
|
|
|
const current = select.selectedOptions[0];
|
|
|
|
let next;
|
2020-10-09 21:20:52 +02:00
|
|
|
if (current) {
|
|
|
|
next = direction === 'up' ? current.previousElementSibling : current.nextElementSibling;
|
|
|
|
}
|
|
|
|
if (next) {
|
|
|
|
select.value = next.value;
|
|
|
|
}
|
2019-06-10 10:18:45 +02:00
|
|
|
selectTheme();
|
2020-10-09 21:20:52 +02:00
|
|
|
}
|
2019-06-10 10:18:45 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document.getElementById('theme-next').onclick = () => {
|
2020-10-09 21:20:52 +02:00
|
|
|
walkThemes('down');
|
|
|
|
};
|
2019-06-10 10:18:45 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document.getElementById('theme-previous').onclick = () => {
|
2020-10-09 21:20:52 +02:00
|
|
|
walkThemes('up');
|
|
|
|
};
|
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document
|
|
|
|
.getElementById('filters')
|
|
|
|
.querySelectorAll('button')
|
2022-12-28 16:46:17 +01:00
|
|
|
.forEach((button) => {
|
2022-12-28 16:05:30 +01:00
|
|
|
button.onclick = (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
toggleFilter(button.value);
|
|
|
|
};
|
|
|
|
});
|
2021-04-22 20:34:59 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document.getElementById('authors-list').onchange = (event) => {
|
2020-10-09 21:20:52 +02:00
|
|
|
filters.author = event.target.value;
|
2019-06-10 20:29:47 +02:00
|
|
|
applyFilters();
|
2020-10-09 21:20:52 +02:00
|
|
|
};
|
2021-04-22 20:34:59 +02:00
|
|
|
|
2022-12-28 17:07:20 +01:00
|
|
|
document.getElementById('name-search').onkeyup = (event) => {
|
2020-10-09 21:20:52 +02:00
|
|
|
filters.name = event.target.value.toLowerCase();
|
2019-06-10 20:58:18 +02:00
|
|
|
applyFilters();
|
2020-10-09 21:20:52 +02:00
|
|
|
};
|
2019-06-10 14:58:21 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document.querySelector('.select-list').onkeyup = (event) => {
|
2021-04-22 20:34:59 +02:00
|
|
|
if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) {
|
|
|
|
return;
|
2019-06-10 10:18:45 +02:00
|
|
|
}
|
2021-04-22 20:34:59 +02:00
|
|
|
if (event.key === 'ArrowUp') {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
walk('up');
|
|
|
|
} else if (event.key === 'ArrowDown') {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
walk('down');
|
|
|
|
}
|
|
|
|
};
|
2019-06-10 10:18:45 +02:00
|
|
|
|
2022-12-28 16:05:30 +01:00
|
|
|
document.body.addEventListener('keydown', (event) => {
|
2019-06-10 10:18:45 +02:00
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
if (event.key === '-') {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
decreaseFontSize();
|
|
|
|
} else if (event.key === '=') {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
increaseFontSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-01-20 17:59:59 +01:00
|
|
|
});
|