Skip to content

Commit

Permalink
Reformat scripts & update icon font
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Dec 21, 2022
1 parent e0542b0 commit bbd969b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 47 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ quote_type = double

[*.js]
indent_size = 2
max_line_length = 80
quote_type = single
curly_bracket_next_line = false

Expand Down
4 changes: 2 additions & 2 deletions MangAdventure/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<link href="{% url 'manifest' %}" rel="manifest" type="application/manifest+json">
<link href="{% url 'opensearch' %}" rel="search" title="{{ config.NAME }}"
type="application/opensearchdescription+xml">
<link href="https://cdn.statically.io/gh/mangadventure/font/a894374/dist/mangadventure.css"
integrity="sha384-5/9RTmWZsNNhnHvp5fVgGoWBJoUAdWMMZ2XAYLJA5eT2pt5Bu+sYnYv+7to8veuZ"
<link href="https://cdn.statically.io/gh/mangadventure/font/6363939/dist/mangadventure.css"
integrity="sha384-H1ngkuzUHs3gdzggMN3f3+uloJM6QYgmJhtIMaTbcXk9UymtkKk4PAjsCajEmDxi"
rel="stylesheet" type="text/css" crossorigin="anonymous">
<link href="{{ config.FONT_URL }}" rel="stylesheet" type="text/css" crossorigin="anonymous">
{% endcache %}
Expand Down
13 changes: 9 additions & 4 deletions static/scripts/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
data.append('series', btn.dataset.series);
xhr.open('POST', btn.dataset.target, true);
xhr.onload = function() {
switch(xhr.status) {
case 201: btn.className = 'mi mi-bookmark bookmark-btn'; break;
case 204: btn.className = 'mi mi-bookmark-o bookmark-btn'; break;
default: console.error(xhr.statusText);
switch (xhr.status) {
case 201:
btn.className = 'mi mi-bookmark bookmark-btn';
break;
case 204:
btn.className = 'mi mi-bookmark-o bookmark-btn';
break;
default:
console.error(xhr.statusText);
}
};
xhr.send(data);
Expand Down
25 changes: 15 additions & 10 deletions static/scripts/chapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const img = ph.nextElementSibling;

if(img.complete) ph.remove();
if (img.complete) ph.remove();
else img.addEventListener('load', () => ph.remove(), true);

img.addEventListener('click', function(evt) {
Expand All @@ -18,20 +18,25 @@
document.getElementById('controls').removeAttribute('class');
document.querySelector('.curr-page input')
.addEventListener('keyup', function(evt) {
if(evt.keyCode !== 13) return;
if (evt.code !== 'Enter') return;
const n = Number(this.value);
if(!n || !Number.isInteger(n)) return;
if(n === Number(this.placeholder)) return;
if(n > Number(this.dataset.max)) return;
if(n > 0) location.href = `../${n}/`;
if (!n || !Number.isInteger(n)) return;
if (n === Number(this.placeholder)) return;
if (n > Number(this.dataset.max)) return;
if (n > 0) location.href = `../${n}/`;
});
});

document.body.addEventListener('keyup', evt => {
switch(evt.keyCode) {
case 37: location.href = changePage('prev'); break;
case 39: location.href = changePage('next'); break;
default: return;
switch (evt.code) {
case 'ArrowLeft':
location.href = changePage('prev');
break;
case 'ArrowRight':
location.href = changePage('next');
break;
default:
return;
}
});
})(document.getElementById('placeholder'));
31 changes: 17 additions & 14 deletions static/scripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
}

function matchQuery(q) {
if(q.matches) {
if (q.matches) {
document.querySelectorAll('td.s-hidden').forEach((elem, i) => {
const n = (i / 6 >> 0) + 1;
switch(elem.className) {
switch (elem.className) {
case 'result-people s-hidden':
appendInfo(n, 'people', 'Author/Artist', elem.innerHTML);
break;
Expand Down Expand Up @@ -46,29 +46,30 @@
const form = document.getElementById('search-form');
const table = document.getElementById('result-table');

if(table && window.Tablesort) {
if (table && window.Tablesort) {
new window.Tablesort(table);
table.querySelector('th').removeAttribute('data-sort-default');
}

matchQuery(query);

form['categories[]'].forEach(c => {c.indeterminate = true});
form['categories[]'].forEach(c => { c.indeterminate = true });
(url.searchParams.get('categories') || '').split(',')
.filter(e => e !== '').forEach(c => {
c = c.trim().toLowerCase();
const val = c[0] === '-' ? c.slice(1) : c;
const input = Array.from(form['categories[]']).find(e => e.value === val);
const input = Array.from(form['categories[]'])
.find(e => e.value === val);
input.indeterminate = false;
input.checked = c[0] !== '-';
});
form.elements[5].lastChild.addEventListener('click', evt => {
let el = evt.target;
if(el.tagName === 'I' || el.nodeType === 3)
if (el.tagName === 'I' || el.nodeType === 3)
el = el.parentNode;
if(el.className !== 'tooltip category') return;
if (el.className !== 'tooltip category') return;
const [state, input] = el.children;
switch(state.className) {
switch (state.className) {
case 'mi mi-circle':
state.className = 'mi mi-ok-circle';
input.indeterminate = false;
Expand All @@ -92,19 +93,19 @@
evt.stopPropagation();
form.categories.value = Array.from(form['categories[]'])
.reduce((acc, cur) => {
if(cur.indeterminate) return acc;
if(acc !== '') acc += ',';
if(!cur.checked) acc += '-';
if (cur.indeterminate) return acc;
if (acc !== '') acc += ',';
if (!cur.checked) acc += '-';
return acc + cur.value;
}, '');
Array.from(form.elements).slice(0, 5).concat(form.categories)
.forEach(el => {el.disabled = !el.value});
.forEach(el => { el.disabled = !el.value });
const search = form.action + '?' +
new URLSearchParams(new FormData(form)).toString();
const xhr = new XMLHttpRequest();
xhr.open(form.method, search, true);
xhr.onload = function() {
if(this.status !== 200) {
if (this.status !== 200) {
document.open();
document.write(this.responseText);
document.close();
Expand All @@ -123,7 +124,9 @@
history.replaceState({name: 'search'}, document.title, search);
initialize();
};
xhr.onerror = function() {console.error(this.statusText)};
xhr.onerror = function() {
console.error(this.statusText);
};
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.send(null);
});
Expand Down
33 changes: 16 additions & 17 deletions static/scripts/tinymce-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
window.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.tinymce').forEach(el => {
const mce_conf = JSON.parse(el.dataset.tinymceConfig);
if('replace_icons' in mce_conf) {
if ('replace_icons' in mce_conf) {
const old_setup = mce_conf.setup;
mce_conf.setup = editor => {
if(typeof old_setup === 'function') old_setup(editor);
if (typeof old_setup === 'function') old_setup(editor);
editor.on('init', evt => {
evt.target.editorContainer.querySelectorAll('i')
.forEach(ico => {
if(ico.className === 'mce-caret') {
ico.className = 'mi mi-down';
} else if(ico.className.endsWith('save')) {
ico.className = 'mi mi-send';
ico.nextElementSibling.innerHTML =
mce_conf.submit_text || 'Send';
} else {
ico.className = ico.className
.replace('mce-ico', 'mi')
.replace('mce-i-', 'mi-');
}
});
evt.target.editorContainer.querySelectorAll('i').forEach(ico => {
if (ico.className === 'mce-caret') {
ico.className = 'mi mi-down';
} else if (ico.className.endsWith('save')) {
ico.className = 'mi mi-send';
ico.nextElementSibling.innerHTML =
mce_conf.submit_text || 'Send';
} else {
ico.className = ico.className
.replace('mce-ico', 'mi')
.replace('mce-i-', 'mi-');
}
});
});
};
}
if(!tinyMCE.editors[el.id]) tinyMCE.init(mce_conf);
if (!tinyMCE.editors[el.id]) tinyMCE.init(mce_conf);
});
});

0 comments on commit bbd969b

Please sign in to comment.