mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-02-17 19:29:28 +01:00
Merge pull request #781 from Zankaria/main-js-refactor
Refactor main.js
This commit is contained in:
commit
0fbf2f6f77
@ -2,27 +2,27 @@
|
||||
* catalog-search.js
|
||||
* - Search and filters threads when on catalog view
|
||||
* - Optional shortcuts 's' and 'esc' to open and close the search.
|
||||
*
|
||||
*
|
||||
* Usage:
|
||||
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
||||
* $config['additional_javascript'][] = 'js/comment-toolbar.js';
|
||||
*/
|
||||
if (active_page == 'catalog') {
|
||||
onready(function () {
|
||||
onReady(function() {
|
||||
'use strict';
|
||||
|
||||
// 'true' = enable shortcuts
|
||||
var useKeybinds = true;
|
||||
// 'true' = enable shortcuts
|
||||
let useKeybinds = true;
|
||||
|
||||
// trigger the search 400ms after last keystroke
|
||||
var delay = 400;
|
||||
var timeoutHandle;
|
||||
// trigger the search 400ms after last keystroke
|
||||
let delay = 400;
|
||||
let timeoutHandle;
|
||||
|
||||
//search and hide none matching threads
|
||||
// search and hide none matching threads
|
||||
function filter(search_term) {
|
||||
$('.replies').each(function () {
|
||||
var subject = $(this).children('.intro').text().toLowerCase();
|
||||
var comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase();
|
||||
let subject = $(this).children('.intro').text().toLowerCase();
|
||||
let comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase();
|
||||
search_term = search_term.toLowerCase();
|
||||
|
||||
if (subject.indexOf(search_term) == -1 && comment.indexOf(search_term) == -1) {
|
||||
@ -34,7 +34,7 @@ if (active_page == 'catalog') {
|
||||
}
|
||||
|
||||
function searchToggle() {
|
||||
var button = $('#catalog_search_button');
|
||||
let button = $('#catalog_search_button');
|
||||
|
||||
if (!button.data('expanded')) {
|
||||
button.data('expanded', '1');
|
||||
@ -59,18 +59,18 @@ if (active_page == 'catalog') {
|
||||
});
|
||||
|
||||
if (useKeybinds) {
|
||||
// 's'
|
||||
// 's'
|
||||
$('body').on('keydown', function (e) {
|
||||
if (e.which === 83 && e.target.tagName === 'BODY' && !(e.ctrlKey || e.altKey || e.shiftKey)) {
|
||||
e.preventDefault();
|
||||
if ($('#search_field').length !== 0) {
|
||||
if ($('#search_field').length !== 0) {
|
||||
$('#search_field').focus();
|
||||
} else {
|
||||
searchToggle();
|
||||
}
|
||||
}
|
||||
});
|
||||
// 'esc'
|
||||
// 'esc'
|
||||
$('.catalog_search').on('keydown', 'input#search_field', function (e) {
|
||||
if (e.which === 27 && !(e.ctrlKey || e.altKey || e.shiftKey)) {
|
||||
window.clearTimeout(timeoutHandle);
|
||||
|
@ -15,16 +15,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
onready(function(){
|
||||
var do_original_filename = function() {
|
||||
var filename, truncated;
|
||||
onReady(function() {
|
||||
let doOriginalFilename = function() {
|
||||
let filename, truncated;
|
||||
if ($(this).attr('title')) {
|
||||
filename = $(this).attr('title');
|
||||
truncated = true;
|
||||
} else {
|
||||
filename = $(this).text();
|
||||
}
|
||||
|
||||
|
||||
$(this).replaceWith(
|
||||
$('<a></a>')
|
||||
.attr('download', filename)
|
||||
@ -34,9 +34,9 @@ onready(function(){
|
||||
);
|
||||
};
|
||||
|
||||
$('.postfilename').each(do_original_filename);
|
||||
$('.postfilename').each(doOriginalFilename);
|
||||
|
||||
$(document).on('new_post', function(e, post) {
|
||||
$(post).find('.postfilename').each(do_original_filename);
|
||||
$(document).on('new_post', function(e, post) {
|
||||
$(post).find('.postfilename').each(doOriginalFilename);
|
||||
});
|
||||
});
|
||||
|
@ -16,37 +16,42 @@
|
||||
*
|
||||
*/
|
||||
|
||||
if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index')
|
||||
onready(function(){
|
||||
$('hr:first').before('<div id="expand-all-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)"></a></div>');
|
||||
$('div#expand-all-images a')
|
||||
.text(_('Expand all images'))
|
||||
.click(function() {
|
||||
$('a img.post-image').each(function() {
|
||||
// Don't expand YouTube embeds
|
||||
if ($(this).parent().parent().hasClass('video-container'))
|
||||
return;
|
||||
if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index') {
|
||||
onReady(function() {
|
||||
$('hr:first').before('<div id="expand-all-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)"></a></div>');
|
||||
$('div#expand-all-images a')
|
||||
.text(_('Expand all images'))
|
||||
.click(function() {
|
||||
$('a img.post-image').each(function() {
|
||||
// Don't expand YouTube embeds
|
||||
if ($(this).parent().parent().hasClass('video-container')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// or WEBM
|
||||
if (/^\/player\.php\?/.test($(this).parent().attr('href')))
|
||||
return;
|
||||
// or WEBM
|
||||
if (/^\/player\.php\?/.test($(this).parent().attr('href'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$(this).parent().data('expanded'))
|
||||
$(this).parent().click();
|
||||
});
|
||||
|
||||
if (!$('#shrink-all-images').length) {
|
||||
$('hr:first').before('<div id="shrink-all-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)"></a></div>');
|
||||
}
|
||||
|
||||
$('div#shrink-all-images a')
|
||||
.text(_('Shrink all images'))
|
||||
.click(function(){
|
||||
$('a img.full-image').each(function() {
|
||||
if ($(this).parent().data('expanded'))
|
||||
$(this).parent().click();
|
||||
});
|
||||
$(this).parent().remove();
|
||||
if (!$(this).parent().data('expanded')) {
|
||||
$(this).parent().click();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (!$('#shrink-all-images').length) {
|
||||
$('hr:first').before('<div id="shrink-all-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)"></a></div>');
|
||||
}
|
||||
|
||||
$('div#shrink-all-images a')
|
||||
.text(_('Shrink all images'))
|
||||
.click(function() {
|
||||
$('a img.full-image').each(function() {
|
||||
if ($(this).parent().data('expanded')) {
|
||||
$(this).parent().click();
|
||||
}
|
||||
});
|
||||
$(this).parent().remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -2,243 +2,265 @@
|
||||
/* Note: This code expects the global variable configRoot to be set. */
|
||||
|
||||
if (typeof _ == 'undefined') {
|
||||
var _ = function(a) { return a; };
|
||||
var _ = function(a) {
|
||||
return a;
|
||||
};
|
||||
}
|
||||
|
||||
function setupVideo(thumb, url) {
|
||||
if (thumb.videoAlreadySetUp) return;
|
||||
thumb.videoAlreadySetUp = true;
|
||||
if (thumb.videoAlreadySetUp) {
|
||||
return;
|
||||
}
|
||||
thumb.videoAlreadySetUp = true;
|
||||
|
||||
var video = null;
|
||||
var videoContainer, videoHide;
|
||||
var expanded = false;
|
||||
var hovering = false;
|
||||
var loop = true;
|
||||
var loopControls = [document.createElement("span"), document.createElement("span")];
|
||||
var fileInfo = thumb.parentNode.querySelector(".fileinfo");
|
||||
var mouseDown = false;
|
||||
let video = null;
|
||||
let videoContainer, videoHide;
|
||||
let expanded = false;
|
||||
let hovering = false;
|
||||
let loop = true;
|
||||
let loopControls = [document.createElement("span"), document.createElement("span")];
|
||||
let fileInfo = thumb.parentNode.querySelector(".fileinfo");
|
||||
let mouseDown = false;
|
||||
|
||||
function unexpand() {
|
||||
if (expanded) {
|
||||
expanded = false;
|
||||
if (video.pause) video.pause();
|
||||
videoContainer.style.display = "none";
|
||||
thumb.style.display = "inline";
|
||||
video.style.maxWidth = "inherit";
|
||||
video.style.maxHeight = "inherit";
|
||||
}
|
||||
}
|
||||
function unexpand() {
|
||||
if (expanded) {
|
||||
expanded = false;
|
||||
if (video.pause) {
|
||||
video.pause();
|
||||
}
|
||||
videoContainer.style.display = "none";
|
||||
thumb.style.display = "inline";
|
||||
video.style.maxWidth = "inherit";
|
||||
video.style.maxHeight = "inherit";
|
||||
}
|
||||
}
|
||||
|
||||
function unhover() {
|
||||
if (hovering) {
|
||||
hovering = false;
|
||||
if (video.pause) video.pause();
|
||||
videoContainer.style.display = "none";
|
||||
video.style.maxWidth = "inherit";
|
||||
video.style.maxHeight = "inherit";
|
||||
}
|
||||
}
|
||||
function unhover() {
|
||||
if (hovering) {
|
||||
hovering = false;
|
||||
if (video.pause) {
|
||||
video.pause();
|
||||
}
|
||||
videoContainer.style.display = "none";
|
||||
video.style.maxWidth = "inherit";
|
||||
video.style.maxHeight = "inherit";
|
||||
}
|
||||
}
|
||||
|
||||
// Create video element if does not exist yet
|
||||
function getVideo() {
|
||||
if (video == null) {
|
||||
video = document.createElement("video");
|
||||
video.src = url;
|
||||
video.loop = loop;
|
||||
video.innerText = _("Your browser does not support HTML5 video.");
|
||||
// Create video element if does not exist yet
|
||||
function getVideo() {
|
||||
if (video == null) {
|
||||
video = document.createElement("video");
|
||||
video.src = url;
|
||||
video.loop = loop;
|
||||
video.innerText = _("Your browser does not support HTML5 video.");
|
||||
|
||||
videoHide = document.createElement("img");
|
||||
videoHide.src = configRoot + "static/collapse.gif";
|
||||
videoHide.alt = "[ - ]";
|
||||
videoHide.title = "Collapse video";
|
||||
videoHide.style.marginLeft = "-15px";
|
||||
videoHide.style.cssFloat = "left";
|
||||
videoHide.addEventListener("click", unexpand, false);
|
||||
videoHide = document.createElement("img");
|
||||
videoHide.src = configRoot + "static/collapse.gif";
|
||||
videoHide.alt = "[ - ]";
|
||||
videoHide.title = "Collapse video";
|
||||
videoHide.style.marginLeft = "-15px";
|
||||
videoHide.style.cssFloat = "left";
|
||||
videoHide.addEventListener("click", unexpand, false);
|
||||
|
||||
videoContainer = document.createElement("div");
|
||||
videoContainer.style.paddingLeft = "15px";
|
||||
videoContainer.style.display = "none";
|
||||
videoContainer.appendChild(videoHide);
|
||||
videoContainer.appendChild(video);
|
||||
thumb.parentNode.insertBefore(videoContainer, thumb.nextSibling);
|
||||
videoContainer = document.createElement("div");
|
||||
videoContainer.style.paddingLeft = "15px";
|
||||
videoContainer.style.display = "none";
|
||||
videoContainer.appendChild(videoHide);
|
||||
videoContainer.appendChild(video);
|
||||
thumb.parentNode.insertBefore(videoContainer, thumb.nextSibling);
|
||||
|
||||
// Dragging to the left collapses the video
|
||||
video.addEventListener("mousedown", function(e) {
|
||||
if (e.button == 0) mouseDown = true;
|
||||
}, false);
|
||||
video.addEventListener("mouseup", function(e) {
|
||||
if (e.button == 0) mouseDown = false;
|
||||
}, false);
|
||||
video.addEventListener("mouseenter", function(e) {
|
||||
mouseDown = false;
|
||||
}, false);
|
||||
video.addEventListener("mouseout", function(e) {
|
||||
if (mouseDown && e.clientX - video.getBoundingClientRect().left <= 0) {
|
||||
unexpand();
|
||||
}
|
||||
mouseDown = false;
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
// Dragging to the left collapses the video
|
||||
video.addEventListener("mousedown", function(e) {
|
||||
if (e.button == 0) mouseDown = true;
|
||||
}, false);
|
||||
video.addEventListener("mouseup", function(e) {
|
||||
if (e.button == 0) mouseDown = false;
|
||||
}, false);
|
||||
video.addEventListener("mouseenter", function(e) {
|
||||
mouseDown = false;
|
||||
}, false);
|
||||
video.addEventListener("mouseout", function(e) {
|
||||
if (mouseDown && e.clientX - video.getBoundingClientRect().left <= 0) {
|
||||
unexpand();
|
||||
}
|
||||
mouseDown = false;
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Clicking on thumbnail expands video
|
||||
thumb.addEventListener("click", function(e) {
|
||||
if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
||||
getVideo();
|
||||
expanded = true;
|
||||
hovering = false;
|
||||
// Clicking on thumbnail expands video
|
||||
thumb.addEventListener("click", function(e) {
|
||||
if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
||||
getVideo();
|
||||
expanded = true;
|
||||
hovering = false;
|
||||
|
||||
video.style.position = "static";
|
||||
video.style.pointerEvents = "inherit";
|
||||
video.style.display = "inline";
|
||||
videoHide.style.display = "inline";
|
||||
videoContainer.style.display = "block";
|
||||
videoContainer.style.position = "static";
|
||||
video.parentNode.parentNode.removeAttribute('style');
|
||||
thumb.style.display = "none";
|
||||
video.style.position = "static";
|
||||
video.style.pointerEvents = "inherit";
|
||||
video.style.display = "inline";
|
||||
videoHide.style.display = "inline";
|
||||
videoContainer.style.display = "block";
|
||||
videoContainer.style.position = "static";
|
||||
video.parentNode.parentNode.removeAttribute('style');
|
||||
thumb.style.display = "none";
|
||||
|
||||
video.muted = (setting("videovolume") == 0);
|
||||
video.volume = setting("videovolume");
|
||||
video.controls = true;
|
||||
if (video.readyState == 0) {
|
||||
video.addEventListener("loadedmetadata", expand2, false);
|
||||
} else {
|
||||
setTimeout(expand2, 0);
|
||||
}
|
||||
video.play();
|
||||
e.preventDefault();
|
||||
}
|
||||
}, false);
|
||||
video.muted = (setting("videovolume") == 0);
|
||||
video.volume = setting("videovolume");
|
||||
video.controls = true;
|
||||
if (video.readyState == 0) {
|
||||
video.addEventListener("loadedmetadata", expand2, false);
|
||||
} else {
|
||||
setTimeout(expand2, 0);
|
||||
}
|
||||
video.play();
|
||||
e.preventDefault();
|
||||
}
|
||||
}, false);
|
||||
|
||||
function expand2() {
|
||||
video.style.maxWidth = "100%";
|
||||
video.style.maxHeight = window.innerHeight + "px";
|
||||
var bottom = video.getBoundingClientRect().bottom;
|
||||
if (bottom > window.innerHeight) {
|
||||
window.scrollBy(0, bottom - window.innerHeight);
|
||||
}
|
||||
// work around Firefox volume control bug
|
||||
video.volume = Math.max(setting("videovolume") - 0.001, 0);
|
||||
video.volume = setting("videovolume");
|
||||
}
|
||||
function expand2() {
|
||||
video.style.maxWidth = "100%";
|
||||
video.style.maxHeight = window.innerHeight + "px";
|
||||
var bottom = video.getBoundingClientRect().bottom;
|
||||
if (bottom > window.innerHeight) {
|
||||
window.scrollBy(0, bottom - window.innerHeight);
|
||||
}
|
||||
// work around Firefox volume control bug
|
||||
video.volume = Math.max(setting("videovolume") - 0.001, 0);
|
||||
video.volume = setting("videovolume");
|
||||
}
|
||||
|
||||
// Hovering over thumbnail displays video
|
||||
thumb.addEventListener("mouseover", function(e) {
|
||||
if (setting("videohover")) {
|
||||
getVideo();
|
||||
expanded = false;
|
||||
hovering = true;
|
||||
// Hovering over thumbnail displays video
|
||||
thumb.addEventListener("mouseover", function(e) {
|
||||
if (setting("videohover")) {
|
||||
getVideo();
|
||||
expanded = false;
|
||||
hovering = true;
|
||||
|
||||
var docRight = document.documentElement.getBoundingClientRect().right;
|
||||
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
||||
var maxWidth = docRight - thumbRight - 20;
|
||||
if (maxWidth < 250) maxWidth = 250;
|
||||
let docRight = document.documentElement.getBoundingClientRect().right;
|
||||
let thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
||||
let maxWidth = docRight - thumbRight - 20;
|
||||
if (maxWidth < 250) {
|
||||
maxWidth = 250;
|
||||
}
|
||||
|
||||
video.style.position = "fixed";
|
||||
video.style.right = "0px";
|
||||
video.style.top = "0px";
|
||||
var docRight = document.documentElement.getBoundingClientRect().right;
|
||||
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
||||
video.style.maxWidth = maxWidth + "px";
|
||||
video.style.maxHeight = "100%";
|
||||
video.style.pointerEvents = "none";
|
||||
video.style.position = "fixed";
|
||||
video.style.right = "0px";
|
||||
video.style.top = "0px";
|
||||
docRight = document.documentElement.getBoundingClientRect().right;
|
||||
thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
||||
video.style.maxWidth = maxWidth + "px";
|
||||
video.style.maxHeight = "100%";
|
||||
video.style.pointerEvents = "none";
|
||||
|
||||
video.style.display = "inline";
|
||||
videoHide.style.display = "none";
|
||||
videoContainer.style.display = "inline";
|
||||
videoContainer.style.position = "fixed";
|
||||
video.style.display = "inline";
|
||||
videoHide.style.display = "none";
|
||||
videoContainer.style.display = "inline";
|
||||
videoContainer.style.position = "fixed";
|
||||
|
||||
video.muted = (setting("videovolume") == 0);
|
||||
video.volume = setting("videovolume");
|
||||
video.controls = false;
|
||||
video.play();
|
||||
}
|
||||
}, false);
|
||||
video.muted = (setting("videovolume") == 0);
|
||||
video.volume = setting("videovolume");
|
||||
video.controls = false;
|
||||
video.play();
|
||||
}
|
||||
}, false);
|
||||
|
||||
thumb.addEventListener("mouseout", unhover, false);
|
||||
thumb.addEventListener("mouseout", unhover, false);
|
||||
|
||||
// Scroll wheel on thumbnail adjusts default volume
|
||||
thumb.addEventListener("wheel", function(e) {
|
||||
if (setting("videohover")) {
|
||||
var volume = setting("videovolume");
|
||||
if (e.deltaY > 0) volume -= 0.1;
|
||||
if (e.deltaY < 0) volume += 0.1;
|
||||
if (volume < 0) volume = 0;
|
||||
if (volume > 1) volume = 1;
|
||||
if (video != null) {
|
||||
video.muted = (volume == 0);
|
||||
video.volume = volume;
|
||||
}
|
||||
changeSetting("videovolume", volume);
|
||||
e.preventDefault();
|
||||
}
|
||||
}, false);
|
||||
// Scroll wheel on thumbnail adjusts default volume
|
||||
thumb.addEventListener("wheel", function(e) {
|
||||
if (setting("videohover")) {
|
||||
var volume = setting("videovolume");
|
||||
if (e.deltaY > 0) {
|
||||
volume -= 0.1;
|
||||
}
|
||||
if (e.deltaY < 0) {
|
||||
volume += 0.1;
|
||||
}
|
||||
if (volume < 0) {
|
||||
volume = 0;
|
||||
}
|
||||
if (volume > 1) {
|
||||
volume = 1;
|
||||
}
|
||||
if (video != null) {
|
||||
video.muted = (volume == 0);
|
||||
video.volume = volume;
|
||||
}
|
||||
changeSetting("videovolume", volume);
|
||||
e.preventDefault();
|
||||
}
|
||||
}, false);
|
||||
|
||||
// [play once] vs [loop] controls
|
||||
function setupLoopControl(i) {
|
||||
loopControls[i].addEventListener("click", function(e) {
|
||||
loop = (i != 0);
|
||||
thumb.href = thumb.href.replace(/([\?&])loop=\d+/, "$1loop=" + i);
|
||||
if (video != null) {
|
||||
video.loop = loop;
|
||||
if (loop && video.currentTime >= video.duration) {
|
||||
video.currentTime = 0;
|
||||
}
|
||||
}
|
||||
loopControls[i].style.fontWeight = "bold";
|
||||
loopControls[1-i].style.fontWeight = "inherit";
|
||||
}, false);
|
||||
}
|
||||
// [play once] vs [loop] controls
|
||||
function setupLoopControl(i) {
|
||||
loopControls[i].addEventListener("click", function(e) {
|
||||
loop = (i != 0);
|
||||
thumb.href = thumb.href.replace(/([\?&])loop=\d+/, "$1loop=" + i);
|
||||
if (video != null) {
|
||||
video.loop = loop;
|
||||
if (loop && video.currentTime >= video.duration) {
|
||||
video.currentTime = 0;
|
||||
}
|
||||
}
|
||||
loopControls[i].style.fontWeight = "bold";
|
||||
loopControls[1-i].style.fontWeight = "inherit";
|
||||
}, false);
|
||||
}
|
||||
|
||||
loopControls[0].textContent = _("[play once]");
|
||||
loopControls[1].textContent = _("[loop]");
|
||||
loopControls[1].style.fontWeight = "bold";
|
||||
for (var i = 0; i < 2; i++) {
|
||||
setupLoopControl(i);
|
||||
loopControls[i].style.whiteSpace = "nowrap";
|
||||
fileInfo.appendChild(document.createTextNode(" "));
|
||||
fileInfo.appendChild(loopControls[i]);
|
||||
}
|
||||
loopControls[0].textContent = _("[play once]");
|
||||
loopControls[1].textContent = _("[loop]");
|
||||
loopControls[1].style.fontWeight = "bold";
|
||||
for (var i = 0; i < 2; i++) {
|
||||
setupLoopControl(i);
|
||||
loopControls[i].style.whiteSpace = "nowrap";
|
||||
fileInfo.appendChild(document.createTextNode(" "));
|
||||
fileInfo.appendChild(loopControls[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function setupVideosIn(element) {
|
||||
var thumbs = element.querySelectorAll("a.file");
|
||||
for (var i = 0; i < thumbs.length; i++) {
|
||||
if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) {
|
||||
setupVideo(thumbs[i], thumbs[i].href);
|
||||
} else {
|
||||
var m = thumbs[i].search.match(/\bv=([^&]*)/);
|
||||
if (m != null) {
|
||||
var url = decodeURIComponent(m[1]);
|
||||
if (/\.webm$|\.mp4$/.test(url)) setupVideo(thumbs[i], url);
|
||||
}
|
||||
}
|
||||
}
|
||||
let thumbs = element.querySelectorAll("a.file");
|
||||
for (let i = 0; i < thumbs.length; i++) {
|
||||
if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) {
|
||||
setupVideo(thumbs[i], thumbs[i].href);
|
||||
} else {
|
||||
let m = thumbs[i].search.match(/\bv=([^&]*)/);
|
||||
if (m != null) {
|
||||
let url = decodeURIComponent(m[1]);
|
||||
if (/\.webm$|\.mp4$/.test(url)) {
|
||||
setupVideo(thumbs[i], url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onready(function(){
|
||||
// Insert menu from settings.js
|
||||
if (typeof settingsMenu != "undefined" && typeof Options == "undefined")
|
||||
document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]);
|
||||
onReady(function(){
|
||||
// Insert menu from settings.js
|
||||
if (typeof settingsMenu != "undefined" && typeof Options == "undefined") {
|
||||
document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]);
|
||||
}
|
||||
|
||||
// Setup Javascript events for videos in document now
|
||||
setupVideosIn(document);
|
||||
// Setup Javascript events for videos in document now
|
||||
setupVideosIn(document);
|
||||
|
||||
// Setup Javascript events for videos added by updater
|
||||
if (window.MutationObserver) {
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
for (var i = 0; i < mutations.length; i++) {
|
||||
var additions = mutations[i].addedNodes;
|
||||
if (additions == null) continue;
|
||||
for (var j = 0; j < additions.length; j++) {
|
||||
var node = additions[j];
|
||||
if (node.nodeType == 1) {
|
||||
setupVideosIn(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(document.body, {childList: true, subtree: true});
|
||||
}
|
||||
// Setup Javascript events for videos added by updater
|
||||
if (window.MutationObserver) {
|
||||
let observer = new MutationObserver(function(mutations) {
|
||||
for (let i = 0; i < mutations.length; i++) {
|
||||
let additions = mutations[i].addedNodes;
|
||||
if (additions == null) {
|
||||
continue;
|
||||
}
|
||||
for (let j = 0; j < additions.length; j++) {
|
||||
let node = additions[j];
|
||||
if (node.nodeType == 1) {
|
||||
setupVideosIn(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(document.body, {childList: true, subtree: true});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -13,21 +13,21 @@
|
||||
*
|
||||
*/
|
||||
|
||||
onready(function(){
|
||||
var inline_expanding_filename = function() {
|
||||
$(this).find(".fileinfo > a").click(function(){
|
||||
var imagelink = $(this).parent().parent().find('a[target="_blank"]:first');
|
||||
if(imagelink.length > 0) {
|
||||
onReady(function() {
|
||||
let inlineExpandingFilename = function() {
|
||||
$(this).find(".fileinfo > a").click(function() {
|
||||
let imagelink = $(this).parent().parent().find('a[target="_blank"]:first');
|
||||
if (imagelink.length > 0) {
|
||||
imagelink.click();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$('div[id^="thread_"]').each(inline_expanding_filename);
|
||||
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
inline_expanding_filename.call(post);
|
||||
});
|
||||
$('div[id^="thread_"]').each(inlineExpandingFilename);
|
||||
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
inlineExpandingFilename.call(post);
|
||||
});
|
||||
});
|
||||
|
189
js/post-hover.js
189
js/post-hover.js
@ -13,59 +13,62 @@
|
||||
*
|
||||
*/
|
||||
|
||||
onready(function(){
|
||||
var dont_fetch_again = [];
|
||||
init_hover = function() {
|
||||
var $link = $(this);
|
||||
|
||||
var id;
|
||||
var matches;
|
||||
onReady(function() {
|
||||
let dontFetchAgain = [];
|
||||
initHover = function() {
|
||||
let link = $(this);
|
||||
let id;
|
||||
let matches;
|
||||
|
||||
if ($link.is('[data-thread]')) {
|
||||
id = $link.attr('data-thread');
|
||||
}
|
||||
else if(matches = $link.text().match(/^>>(?:>\/([^\/]+)\/)?(\d+)$/)) {
|
||||
if (link.is('[data-thread]')) {
|
||||
id = link.attr('data-thread');
|
||||
} else if (matches = link.text().match(/^>>(?:>\/([^\/]+)\/)?(\d+)$/)) {
|
||||
id = matches[2];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
var board = $(this);
|
||||
|
||||
let board = $(this);
|
||||
while (board.data('board') === undefined) {
|
||||
board = board.parent();
|
||||
}
|
||||
var threadid;
|
||||
if ($link.is('[data-thread]')) threadid = 0;
|
||||
else threadid = board.attr('id').replace("thread_", "");
|
||||
let threadid;
|
||||
if (link.is('[data-thread]')) {
|
||||
threadid = 0;
|
||||
} else {
|
||||
threadid = board.attr('id').replace("thread_", "");
|
||||
}
|
||||
|
||||
board = board.data('board');
|
||||
|
||||
var parentboard = board;
|
||||
|
||||
if ($link.is('[data-thread]')) parentboard = $('form[name="post"] input[name="board"]').val();
|
||||
else if (matches[1] !== undefined) board = matches[1];
|
||||
let parentboard = board;
|
||||
|
||||
var $post = false;
|
||||
var hovering = false;
|
||||
var hovered_at;
|
||||
$link.hover(function(e) {
|
||||
if (link.is('[data-thread]')) {
|
||||
parentboard = $('form[name="post"] input[name="board"]').val();
|
||||
} else if (matches[1] !== undefined) {
|
||||
board = matches[1];
|
||||
}
|
||||
|
||||
let post = false;
|
||||
let hovering = false;
|
||||
let hoveredAt;
|
||||
link.hover(function(e) {
|
||||
hovering = true;
|
||||
hovered_at = {'x': e.pageX, 'y': e.pageY};
|
||||
|
||||
var start_hover = function($link) {
|
||||
if ($post.is(':visible') &&
|
||||
$post.offset().top >= $(window).scrollTop() &&
|
||||
$post.offset().top + $post.height() <= $(window).scrollTop() + $(window).height()) {
|
||||
// post is in view
|
||||
$post.addClass('highlighted');
|
||||
} else {
|
||||
var $newPost = $post.clone();
|
||||
$newPost.find('>.reply, >br').remove();
|
||||
$newPost.find('span.mentioned').remove();
|
||||
$newPost.find('a.post_anchor').remove();
|
||||
hoveredAt = {'x': e.pageX, 'y': e.pageY};
|
||||
|
||||
$newPost
|
||||
let startHover = function(link) {
|
||||
if (post.is(':visible') &&
|
||||
post.offset().top >= $(window).scrollTop() &&
|
||||
post.offset().top + post.height() <= $(window).scrollTop() + $(window).height()) {
|
||||
// post is in view
|
||||
post.addClass('highlighted');
|
||||
} else {
|
||||
let newPost = post.clone();
|
||||
newPost.find('>.reply, >br').remove();
|
||||
newPost.find('span.mentioned').remove();
|
||||
newPost.find('a.post_anchor').remove();
|
||||
|
||||
newPost
|
||||
.attr('id', 'post-hover-' + id)
|
||||
.attr('data-board', board)
|
||||
.addClass('post-hover')
|
||||
@ -76,95 +79,99 @@ onready(function(){
|
||||
.css('font-style', 'normal')
|
||||
.css('z-index', '100')
|
||||
.addClass('reply').addClass('post')
|
||||
.insertAfter($link.parent())
|
||||
.insertAfter(link.parent())
|
||||
|
||||
$link.trigger('mousemove');
|
||||
link.trigger('mousemove');
|
||||
}
|
||||
};
|
||||
|
||||
$post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id);
|
||||
if($post.length > 0) {
|
||||
start_hover($(this));
|
||||
|
||||
post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id);
|
||||
if (post.length > 0) {
|
||||
startHover($(this));
|
||||
} else {
|
||||
var url = $link.attr('href').replace(/#.*$/, '');
|
||||
|
||||
if($.inArray(url, dont_fetch_again) != -1) {
|
||||
let url = link.attr('href').replace(/#.*$/, '');
|
||||
|
||||
if ($.inArray(url, dontFetchAgain) != -1) {
|
||||
return;
|
||||
}
|
||||
dont_fetch_again.push(url);
|
||||
|
||||
dontFetchAgain.push(url);
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
context: document.body,
|
||||
success: function(data) {
|
||||
var mythreadid = $(data).find('div[id^="thread_"]').attr('id').replace("thread_", "");
|
||||
let mythreadid = $(data).find('div[id^="thread_"]').attr('id').replace("thread_", "");
|
||||
|
||||
if (mythreadid == threadid && parentboard == board) {
|
||||
$(data).find('div.post.reply').each(function() {
|
||||
if($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) {
|
||||
if ($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) {
|
||||
$('[data-board="' + board + '"]#thread_' + threadid + " .post.reply:first").before($(this).hide().addClass('hidden'));
|
||||
}
|
||||
});
|
||||
}
|
||||
else if ($('[data-board="' + board + '"]#thread_'+mythreadid).length > 0) {
|
||||
} else if ($('[data-board="' + board + '"]#thread_' + mythreadid).length > 0) {
|
||||
$(data).find('div.post.reply').each(function() {
|
||||
if($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) {
|
||||
if ($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) {
|
||||
$('[data-board="' + board + '"]#thread_' + mythreadid + " .post.reply:first").before($(this).hide().addClass('hidden'));
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$(data).find('div[id^="thread_"]').hide().attr('data-cached', 'yes').prependTo('form[name="postcontrols"]');
|
||||
}
|
||||
|
||||
$post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id);
|
||||
post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id);
|
||||
|
||||
if(hovering && $post.length > 0) {
|
||||
start_hover($link);
|
||||
if (hovering && post.length > 0) {
|
||||
startHover(link);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, function() {
|
||||
hovering = false;
|
||||
if(!$post)
|
||||
if (!post) {
|
||||
return;
|
||||
|
||||
$post.removeClass('highlighted');
|
||||
if($post.hasClass('hidden') || $post.data('cached') == 'yes')
|
||||
$post.css('display', 'none');
|
||||
}
|
||||
|
||||
post.removeClass('highlighted');
|
||||
if (post.hasClass('hidden') || post.data('cached') == 'yes') {
|
||||
post.css('display', 'none');
|
||||
}
|
||||
$('.post-hover').remove();
|
||||
}).mousemove(function(e) {
|
||||
if(!$post)
|
||||
if (!post) {
|
||||
return;
|
||||
|
||||
var $hover = $('#post-hover-' + id + '[data-board="' + board + '"]');
|
||||
if($hover.length == 0)
|
||||
return;
|
||||
|
||||
var scrollTop = $(window).scrollTop();
|
||||
if ($link.is("[data-thread]")) scrollTop = 0;
|
||||
var epy = e.pageY;
|
||||
if ($link.is("[data-thread]")) epy -= $(window).scrollTop();
|
||||
|
||||
var top = (epy ? epy : hovered_at['y']) - 10;
|
||||
|
||||
if(epy < scrollTop + 15) {
|
||||
top = scrollTop;
|
||||
} else if(epy > scrollTop + $(window).height() - $hover.height() - 15) {
|
||||
top = scrollTop + $(window).height() - $hover.height() - 15;
|
||||
}
|
||||
|
||||
|
||||
$hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top);
|
||||
|
||||
let hover = $('#post-hover-' + id + '[data-board="' + board + '"]');
|
||||
if (hover.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let scrollTop = $(window).scrollTop();
|
||||
if (link.is("[data-thread]")) {
|
||||
scrollTop = 0;
|
||||
}
|
||||
let epy = e.pageY;
|
||||
if (link.is("[data-thread]")) {
|
||||
epy -= $(window).scrollTop();
|
||||
}
|
||||
|
||||
let top = (epy ? epy : hoveredAt['y']) - 10;
|
||||
|
||||
if (epy < scrollTop + 15) {
|
||||
top = scrollTop;
|
||||
} else if (epy > scrollTop + $(window).height() - hover.height() - 15) {
|
||||
top = scrollTop + $(window).height() - hover.height() - 15;
|
||||
}
|
||||
|
||||
hover.css('left', (e.pageX ? e.pageX : hoveredAt['x'])).css('top', top);
|
||||
});
|
||||
};
|
||||
|
||||
$('div.body a:not([rel="nofollow"])').each(init_hover);
|
||||
|
||||
|
||||
$('div.body a:not([rel="nofollow"])').each(initHover);
|
||||
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
$(post).find('div.body a:not([rel="nofollow"])').each(init_hover);
|
||||
$(post).find('div.body a:not([rel="nofollow"])').each(initHover);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* Released under the MIT license
|
||||
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
*
|
||||
* Usage:
|
||||
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
||||
@ -13,46 +13,50 @@
|
||||
*
|
||||
*/
|
||||
|
||||
onready(function(){
|
||||
var showBackLinks = function() {
|
||||
var reply_id = $(this).attr('id').replace(/(^reply_)|(^op_)/, '');
|
||||
|
||||
onReady(function() {
|
||||
let showBackLinks = function() {
|
||||
let reply_id = $(this).attr('id').replace(/(^reply_)|(^op_)/, '');
|
||||
|
||||
$(this).find('div.body a:not([rel="nofollow"])').each(function() {
|
||||
var id, post, $mentioned;
|
||||
|
||||
if(id = $(this).text().match(/^>>(\d+)$/))
|
||||
let id, post, $mentioned;
|
||||
|
||||
if (id = $(this).text().match(/^>>(\d+)$/)) {
|
||||
id = id[1];
|
||||
else
|
||||
} else {
|
||||
return;
|
||||
|
||||
$post = $('#reply_' + id);
|
||||
if($post.length == 0){
|
||||
$post = $('#op_' + id);
|
||||
if($post.length == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$post = $('#reply_' + id);
|
||||
if ($post.length == 0){
|
||||
$post = $('#op_' + id);
|
||||
if ($post.length == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$mentioned = $post.find('p.intro span.mentioned');
|
||||
if($mentioned.length == 0)
|
||||
if($mentioned.length == 0) {
|
||||
$mentioned = $('<span class="mentioned unimportant"></span>').appendTo($post.find('p.intro'));
|
||||
|
||||
if ($mentioned.find('a.mentioned-' + reply_id).length != 0)
|
||||
}
|
||||
|
||||
if ($mentioned.find('a.mentioned-' + reply_id).length != 0) {
|
||||
return;
|
||||
|
||||
var $link = $('<a class="mentioned-' + reply_id + '" onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">>>' +
|
||||
}
|
||||
|
||||
let link = $('<a class="mentioned-' + reply_id + '" onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">>>' +
|
||||
reply_id + '</a>');
|
||||
$link.appendTo($mentioned)
|
||||
|
||||
link.appendTo($mentioned)
|
||||
|
||||
if (window.init_hover) {
|
||||
$link.each(init_hover);
|
||||
link.each(init_hover);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$('div.post.reply').each(showBackLinks);
|
||||
$('div.post.op').each(showBackLinks);
|
||||
|
||||
$(document).on('new_post', function(e, post) {
|
||||
$(document).on('new_post', function(e, post) {
|
||||
showBackLinks.call(post);
|
||||
if ($(post).hasClass("op")) {
|
||||
$(post).find('div.post.reply').each(showBackLinks);
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* Released under the MIT license
|
||||
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
*
|
||||
* Usage:
|
||||
* $config['additional_javascript'][] = 'js/mobile-style.js';
|
||||
@ -12,11 +12,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
onready(function(){
|
||||
if(device_type == 'mobile') {
|
||||
var fix_spoilers = function(where) {
|
||||
var spoilers = where.getElementsByClassName('spoiler');
|
||||
for(var i = 0; i < spoilers.length; i++) {
|
||||
onReady(function() {
|
||||
if (device_type == 'mobile') {
|
||||
let fix_spoilers = function(where) {
|
||||
let spoilers = where.getElementsByClassName('spoiler');
|
||||
for (let i = 0; i < spoilers.length; i++) {
|
||||
spoilers[i].onmousedown = function() {
|
||||
this.style.color = 'white';
|
||||
};
|
||||
@ -24,11 +24,10 @@ onready(function(){
|
||||
};
|
||||
fix_spoilers(document);
|
||||
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
fix_spoilers(post);
|
||||
});
|
||||
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
fix_spoilers(post);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Released under the MIT license
|
||||
* Copyright (c) 2013 Michael Save <savetheinternet@tinyboard.org>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
*
|
||||
* Usage:
|
||||
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
||||
@ -14,32 +14,32 @@
|
||||
*
|
||||
*/
|
||||
|
||||
onready(function(){
|
||||
var stylesDiv = $('div.styles');
|
||||
var stylesSelect = $('<select></select>');
|
||||
|
||||
var i = 1;
|
||||
onReady(function() {
|
||||
let stylesDiv = $('div.styles');
|
||||
let stylesSelect = $('<select></select>');
|
||||
|
||||
let i = 1;
|
||||
stylesDiv.children().each(function() {
|
||||
var opt = $('<option></option>')
|
||||
let opt = $('<option></option>')
|
||||
.html(this.innerHTML.replace(/(^\[|\]$)/g, ''))
|
||||
.val(i);
|
||||
if ($(this).hasClass('selected'))
|
||||
if ($(this).hasClass('selected')) {
|
||||
opt.attr('selected', true);
|
||||
}
|
||||
stylesSelect.append(opt);
|
||||
$(this).attr('id', 'style-select-' + i);
|
||||
i++;
|
||||
});
|
||||
|
||||
|
||||
stylesSelect.change(function() {
|
||||
$('#style-select-' + $(this).val()).click();
|
||||
});
|
||||
|
||||
|
||||
stylesDiv.hide();
|
||||
|
||||
|
||||
stylesDiv.after(
|
||||
$('<div id="style-select" style="float:right;margin-bottom:10px"></div>')
|
||||
.text(_('Style: '))
|
||||
.append(stylesSelect)
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
* Released under the MIT license
|
||||
* Copyright (c) 2013 Michael Save <savetheinternet@tinyboard.org>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
||||
*
|
||||
* Usage:
|
||||
* $config['embedding'] = array();
|
||||
@ -22,13 +22,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
onready(function(){
|
||||
var do_embed_yt = function(tag) {
|
||||
onReady(function() {
|
||||
let do_embed_yt = function(tag) {
|
||||
$('div.video-container a', tag).click(function() {
|
||||
var videoID = $(this.parentNode).data('video');
|
||||
|
||||
$(this.parentNode).html('<iframe style="float:left;margin: 10px 20px" type="text/html" '+
|
||||
let videoID = $(this.parentNode).data('video');
|
||||
|
||||
$(this.parentNode).html('<iframe style="float:left;margin: 10px 20px" type="text/html" ' +
|
||||
'width="360" height="270" src="//www.youtube.com/embed/' + videoID +
|
||||
'?autoplay=1&html5=1" allowfullscreen frameborder="0"/>');
|
||||
|
||||
@ -37,9 +36,8 @@ onready(function(){
|
||||
};
|
||||
do_embed_yt(document);
|
||||
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
do_embed_yt(post);
|
||||
});
|
||||
// allow to work with auto-reload.js, etc.
|
||||
$(document).on('new_post', function(e, post) {
|
||||
do_embed_yt(post);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -18,92 +18,92 @@ function _(s) {
|
||||
* > alert(fmt(_("{0} users"), [3]));
|
||||
* 3 uzytkownikow
|
||||
*/
|
||||
function fmt(s,a) {
|
||||
function fmt(s, a) {
|
||||
return s.replace(/\{([0-9]+)\}/g, function(x) { return a[x[1]]; });
|
||||
}
|
||||
|
||||
function until($timestamp) {
|
||||
var $difference = $timestamp - Date.now()/1000|0, $num;
|
||||
switch(true){
|
||||
case ($difference < 60):
|
||||
return "" + $difference + ' ' + _('second(s)');
|
||||
case ($difference < 3600): //60*60 = 3600
|
||||
return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)');
|
||||
case ($difference < 86400): //60*60*24 = 86400
|
||||
return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)');
|
||||
case ($difference < 604800): //60*60*24*7 = 604800
|
||||
return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)');
|
||||
case ($difference < 31536000): //60*60*24*365 = 31536000
|
||||
return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)');
|
||||
default:
|
||||
return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)');
|
||||
}
|
||||
function until(timestamp) {
|
||||
let difference = timestamp - Date.now() / 1000 | 0;
|
||||
switch (true) {
|
||||
case (difference < 60):
|
||||
return "" + difference + ' ' + _('second(s)');
|
||||
case (difference < 3600): // 60 * 60 = 3600
|
||||
return "" + Math.round(difference / 60) + ' ' + _('minute(s)');
|
||||
case (difference < 86400): // 60 * 60 * 24 = 86400
|
||||
return "" + Math.round(difference / 3600) + ' ' + _('hour(s)');
|
||||
case (difference < 604800): // 60 * 60 * 24 * 7 = 604800
|
||||
return "" + Math.round(difference / 86400) + ' ' + _('day(s)');
|
||||
case (difference < 31536000): // 60 * 60 * 24 * 365 = 31536000
|
||||
return "" + Math.round(difference / 604800) + ' ' + _('week(s)');
|
||||
default:
|
||||
return "" + Math.round(difference / 31536000) + ' ' + _('year(s)');
|
||||
}
|
||||
}
|
||||
|
||||
function ago($timestamp) {
|
||||
var $difference = (Date.now()/1000|0) - $timestamp, $num;
|
||||
switch(true){
|
||||
case ($difference < 60) :
|
||||
return "" + $difference + ' ' + _('second(s)');
|
||||
case ($difference < 3600): //60*60 = 3600
|
||||
return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)');
|
||||
case ($difference < 86400): //60*60*24 = 86400
|
||||
return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)');
|
||||
case ($difference < 604800): //60*60*24*7 = 604800
|
||||
return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)');
|
||||
case ($difference < 31536000): //60*60*24*365 = 31536000
|
||||
return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)');
|
||||
default:
|
||||
return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)');
|
||||
}
|
||||
function ago(timestamp) {
|
||||
let difference = (Date.now() / 1000 | 0) - timestamp;
|
||||
switch (true) {
|
||||
case (difference < 60):
|
||||
return "" + difference + ' ' + _('second(s)');
|
||||
case (difference < 3600): /// 60 * 60 = 3600
|
||||
return "" + Math.round(difference/(60)) + ' ' + _('minute(s)');
|
||||
case (difference < 86400): // 60 * 60 * 24 = 86400
|
||||
return "" + Math.round(difference/(3600)) + ' ' + _('hour(s)');
|
||||
case (difference < 604800): // 60 * 60 * 24 * 7 = 604800
|
||||
return "" + Math.round(difference/(86400)) + ' ' + _('day(s)');
|
||||
case (difference < 31536000): // 60 * 60 * 24 * 365 = 31536000
|
||||
return "" + Math.round(difference/(604800)) + ' ' + _('week(s)');
|
||||
default:
|
||||
return "" + Math.round(difference/(31536000)) + ' ' + _('year(s)');
|
||||
}
|
||||
}
|
||||
|
||||
var datelocale =
|
||||
{ days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
|
||||
, shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")]
|
||||
, months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')]
|
||||
, shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')]
|
||||
, AM: _('AM')
|
||||
, PM: _('PM')
|
||||
, am: _('am')
|
||||
, pm: _('pm')
|
||||
};
|
||||
{ days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
|
||||
, shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")]
|
||||
, months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')]
|
||||
, shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')]
|
||||
, AM: _('AM')
|
||||
, PM: _('PM')
|
||||
, am: _('am')
|
||||
, pm: _('pm')
|
||||
};
|
||||
|
||||
|
||||
function alert(a, do_confirm, confirm_ok_action, confirm_cancel_action) {
|
||||
var handler, div, bg, closebtn, okbtn;
|
||||
var close = function() {
|
||||
handler.fadeOut(400, function() { handler.remove(); });
|
||||
return false;
|
||||
};
|
||||
var handler, div, bg, closebtn, okbtn;
|
||||
let close = function() {
|
||||
handler.fadeOut(400, function() { handler.remove(); });
|
||||
return false;
|
||||
};
|
||||
|
||||
handler = $("<div id='alert_handler'></div>").hide().appendTo('body');
|
||||
handler = $("<div id='alert_handler'></div>").hide().appendTo('body');
|
||||
|
||||
bg = $("<div id='alert_background'></div>").appendTo(handler);
|
||||
bg = $("<div id='alert_background'></div>").appendTo(handler);
|
||||
|
||||
div = $("<div id='alert_div'></div>").appendTo(handler);
|
||||
closebtn = $("<a id='alert_close' href='javascript:void(0)'><i class='fa fa-times'></i></div>")
|
||||
.appendTo(div);
|
||||
div = $("<div id='alert_div'></div>").appendTo(handler);
|
||||
closebtn = $("<a id='alert_close' href='javascript:void(0)'><i class='fa fa-times'></i></div>")
|
||||
.appendTo(div);
|
||||
|
||||
$("<div id='alert_message'></div>").html(a).appendTo(div);
|
||||
$("<div id='alert_message'></div>").html(a).appendTo(div);
|
||||
|
||||
okbtn = $("<button class='button alert_button'>"+_("OK")+"</button>").appendTo(div);
|
||||
okbtn = $("<button class='button alert_button'>"+_("OK")+"</button>").appendTo(div);
|
||||
|
||||
if (do_confirm) {
|
||||
confirm_ok_action = (typeof confirm_ok_action !== "function") ? function(){} : confirm_ok_action;
|
||||
confirm_cancel_action = (typeof confirm_cancel_action !== "function") ? function(){} : confirm_cancel_action;
|
||||
okbtn.click(confirm_ok_action);
|
||||
$("<button class='button alert_button'>"+_("Cancel")+"</button>").click(confirm_cancel_action).click(close).appendTo(div);
|
||||
bg.click(confirm_cancel_action);
|
||||
okbtn.click(confirm_cancel_action);
|
||||
closebtn.click(confirm_cancel_action);
|
||||
}
|
||||
if (do_confirm) {
|
||||
confirm_ok_action = (typeof confirm_ok_action !== "function") ? function(){} : confirm_ok_action;
|
||||
confirm_cancel_action = (typeof confirm_cancel_action !== "function") ? function(){} : confirm_cancel_action;
|
||||
okbtn.click(confirm_ok_action);
|
||||
$("<button class='button alert_button'>"+_("Cancel")+"</button>").click(confirm_cancel_action).click(close).appendTo(div);
|
||||
bg.click(confirm_cancel_action);
|
||||
okbtn.click(confirm_cancel_action);
|
||||
closebtn.click(confirm_cancel_action);
|
||||
}
|
||||
|
||||
bg.click(close);
|
||||
okbtn.click(close);
|
||||
closebtn.click(close);
|
||||
bg.click(close);
|
||||
okbtn.click(close);
|
||||
closebtn.click(close);
|
||||
|
||||
handler.fadeIn(400);
|
||||
handler.fadeIn(400);
|
||||
}
|
||||
|
||||
var saved = {};
|
||||
@ -131,7 +131,7 @@ function changeStyle(styleName, link) {
|
||||
localStorage.stylesheet = styleName;
|
||||
{% endif %}
|
||||
{% verbatim %}
|
||||
|
||||
|
||||
if (!document.getElementById('stylesheet')) {
|
||||
var s = document.createElement('link');
|
||||
s.rel = 'stylesheet';
|
||||
@ -140,34 +140,35 @@ function changeStyle(styleName, link) {
|
||||
var x = document.getElementsByTagName('head')[0];
|
||||
x.appendChild(s);
|
||||
}
|
||||
|
||||
|
||||
document.getElementById('stylesheet').href = styles[styleName];
|
||||
selectedstyle = styleName;
|
||||
|
||||
|
||||
if (document.getElementsByClassName('styles').length != 0) {
|
||||
var styleLinks = document.getElementsByClassName('styles')[0].childNodes;
|
||||
for (var i = 0; i < styleLinks.length; i++) {
|
||||
styleLinks[i].className = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (link) {
|
||||
link.className = 'selected';
|
||||
}
|
||||
|
||||
if (typeof $ != 'undefined')
|
||||
|
||||
if (typeof $ != 'undefined') {
|
||||
$(window).trigger('stylesheet', styleName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{% endverbatim %}
|
||||
{% if config.stylesheets_board %}
|
||||
{% verbatim %}
|
||||
|
||||
|
||||
if (!localStorage.board_stylesheets) {
|
||||
localStorage.board_stylesheets = '{}';
|
||||
}
|
||||
|
||||
|
||||
var stylesheet_choices = JSON.parse(localStorage.board_stylesheets);
|
||||
if (board_name && stylesheet_choices[board_name]) {
|
||||
for (var styleName in styles) {
|
||||
@ -192,10 +193,10 @@ function changeStyle(styleName, link) {
|
||||
{% endif %}
|
||||
{% verbatim %}
|
||||
|
||||
function init_stylechooser() {
|
||||
function initStyleChooser() {
|
||||
var newElement = document.createElement('div');
|
||||
newElement.className = 'styles';
|
||||
|
||||
|
||||
for (styleName in styles) {
|
||||
var style = document.createElement('a');
|
||||
style.innerHTML = '[' + styleName + ']';
|
||||
@ -207,17 +208,18 @@ function init_stylechooser() {
|
||||
}
|
||||
style.href = 'javascript:void(0);';
|
||||
newElement.appendChild(style);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling);
|
||||
}
|
||||
|
||||
function get_cookie(cookie_name) {
|
||||
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
|
||||
if (results)
|
||||
return (unescape(results[2]));
|
||||
else
|
||||
function getCookie(cookie_name) {
|
||||
let results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
|
||||
if (results) {
|
||||
return unescape(results[2]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function highlightReply(id) {
|
||||
@ -225,33 +227,35 @@ function highlightReply(id) {
|
||||
// don't highlight on middle click
|
||||
return true;
|
||||
}
|
||||
|
||||
var divs = document.getElementsByTagName('div');
|
||||
|
||||
let divs = document.getElementsByTagName('div');
|
||||
for (var i = 0; i < divs.length; i++)
|
||||
{
|
||||
if (divs[i].className.indexOf('post') != -1)
|
||||
if (divs[i].className.indexOf('post') != -1) {
|
||||
divs[i].className = divs[i].className.replace(/highlighted/, '');
|
||||
}
|
||||
}
|
||||
if (id) {
|
||||
var post = document.getElementById('reply_'+id);
|
||||
if (post)
|
||||
let post = document.getElementById('reply_' + id);
|
||||
if (post) {
|
||||
post.className += ' highlighted';
|
||||
window.location.hash = id;
|
||||
}
|
||||
window.location.hash = id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function generatePassword() {
|
||||
var pass = '';
|
||||
var chars = '{% endverbatim %}{{ config.genpassword_chars }}{% verbatim %}';
|
||||
for (var i = 0; i < 8; i++) {
|
||||
var rnd = Math.floor(Math.random() * chars.length);
|
||||
let pass = '';
|
||||
let chars = '{% endverbatim %}{{ config.genpassword_chars }}{% verbatim %}';
|
||||
for (let i = 0; i < 8; i++) {
|
||||
let rnd = Math.floor(Math.random() * chars.length);
|
||||
pass += chars.substring(rnd, rnd + 1);
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
|
||||
function dopost(form) {
|
||||
function doPost(form) {
|
||||
if (form.elements['name']) {
|
||||
localStorage.name = form.elements['name'].value.replace(/( |^)## .+$/, '');
|
||||
}
|
||||
@ -261,28 +265,29 @@ function dopost(form) {
|
||||
if (form.elements['email'] && form.elements['email'].value != 'sage') {
|
||||
localStorage.email = form.elements['email'].value;
|
||||
}
|
||||
|
||||
|
||||
saved[document.location] = form.elements['body'].value;
|
||||
sessionStorage.body = JSON.stringify(saved);
|
||||
|
||||
|
||||
return form.elements['body'].value != "" || (form.elements['file'] && form.elements['file'].value != "") || (form.elements.file_url && form.elements['file_url'].value != "");
|
||||
}
|
||||
|
||||
function citeReply(id, with_link) {
|
||||
var textarea = document.getElementById('body');
|
||||
let textarea = document.getElementById('body');
|
||||
if (!textarea) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!textarea) return false;
|
||||
|
||||
if (document.selection) {
|
||||
// IE
|
||||
textarea.focus();
|
||||
var sel = document.selection.createRange();
|
||||
let sel = document.selection.createRange();
|
||||
sel.text = '>>' + id + '\n';
|
||||
} else if (textarea.selectionStart || textarea.selectionStart == '0') {
|
||||
var start = textarea.selectionStart;
|
||||
var end = textarea.selectionEnd;
|
||||
let start = textarea.selectionStart;
|
||||
let end = textarea.selectionEnd;
|
||||
textarea.value = textarea.value.substring(0, start) + '>>' + id + '\n' + textarea.value.substring(end, textarea.value.length);
|
||||
|
||||
|
||||
textarea.selectionStart += ('>>' + id).length + 1;
|
||||
textarea.selectionEnd = textarea.selectionStart;
|
||||
} else {
|
||||
@ -290,10 +295,10 @@ function citeReply(id, with_link) {
|
||||
textarea.value += '>>' + id + '\n';
|
||||
}
|
||||
if (typeof $ != 'undefined') {
|
||||
var select = document.getSelection().toString();
|
||||
let select = document.getSelection().toString();
|
||||
if (select) {
|
||||
var body = $('#reply_' + id + ', #op_' + id).find('div.body'); // TODO: support for OPs
|
||||
var index = body.text().indexOf(select.replace('\n', '')); // for some reason this only works like this
|
||||
let body = $('#reply_' + id + ', #op_' + id).find('div.body'); // TODO: support for OPs
|
||||
let index = body.text().indexOf(select.replace('\n', '')); // for some reason this only works like this
|
||||
if (index > -1) {
|
||||
textarea.value += '>' + select + '\n';
|
||||
}
|
||||
@ -308,36 +313,40 @@ function citeReply(id, with_link) {
|
||||
function rememberStuff() {
|
||||
if (document.forms.post) {
|
||||
if (document.forms.post.password) {
|
||||
if (!localStorage.password)
|
||||
if (!localStorage.password) {
|
||||
localStorage.password = generatePassword();
|
||||
}
|
||||
document.forms.post.password.value = localStorage.password;
|
||||
}
|
||||
|
||||
if (localStorage.name && document.forms.post.elements['name'])
|
||||
|
||||
if (localStorage.name && document.forms.post.elements['name']) {
|
||||
document.forms.post.elements['name'].value = localStorage.name;
|
||||
if (localStorage.email && document.forms.post.elements['email'])
|
||||
}
|
||||
if (localStorage.email && document.forms.post.elements['email']) {
|
||||
document.forms.post.elements['email'].value = localStorage.email;
|
||||
|
||||
if (window.location.hash.indexOf('q') == 1)
|
||||
}
|
||||
|
||||
if (window.location.hash.indexOf('q') == 1) {
|
||||
citeReply(window.location.hash.substring(2), true);
|
||||
|
||||
}
|
||||
|
||||
if (sessionStorage.body) {
|
||||
var saved = JSON.parse(sessionStorage.body);
|
||||
if (get_cookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}')) {
|
||||
let saved = JSON.parse(sessionStorage.body);
|
||||
if (getCookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}')) {
|
||||
// Remove successful posts
|
||||
var successful = JSON.parse(get_cookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}'));
|
||||
for (var url in successful) {
|
||||
let successful = JSON.parse(getCookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}'));
|
||||
for (let url in successful) {
|
||||
saved[url] = null;
|
||||
}
|
||||
sessionStorage.body = JSON.stringify(saved);
|
||||
|
||||
|
||||
document.cookie = '{% endverbatim %}{{ config.cookies.js }}{% verbatim %}={};expires=0;path=/;';
|
||||
}
|
||||
if (saved[document.location]) {
|
||||
document.forms.post.body.value = saved[document.location];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (localStorage.body) {
|
||||
document.forms.post.body.value = localStorage.body;
|
||||
localStorage.body = '';
|
||||
@ -350,23 +359,24 @@ var script_settings = function(script_name) {
|
||||
this.get = function(var_name, default_val) {
|
||||
if (typeof tb_settings == 'undefined' ||
|
||||
typeof tb_settings[this.script_name] == 'undefined' ||
|
||||
typeof tb_settings[this.script_name][var_name] == 'undefined')
|
||||
typeof tb_settings[this.script_name][var_name] == 'undefined') {
|
||||
return default_val;
|
||||
}
|
||||
return tb_settings[this.script_name][var_name];
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
init_stylechooser();
|
||||
initStyleChooser();
|
||||
|
||||
{% endverbatim %}
|
||||
{% endverbatim %}
|
||||
{% if config.allow_delete %}
|
||||
if (document.forms.postcontrols) {
|
||||
document.forms.postcontrols.password.value = localStorage.password;
|
||||
}
|
||||
{% endif %}
|
||||
{% verbatim %}
|
||||
|
||||
|
||||
if (window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1))
|
||||
highlightReply(window.location.hash.substring(1));
|
||||
}
|
||||
@ -376,12 +386,12 @@ var RecaptchaOptions = {
|
||||
};
|
||||
|
||||
onready_callbacks = [];
|
||||
function onready(fnc) {
|
||||
function onReady(fnc) {
|
||||
onready_callbacks.push(fnc);
|
||||
}
|
||||
|
||||
function ready() {
|
||||
for (var i = 0; i < onready_callbacks.length; i++) {
|
||||
for (let i = 0; i < onready_callbacks.length; i++) {
|
||||
onready_callbacks[i]();
|
||||
}
|
||||
}
|
||||
@ -391,7 +401,7 @@ function ready() {
|
||||
var post_date = "{{ config.post_date }}";
|
||||
var max_images = {{ config.max_images }};
|
||||
|
||||
onready(init);
|
||||
onReady(init);
|
||||
|
||||
{% if config.google_analytics %}{% verbatim %}
|
||||
|
||||
@ -404,4 +414,3 @@ sc.innerHTML = 'var sc_project={{ config.statcounter_project }};var sc_invisible
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(sc, s);
|
||||
{% endif %}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<form name="post" onsubmit="return dopost(this);" enctype="multipart/form-data" action="{{ config.post_url }}" method="post">
|
||||
<form name="post" onsubmit="return doPost(this);" enctype="multipart/form-data" action="{{ config.post_url }}" method="post">
|
||||
{{ antibot.html() }}
|
||||
{% if id %}<input type="hidden" name="thread" value="{{ id }}">{% endif %}
|
||||
{{ antibot.html() }}
|
||||
@ -112,7 +112,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% elseif config.new_thread_capt %}
|
||||
{% if not id %}
|
||||
{% if not id %}
|
||||
<tr class='captcha'>
|
||||
<th>
|
||||
{% trans %}Verification{% endtrans %}
|
||||
@ -165,7 +165,7 @@
|
||||
|
||||
{% if config.allow_upload_by_url %}
|
||||
<div style="float:none;text-align:left" id="upload_url">
|
||||
<label for="file_url">{% trans %}Or URL{% endtrans %}</label>:
|
||||
<label for="file_url">{% trans %}Or URL{% endtrans %}</label>:
|
||||
<input style="display:inline" type="text" id="file_url" name="file_url" size="35">
|
||||
</div>
|
||||
{% endif %}
|
||||
@ -210,7 +210,7 @@
|
||||
{{ antibot.html() }}
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="password" value="" size="12" maxlength="18" autocomplete="off">
|
||||
<input type="text" name="password" value="" size="12" maxlength="18" autocomplete="off">
|
||||
<span class="unimportant">{% trans %}(For file deletion.){% endtrans %}</span>
|
||||
{{ antibot.html() }}
|
||||
</td>
|
||||
@ -221,7 +221,7 @@
|
||||
{{ antibot.html() }}
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="simple_spam" value="" size="12" maxlength="18" autocomplete="off">
|
||||
<input type="text" name="simple_spam" value="" size="12" maxlength="18" autocomplete="off">
|
||||
{{ antibot.html() }}
|
||||
</td>
|
||||
</tr>{% endif %}
|
||||
|
@ -80,7 +80,7 @@
|
||||
{% endverbatim %}
|
||||
{% for name, uri in config.stylesheets %}{% verbatim %}'{% endverbatim %}{{ name|addslashes }}{% verbatim %}' : '{% endverbatim %}/stylesheets/{{ uri|addslashes }}{% verbatim %}',
|
||||
{% endverbatim %}{% endfor %}{% verbatim %}
|
||||
}; onready(init);
|
||||
}; onReady(init);
|
||||
{% endverbatim %}</script>
|
||||
|
||||
<script type="text/javascript">{% verbatim %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user