bigtime cleanup and make some more frontend code use proper classes. more extensible

merge-requests/208/head
fatchan 4 years ago
parent d512c69652
commit 1ee3857629
  1. 549
      gulp/res/css/style.css
  2. 51
      gulp/res/js/expand.js
  3. 153
      gulp/res/js/hide.js
  4. 2
      gulp/res/js/modal.js
  5. 14
      gulp/res/js/theme.js
  6. 2
      views/mixins/modal.pug

File diff suppressed because it is too large Load Diff

@ -1,7 +1,5 @@
setDefaultLocalStorage('volume', 100);
setDefaultLocalStorage('loop', false);
setDefaultLocalStorage('heightlimit', true);
setDefaultLocalStorage('crispimages', false);
window.addEventListener('DOMContentLoaded', (event) => {
@ -36,16 +34,6 @@ window.addEventListener('DOMContentLoaded', (event) => {
loopSetting.checked = loopEnabled;
loopSetting.addEventListener('change', toggleLoop, false);
const heightlimitSetting = document.getElementById('heightlimit-setting');
let heightlimitEnabled = localStorage.getItem('heightlimit') == 'true';
const toggleHeightlimit = (change) => {
heightlimitEnabled = heightlimitSetting.checked;
console.log('toggling image height limit', heightlimitEnabled);
setLocalStorage('heightlimit', heightlimitEnabled);
}
heightlimitSetting.checked = heightlimitEnabled;
heightlimitSetting.addEventListener('change', toggleHeightlimit, false);
if (!isCatalog) { //dont expand on catalog
const thumbs = document.getElementsByClassName('post-file-src');
const toggle = function(thumb, exp, fn, src) {
@ -54,11 +42,6 @@ window.addEventListener('DOMContentLoaded', (event) => {
} else {
exp.loop = false;
}
if (!heightlimitEnabled) {
exp.classList.add('mh-100');
} else {
exp.classList.remove('mh-100');
}
exp.volume = volumeLevel/100;
const close = exp.previousSibling.innerText === 'Close' ? exp.previousSibling : null;
if (thumb.style.display === 'none') {
@ -111,6 +94,40 @@ window.addEventListener('DOMContentLoaded', (event) => {
fileLink.style.minHeight = fileLink.offsetHeight+'px';
switch(type) {
case 'image':
/* loading bar experiment; causes some issues with loading speed from cache and extra requests
const request = new XMLHttpRequest();
request.onprogress = (e) => {
const progress = Math.floor((e.loaded/e.total)*100);
const progressWidth = Math.floor((e.loaded/e.total)*thumbElement.width);
if (progress >= 100) {
pfs.removeAttribute('data-loading');
} else {
pfs.setAttribute('data-loading', progress);
pfs.style = `--data-loading: ${progressWidth}px`;
}
}
expandedElement = document.createElement('img');
source = expandedElement;
let once = false;
//some jank here to try and recude any delay induced by xhr
const loaded = function() {
pfs.removeAttribute('data-loading');
pfs.removeAttribute('style');
if (once) {
return;
}
source.src = fileSrc;
once = true;
thumbElement.style.opacity = '';
thumbElement.style.cursor = '';
fileLink.appendChild(expandedElement);
toggle(thumbElement, expandedElement, fileName, pfs);
}
source.onload = loaded;
request.onload = loaded;
request.open('GET', fileSrc, true);
request.send(null);
*/
e.preventDefault();
thumbElement.style.opacity = '0.5';
thumbElement.style.cursor = 'wait'

@ -1,12 +1,3 @@
/*
setDefaultLocalStorage('hidestubs', false);
let hideStubsEnabled = localStorage.getItem('hidestubs') == 'true';
*/
setDefaultLocalStorage('hiderecursive', false);
let hideRecursiveEnabled = localStorage.getItem('hiderecursive') == 'true';
setDefaultLocalStorage('hideimages', false);
let hideImagesEnabled = localStorage.getItem('hideimages') == 'true';
const fileInput = document.getElementById('file');
fileInput ? fileInput.style.display = 'none' : void 0;
let hidden;
@ -18,7 +9,7 @@ const loadHiddenStorage = () => {
return;
}
} catch (e) {
//ignore
console.error(e);
}
//set to empty if not exist or error parsing
setLocalStorage('hidden', '[]');
@ -76,7 +67,7 @@ const changeOption = function(e) {
}
this.value = '';
setHidden(posts, hiding);
setLocalStorage('hidden', JSON.stringify([...hidden]));
setLocalStorage('hidden', JSON.stringify([...hidden]));
}
for (let menu of document.getElementsByClassName('postmenu')) {
@ -104,95 +95,64 @@ for (let elem of hidden) {
setHidden(posts, true);
}
const hideImages = () => {
const postThumbs = document.getElementsByClassName('file-thumb');
for (thumb of postThumbs) {
thumb.classList.toggle('invisible');
}
}
if (hideImagesEnabled) {
hideImages();
}
const renderCSSLink = document.createElement('style');
renderCSSLink.type = 'text/css';
renderCSSLink.id = 'rendercss';
document.head.appendChild(renderCSSLink);
const renderSheet = renderCSSLink.sheet;
const rulesKey = renderSheet.rules ? 'rules' : 'cssRules';
window.addEventListener('settingsReady', function(event) {
const mainStyleSheet = document.querySelector('link[rel="stylesheet"]').sheet;
const replaceCssRule = (selectorText, css) => {
const rulesKey = mainStyleSheet.rules != null ? 'rules' : 'cssRules';
for (let i = 0; i < mainStyleSheet[rulesKey].length; i++) {
const rule = mainStyleSheet[rulesKey][i];
if(rule.selectorText == selectorText) {
mainStyleSheet.removeRule(i);
return;
}
}
mainStyleSheet.insertRule(css);
return;
class CssToggle {
constructor (settingId, localStorageKey, settingCss) {
this.localStorageKey = localStorageKey;
this.settingBoolean = localStorage.getItem(this.localStorageKey) == 'true';
this.settingCss = settingCss;
window.addEventListener('settingsReady', () => {
//on event fire, set boolean to correct checked stats
this.setting = document.getElementById(settingId);
this.setting.checked = this.settingBoolean;
this.setting.addEventListener('change', () => {
this.toggle();
}, false);
});
this.toggle();
}
const hideRecursiveCss = `.op.hidden ~ .anchor, .op.hidden ~ .post-container {
display: none;
}`;
const hideRecursiveSetting = document.getElementById('hiderecursive-setting');
hideRecursiveSetting.checked = hideRecursiveEnabled;
hideRecursiveEnabled && replaceCssRule('.post-container.hidden, .catalog-tile.hidden', hideRecursiveCss);
const toggleHideRecursive = () => {
hideRecursiveEnabled = !hideRecursiveEnabled;
replaceCssRule('.op.hidden ~ .anchor, .op.hidden ~ .post-container', hideRecursiveCss);
console.log('toggling recursive hide', hideRecursiveEnabled);
setLocalStorage('hiderecursive', hideRecursiveEnabled);
}
hideRecursiveSetting.addEventListener('change', toggleHideRecursive, false);
/*
const hideStubsCss = `.post-container.hidden, .catalog-tile.hidden {
visibility: hidden;
margin-top: -1.5em;
height: 0;
}`;
const hideStubsSetting = document.getElementById('hidestubs-setting');
hideStubsSetting.checked = hideStubsEnabled;
hideStubsEnabled && replaceCssRule('.post-container.hidden, .catalog-tile.hidden', hideStubsCss);
const toggleHideStubs = () => {
hideStubsEnabled = !hideStubsEnabled;
replaceCssRule('.post-container.hidden, .catalog-tile.hidden', hideStubsCss);
console.log('toggling hiding stubs', hideStubsEnabled);
setLocalStorage('hidestubs', hideStubsEnabled);
toggle () {
this.settingBoolean = !this.settingBoolean;
if (this.settingBoolean) {
renderSheet.insertRule(this.settingCss);
} else {
for (let i = 0; i < renderSheet[rulesKey].length; i++) {
if (renderSheet[rulesKey][i].cssText == this.settingCss) {
renderSheet.deleteRule(i);
}
}
}
console.log('toggling', this.localStorageKey, this.settingBoolean);
setLocalStorage(this.localStorageKey, this.settingBoolean);
}
hideStubsSetting.addEventListener('change', toggleHideStubs, false);
*/
};
const crispSetting = document.getElementById('crispimages-setting');
let crispEnabled = localStorage.getItem('crispimages') == 'true';
const normCss = 'img{image-rendering:auto}';
const crispCss = `img{
image-rendering: crisp-edges;
image-rendering: pixelated;
image-rendering: -webkit-optimize-contrast;
-ms-interpolation-mode: nearest-neighbor;
}`;
replaceCssRule('img', crispEnabled ? crispCss : normCss);
const changeCrispSetting = (change) => {
crispEnabled = crispSetting.checked;
replaceCssRule('img', crispEnabled ? crispCss : normCss);
console.log('setting images crisp', crispEnabled);
setLocalStorage('crispimages', crispEnabled);
}
crispSetting.checked = crispEnabled;
crispSetting.addEventListener('change', changeCrispSetting, false);
//det localstorage defaults
// setDefaultLocalStorage('hidestubs', false);
setDefaultLocalStorage('hiderecursive', false);
setDefaultLocalStorage('hideimages', false);
setDefaultLocalStorage('crispimages', false);
setDefaultLocalStorage('heightlimit', false);
//todo: option here and in modal for clearing hide list and unhide all hidden posts
const hideImagesSetting = document.getElementById('hideimages-setting');
hideImagesSetting.checked = hideImagesEnabled;
const toggleHideImages = () => {
hideImagesEnabled = !hideImagesEnabled
setLocalStorage('hideimages', hideImagesEnabled);
hideImages();
}
hideImagesSetting.addEventListener('change', toggleHideImages, false);
//define the css
//const hideStubsCss = `.post-container.hidden, .catalog-tile.hidden { visibility: hidden;margin-top: -1.5em;height: 0; }`;
const hideImagesCss = `.file-thumb { visibility: hidden !important; }`
const hideRecursiveCss = `.op.hidden ~ .anchor, .op.hidden ~ .post-container { display: none; }`;
const heightlimitCss = `img, video { max-height: unset; }`;
const crispCss = `img { image-rendering: crisp-edges; }`;
});
//make classes with css
//new CssToggle('hidestubs-setting', 'hidestubs', hideStubsCss);
new CssToggle('hiderecursive-setting', 'hiderecursive', hideRecursiveCss);
new CssToggle('heightlimit-setting', 'heightlimit', heightlimitCss);
new CssToggle('crispimages-setting', 'crispimages', crispCss);
new CssToggle('hideimages-setting', 'hideimages', hideImagesCss);
window.addEventListener('addPost', function(e) {
const post = e.detail.post;
@ -201,11 +161,6 @@ window.addEventListener('addPost', function(e) {
if (hidden.has(hiddenKey) || hidden.has(userId)) {
post.classList.add('hidden');
}
if (hideImagesEnabled) {
for (thumb of post.querySelectorAll('.file-thumb')) {
thumb.classList.add('invisible');
}
}
const menu = post.querySelector('.postmenu');
for (let i = 0; i < menu.children.length; i++) {
menu.children[i].originalText = menu.children[i].innerText;

@ -95,7 +95,7 @@ pug_html = pug_html + "\u003Coption" + (pug_attr("value", theme, true, false)) +
}
}).call(this);
pug_html = pug_html + "\u003C\u002Fselect\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ELive posts\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"live-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ENotifications\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"notification-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EScroll to new posts\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"scroll-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ELocal time\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"localtime-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003E24h time\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"24hour-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EShow relative time\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"relative-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EHide Thumbnails\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"hideimages-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ERecursive Post Hide\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"hiderecursive-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EVideo\u002FAudio Volume\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"volume-setting\" type=\"range\" min=\"0\" max=\"100\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ELoop audio\u002Fvideo\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"loop-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ELimit expand height\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"heightlimit-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ECrisp image rendering\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"crispimages-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ECustom CSS\u003C\u002Fdiv\u003E\u003Ctextarea id=\"customcss-setting\"\u003E\u003C\u002Ftextarea\u003E\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E";
pug_html = pug_html + "\u003C\u002Fselect\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ELive posts\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"live-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ENotifications\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"notification-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EScroll to new posts\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"scroll-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ELocal time\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"localtime-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003E24h time\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"24hour-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EShow relative time\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"relative-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EHide Thumbnails\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"hideimages-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ERecursive Post Hide\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"hiderecursive-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EVideo\u002FAudio Volume\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"volume-setting\" type=\"range\" min=\"0\" max=\"100\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ELoop audio\u002Fvideo\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"loop-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003EUnlimit expand height\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"heightlimit-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ECrisp image rendering\u003C\u002Fdiv\u003E\u003Clabel class=\"postform-style ph-5\"\u003E\u003Cinput id=\"crispimages-setting\" type=\"checkbox\"\u002F\u003E\u003C\u002Flabel\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"row\"\u003E\u003Cdiv class=\"label\"\u003ECustom CSS\u003C\u002Fdiv\u003E\u003Ctextarea id=\"customcss-setting\"\u003E\u003C\u002Ftextarea\u003E\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E";
}
pug_html = pug_html + "\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E";
};

@ -1,6 +1,7 @@
setDefaultLocalStorage('theme', 'default');
setDefaultLocalStorage('codetheme', 'default');
setDefaultLocalStorage('customcss', '');
let customCSSString = localStorage.getItem('customcss');
window.addEventListener('settingsReady', function(event) {
@ -22,7 +23,6 @@ window.addEventListener('settingsReady', function(event) {
//custom CSS for users
const customCSSSetting = document.getElementById('customcss-setting');
let customCSSString = localStorage.getItem('customcss');
const editCustomCSS = (change) => {
customCSSString = customCSSSetting.value;
console.log('editing custom CSS', customCSSString.length);
@ -34,6 +34,11 @@ window.addEventListener('settingsReady', function(event) {
});
const customCSSLink = document.createElement('style');
customCSSLink.rel = 'stylesheet';
customCSSLink.id = 'customcss';
document.head.appendChild(customCSSLink);
function changeTheme(type) {
switch(type) {
case 'theme':
@ -78,13 +83,6 @@ function changeTheme(type) {
}
break;
case 'customcss':
let customCSSLink = document.getElementById(type);
if (!customCSSLink) {
customCSSLink = document.createElement('style');
customCSSLink.rel = 'stylesheet';
customCSSLink.id = 'customcss';
document.head.appendChild(customCSSLink);
}
customCSSLink.innerHTML = localStorage.getItem('customcss');
break;
}

@ -72,7 +72,7 @@ mixin modal(data)
label.postform-style.ph-5
input#loop-setting(type='checkbox')
.row
.label Limit expand height
.label Unlimit expand height
label.postform-style.ph-5
input#heightlimit-setting(type='checkbox')
.row

Loading…
Cancel
Save