jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.8 KiB

window.addEventListener('DOMContentLoaded', (event) => {
5 years ago
const thumbs = document.getElementsByClassName('post-file-src');
5 years ago
const toggle = function(thumb, exp, fn) {
const close = exp.previousSibling.innerText === 'Close video' ? exp.previousSibling : null;
if (thumb.style.display === 'none') {
thumb.style.display = '';
exp.style.display = 'none';
5 years ago
fn.style.maxWidth = '';
if (close) {
close.style.display = 'none';
exp.pause();
}
} else {
thumb.style.display = 'none';
exp.style.display = '';
5 years ago
fn.style.maxWidth = exp.offsetWidth+'px';
if (close) {
close.style.display = '';
exp.play();
}
}
}
5 years ago
const expand = function(e) {
e.preventDefault();
const fileLink = this.firstChild;
const fileSrc = fileLink.href;
const type = this.dataset.type;
const thumbElement = fileLink.firstChild;
5 years ago
const fileName = this.previousSibling;
const next = thumbElement.nextSibling;
let expandedElement;
if (next) {
if (next.innerText === 'Close video') {
expandedElement = next.nextSibling;
} else {
expandedElement = next;
}
}
if (!expandedElement && thumbElement.style.opacity !== '0.5') {
fileLink.style.minWidth = fileLink.offsetWidth+'px';
fileLink.style.minHeight = fileLink.offsetHeight+'px';
let source;
switch(type) {
case 'image':
thumbElement.style.opacity = '0.5';
thumbElement.style.cursor = 'wait'
expandedElement = document.createElement('img');
source = expandedElement;
source.onload = function() {
thumbElement.style.opacity = '';
thumbElement.style.cursor = '';
fileLink.appendChild(expandedElement);
5 years ago
toggle(thumbElement, expandedElement, fileName);
}
break;
case 'video':
expandedElement = document.createElement('video');
close = document.createElement('div');
close.innerText = 'Close video';
close.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
5 years ago
toggle(thumbElement, expandedElement, fileName);
}, true);
expandedElement.controls = 'true';
source = document.createElement('source');
expandedElement.appendChild(source);
fileLink.appendChild(expandedElement);
fileLink.insertBefore(close, expandedElement);
5 years ago
toggle(thumbElement, expandedElement, fileName);
break;
deault:
break; //uh oh
}
source.src = fileSrc;
} else if (expandedElement) {
5 years ago
toggle(thumbElement, expandedElement, fileName);
}
return false;
};
5 years ago
for (let i = 0; i < thumbs.length; i++) {
thumbs[i].addEventListener('click', expand, false);
}
window.addEventListener('addPost', function(e) {
const post = e.detail.post;
const newthumbs = post.getElementsByClassName('post-file-src');
for (let i = 0; i < newthumbs.length; i++) {
newthumbs[i].addEventListener('click', expand, false);
}
});
});