expand improvements, dont apply to too-small thumbnails and dont reduce width of filename

merge-requests/208/head
fatchan 5 years ago
parent 126f2c7e2c
commit d0fc7ebb9e
  1. 37
      gulp/res/js/expand.js

@ -17,7 +17,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
const volumeSetting = document.getElementById('volume-setting'); const volumeSetting = document.getElementById('volume-setting');
let volumeLevel = localStorage.getItem('volume'); let volumeLevel = localStorage.getItem('volume');
const changeVolume = (change, changeFromConflict) => { const changeVolume = (change) => {
volumeLevel = volumeSetting.value; volumeLevel = volumeSetting.value;
console.log('adjusting volume', volumeLevel); console.log('adjusting volume', volumeLevel);
setLocalStorage('volume', volumeLevel); setLocalStorage('volume', volumeLevel);
@ -41,7 +41,9 @@ window.addEventListener('DOMContentLoaded', (event) => {
//expanding //expanding
thumb.style.display = 'none'; thumb.style.display = 'none';
exp.style.display = ''; exp.style.display = '';
fn.style.maxWidth = exp.offsetWidth+'px'; if (exp.offsetWidth >= fn.offsetWidth) {
fn.style.maxWidth = exp.offsetWidth+'px';
}
if (close) { if (close) {
src.style.visibility = 'hidden'; src.style.visibility = 'hidden';
close.style.display = ''; close.style.display = '';
@ -69,10 +71,10 @@ window.addEventListener('DOMContentLoaded', (event) => {
} }
if (!expandedElement && thumbElement.style.opacity !== '0.5') { if (!expandedElement && thumbElement.style.opacity !== '0.5') {
let source; let source;
fileLink.style.minWidth = fileLink.offsetWidth+'px';
fileLink.style.minHeight = fileLink.offsetHeight+'px';
switch(type) { switch(type) {
case 'image': case 'image':
fileLink.style.minWidth = fileLink.offsetWidth+'px';
fileLink.style.minHeight = fileLink.offsetHeight+'px';
thumbElement.style.opacity = '0.5'; thumbElement.style.opacity = '0.5';
thumbElement.style.cursor = 'wait' thumbElement.style.cursor = 'wait'
expandedElement = document.createElement('img'); expandedElement = document.createElement('img');
@ -85,8 +87,6 @@ window.addEventListener('DOMContentLoaded', (event) => {
} }
break; break;
case 'video': case 'video':
fileLink.style.minWidth = fileLink.offsetWidth+'px';
fileLink.style.minHeight = fileLink.offsetHeight+'px';
case 'audio': case 'audio':
expandedElement = document.createElement(type); expandedElement = document.createElement(type);
close = document.createElement('div'); close = document.createElement('div');
@ -114,19 +114,34 @@ window.addEventListener('DOMContentLoaded', (event) => {
return false; return false;
}; };
for (let i = 0; i < thumbs.length; i++) { const dontexpand = (e) => {
thumbs[i].addEventListener('click', expand, false); e.preventDefault();
} }
const addExpandEvent = (t) => {
for (let i = 0; i < t.length; i++) {
const type = t[i].dataset.type;
const thumb = t[i].firstChild.firstChild;
const thumbsrc = thumb.getAttribute('src');
if (type !== 'image' || thumbsrc.startsWith('/img/thumb') || thumbsrc.startsWith('/img/spoiler')) {
//non-images, non-spoiler s and images with thumnbs are expanded
t[i].addEventListener('click', expand, false);
} else {
//otherwise (too small images), dont expand. add dummy event to stop opening in new tab
t[i].addEventListener('click', dontexpand, false);
}
}
}
addExpandEvent(thumbs)
window.addEventListener('addPost', function(e) { window.addEventListener('addPost', function(e) {
if (e.detail.hover) { if (e.detail.hover) {
return; //dont need to handle hovered posts for this return; //dont need to handle hovered posts for this
} }
const post = e.detail.post; const post = e.detail.post;
const newthumbs = post.getElementsByClassName('post-file-src'); const newthumbs = post.getElementsByClassName('post-file-src');
for (let i = 0; i < newthumbs.length; i++) { addExpandEvent(newthumbs);
newthumbs[i].addEventListener('click', expand, false);
}
}); });
} }

Loading…
Cancel
Save