Merge pull request #781 from Zankaria/main-js-refactor

Refactor main.js
This commit is contained in:
Lorenzo Yario 2024-08-08 23:41:29 -07:00 committed by GitHub
commit 0fbf2f6f77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 603 additions and 559 deletions

View File

@ -2,27 +2,27 @@
* catalog-search.js * catalog-search.js
* - Search and filters threads when on catalog view * - Search and filters threads when on catalog view
* - Optional shortcuts 's' and 'esc' to open and close the search. * - Optional shortcuts 's' and 'esc' to open and close the search.
* *
* Usage: * Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/comment-toolbar.js'; * $config['additional_javascript'][] = 'js/comment-toolbar.js';
*/ */
if (active_page == 'catalog') { if (active_page == 'catalog') {
onready(function () { onReady(function() {
'use strict'; 'use strict';
// 'true' = enable shortcuts // 'true' = enable shortcuts
var useKeybinds = true; let useKeybinds = true;
// trigger the search 400ms after last keystroke // trigger the search 400ms after last keystroke
var delay = 400; let delay = 400;
var timeoutHandle; let timeoutHandle;
//search and hide none matching threads // search and hide none matching threads
function filter(search_term) { function filter(search_term) {
$('.replies').each(function () { $('.replies').each(function () {
var subject = $(this).children('.intro').text().toLowerCase(); let subject = $(this).children('.intro').text().toLowerCase();
var comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase(); let comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase();
search_term = search_term.toLowerCase(); search_term = search_term.toLowerCase();
if (subject.indexOf(search_term) == -1 && comment.indexOf(search_term) == -1) { if (subject.indexOf(search_term) == -1 && comment.indexOf(search_term) == -1) {
@ -34,7 +34,7 @@ if (active_page == 'catalog') {
} }
function searchToggle() { function searchToggle() {
var button = $('#catalog_search_button'); let button = $('#catalog_search_button');
if (!button.data('expanded')) { if (!button.data('expanded')) {
button.data('expanded', '1'); button.data('expanded', '1');
@ -59,18 +59,18 @@ if (active_page == 'catalog') {
}); });
if (useKeybinds) { if (useKeybinds) {
// 's' // 's'
$('body').on('keydown', function (e) { $('body').on('keydown', function (e) {
if (e.which === 83 && e.target.tagName === 'BODY' && !(e.ctrlKey || e.altKey || e.shiftKey)) { if (e.which === 83 && e.target.tagName === 'BODY' && !(e.ctrlKey || e.altKey || e.shiftKey)) {
e.preventDefault(); e.preventDefault();
if ($('#search_field').length !== 0) { if ($('#search_field').length !== 0) {
$('#search_field').focus(); $('#search_field').focus();
} else { } else {
searchToggle(); searchToggle();
} }
} }
}); });
// 'esc' // 'esc'
$('.catalog_search').on('keydown', 'input#search_field', function (e) { $('.catalog_search').on('keydown', 'input#search_field', function (e) {
if (e.which === 27 && !(e.ctrlKey || e.altKey || e.shiftKey)) { if (e.which === 27 && !(e.ctrlKey || e.altKey || e.shiftKey)) {
window.clearTimeout(timeoutHandle); window.clearTimeout(timeoutHandle);

View File

@ -15,16 +15,16 @@
* *
*/ */
onready(function(){ onReady(function() {
var do_original_filename = function() { let doOriginalFilename = function() {
var filename, truncated; let filename, truncated;
if ($(this).attr('title')) { if ($(this).attr('title')) {
filename = $(this).attr('title'); filename = $(this).attr('title');
truncated = true; truncated = true;
} else { } else {
filename = $(this).text(); filename = $(this).text();
} }
$(this).replaceWith( $(this).replaceWith(
$('<a></a>') $('<a></a>')
.attr('download', filename) .attr('download', filename)
@ -34,9 +34,9 @@ onready(function(){
); );
}; };
$('.postfilename').each(do_original_filename); $('.postfilename').each(doOriginalFilename);
$(document).on('new_post', function(e, post) { $(document).on('new_post', function(e, post) {
$(post).find('.postfilename').each(do_original_filename); $(post).find('.postfilename').each(doOriginalFilename);
}); });
}); });

View File

@ -16,37 +16,42 @@
* *
*/ */
if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index') if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index') {
onready(function(){ onReady(function() {
$('hr:first').before('<div id="expand-all-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)"></a></div>'); $('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') $('div#expand-all-images a')
.text(_('Expand all images')) .text(_('Expand all images'))
.click(function() { .click(function() {
$('a img.post-image').each(function() { $('a img.post-image').each(function() {
// Don't expand YouTube embeds // Don't expand YouTube embeds
if ($(this).parent().parent().hasClass('video-container')) if ($(this).parent().parent().hasClass('video-container')) {
return; return;
}
// or WEBM // or WEBM
if (/^\/player\.php\?/.test($(this).parent().attr('href'))) if (/^\/player\.php\?/.test($(this).parent().attr('href'))) {
return; return;
}
if (!$(this).parent().data('expanded')) if (!$(this).parent().data('expanded')) {
$(this).parent().click(); $(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 (!$('#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();
});
});
});
}

View File

@ -2,243 +2,265 @@
/* Note: This code expects the global variable configRoot to be set. */ /* Note: This code expects the global variable configRoot to be set. */
if (typeof _ == 'undefined') { if (typeof _ == 'undefined') {
var _ = function(a) { return a; }; var _ = function(a) {
return a;
};
} }
function setupVideo(thumb, url) { function setupVideo(thumb, url) {
if (thumb.videoAlreadySetUp) return; if (thumb.videoAlreadySetUp) {
thumb.videoAlreadySetUp = true; return;
}
thumb.videoAlreadySetUp = true;
var video = null; let video = null;
var videoContainer, videoHide; let videoContainer, videoHide;
var expanded = false; let expanded = false;
var hovering = false; let hovering = false;
var loop = true; let loop = true;
var loopControls = [document.createElement("span"), document.createElement("span")]; let loopControls = [document.createElement("span"), document.createElement("span")];
var fileInfo = thumb.parentNode.querySelector(".fileinfo"); let fileInfo = thumb.parentNode.querySelector(".fileinfo");
var mouseDown = false; let mouseDown = false;
function unexpand() { function unexpand() {
if (expanded) { if (expanded) {
expanded = false; expanded = false;
if (video.pause) video.pause(); if (video.pause) {
videoContainer.style.display = "none"; video.pause();
thumb.style.display = "inline"; }
video.style.maxWidth = "inherit"; videoContainer.style.display = "none";
video.style.maxHeight = "inherit"; thumb.style.display = "inline";
} video.style.maxWidth = "inherit";
} video.style.maxHeight = "inherit";
}
}
function unhover() { function unhover() {
if (hovering) { if (hovering) {
hovering = false; hovering = false;
if (video.pause) video.pause(); if (video.pause) {
videoContainer.style.display = "none"; video.pause();
video.style.maxWidth = "inherit"; }
video.style.maxHeight = "inherit"; videoContainer.style.display = "none";
} video.style.maxWidth = "inherit";
} video.style.maxHeight = "inherit";
}
}
// Create video element if does not exist yet // Create video element if does not exist yet
function getVideo() { function getVideo() {
if (video == null) { if (video == null) {
video = document.createElement("video"); video = document.createElement("video");
video.src = url; video.src = url;
video.loop = loop; video.loop = loop;
video.innerText = _("Your browser does not support HTML5 video."); video.innerText = _("Your browser does not support HTML5 video.");
videoHide = document.createElement("img"); videoHide = document.createElement("img");
videoHide.src = configRoot + "static/collapse.gif"; videoHide.src = configRoot + "static/collapse.gif";
videoHide.alt = "[ - ]"; videoHide.alt = "[ - ]";
videoHide.title = "Collapse video"; videoHide.title = "Collapse video";
videoHide.style.marginLeft = "-15px"; videoHide.style.marginLeft = "-15px";
videoHide.style.cssFloat = "left"; videoHide.style.cssFloat = "left";
videoHide.addEventListener("click", unexpand, false); videoHide.addEventListener("click", unexpand, false);
videoContainer = document.createElement("div"); videoContainer = document.createElement("div");
videoContainer.style.paddingLeft = "15px"; videoContainer.style.paddingLeft = "15px";
videoContainer.style.display = "none"; videoContainer.style.display = "none";
videoContainer.appendChild(videoHide); videoContainer.appendChild(videoHide);
videoContainer.appendChild(video); videoContainer.appendChild(video);
thumb.parentNode.insertBefore(videoContainer, thumb.nextSibling); thumb.parentNode.insertBefore(videoContainer, thumb.nextSibling);
// Dragging to the left collapses the video // Dragging to the left collapses the video
video.addEventListener("mousedown", function(e) { video.addEventListener("mousedown", function(e) {
if (e.button == 0) mouseDown = true; if (e.button == 0) mouseDown = true;
}, false); }, false);
video.addEventListener("mouseup", function(e) { video.addEventListener("mouseup", function(e) {
if (e.button == 0) mouseDown = false; if (e.button == 0) mouseDown = false;
}, false); }, false);
video.addEventListener("mouseenter", function(e) { video.addEventListener("mouseenter", function(e) {
mouseDown = false; mouseDown = false;
}, false); }, false);
video.addEventListener("mouseout", function(e) { video.addEventListener("mouseout", function(e) {
if (mouseDown && e.clientX - video.getBoundingClientRect().left <= 0) { if (mouseDown && e.clientX - video.getBoundingClientRect().left <= 0) {
unexpand(); unexpand();
} }
mouseDown = false; mouseDown = false;
}, false); }, false);
} }
} }
// Clicking on thumbnail expands video // Clicking on thumbnail expands video
thumb.addEventListener("click", function(e) { thumb.addEventListener("click", function(e) {
if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
getVideo(); getVideo();
expanded = true; expanded = true;
hovering = false; hovering = false;
video.style.position = "static"; video.style.position = "static";
video.style.pointerEvents = "inherit"; video.style.pointerEvents = "inherit";
video.style.display = "inline"; video.style.display = "inline";
videoHide.style.display = "inline"; videoHide.style.display = "inline";
videoContainer.style.display = "block"; videoContainer.style.display = "block";
videoContainer.style.position = "static"; videoContainer.style.position = "static";
video.parentNode.parentNode.removeAttribute('style'); video.parentNode.parentNode.removeAttribute('style');
thumb.style.display = "none"; thumb.style.display = "none";
video.muted = (setting("videovolume") == 0); video.muted = (setting("videovolume") == 0);
video.volume = setting("videovolume"); video.volume = setting("videovolume");
video.controls = true; video.controls = true;
if (video.readyState == 0) { if (video.readyState == 0) {
video.addEventListener("loadedmetadata", expand2, false); video.addEventListener("loadedmetadata", expand2, false);
} else { } else {
setTimeout(expand2, 0); setTimeout(expand2, 0);
} }
video.play(); video.play();
e.preventDefault(); e.preventDefault();
} }
}, false); }, false);
function expand2() { function expand2() {
video.style.maxWidth = "100%"; video.style.maxWidth = "100%";
video.style.maxHeight = window.innerHeight + "px"; video.style.maxHeight = window.innerHeight + "px";
var bottom = video.getBoundingClientRect().bottom; var bottom = video.getBoundingClientRect().bottom;
if (bottom > window.innerHeight) { if (bottom > window.innerHeight) {
window.scrollBy(0, bottom - window.innerHeight); window.scrollBy(0, bottom - window.innerHeight);
} }
// work around Firefox volume control bug // work around Firefox volume control bug
video.volume = Math.max(setting("videovolume") - 0.001, 0); video.volume = Math.max(setting("videovolume") - 0.001, 0);
video.volume = setting("videovolume"); video.volume = setting("videovolume");
} }
// Hovering over thumbnail displays video // Hovering over thumbnail displays video
thumb.addEventListener("mouseover", function(e) { thumb.addEventListener("mouseover", function(e) {
if (setting("videohover")) { if (setting("videohover")) {
getVideo(); getVideo();
expanded = false; expanded = false;
hovering = true; hovering = true;
var docRight = document.documentElement.getBoundingClientRect().right; let docRight = document.documentElement.getBoundingClientRect().right;
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right; let thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
var maxWidth = docRight - thumbRight - 20; let maxWidth = docRight - thumbRight - 20;
if (maxWidth < 250) maxWidth = 250; if (maxWidth < 250) {
maxWidth = 250;
}
video.style.position = "fixed"; video.style.position = "fixed";
video.style.right = "0px"; video.style.right = "0px";
video.style.top = "0px"; video.style.top = "0px";
var docRight = document.documentElement.getBoundingClientRect().right; docRight = document.documentElement.getBoundingClientRect().right;
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right; thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
video.style.maxWidth = maxWidth + "px"; video.style.maxWidth = maxWidth + "px";
video.style.maxHeight = "100%"; video.style.maxHeight = "100%";
video.style.pointerEvents = "none"; video.style.pointerEvents = "none";
video.style.display = "inline"; video.style.display = "inline";
videoHide.style.display = "none"; videoHide.style.display = "none";
videoContainer.style.display = "inline"; videoContainer.style.display = "inline";
videoContainer.style.position = "fixed"; videoContainer.style.position = "fixed";
video.muted = (setting("videovolume") == 0); video.muted = (setting("videovolume") == 0);
video.volume = setting("videovolume"); video.volume = setting("videovolume");
video.controls = false; video.controls = false;
video.play(); video.play();
} }
}, false); }, false);
thumb.addEventListener("mouseout", unhover, false); thumb.addEventListener("mouseout", unhover, false);
// Scroll wheel on thumbnail adjusts default volume // Scroll wheel on thumbnail adjusts default volume
thumb.addEventListener("wheel", function(e) { thumb.addEventListener("wheel", function(e) {
if (setting("videohover")) { if (setting("videohover")) {
var volume = setting("videovolume"); var volume = setting("videovolume");
if (e.deltaY > 0) volume -= 0.1; if (e.deltaY > 0) {
if (e.deltaY < 0) volume += 0.1; volume -= 0.1;
if (volume < 0) volume = 0; }
if (volume > 1) volume = 1; if (e.deltaY < 0) {
if (video != null) { volume += 0.1;
video.muted = (volume == 0); }
video.volume = volume; if (volume < 0) {
} volume = 0;
changeSetting("videovolume", volume); }
e.preventDefault(); if (volume > 1) {
} volume = 1;
}, false); }
if (video != null) {
video.muted = (volume == 0);
video.volume = volume;
}
changeSetting("videovolume", volume);
e.preventDefault();
}
}, false);
// [play once] vs [loop] controls // [play once] vs [loop] controls
function setupLoopControl(i) { function setupLoopControl(i) {
loopControls[i].addEventListener("click", function(e) { loopControls[i].addEventListener("click", function(e) {
loop = (i != 0); loop = (i != 0);
thumb.href = thumb.href.replace(/([\?&])loop=\d+/, "$1loop=" + i); thumb.href = thumb.href.replace(/([\?&])loop=\d+/, "$1loop=" + i);
if (video != null) { if (video != null) {
video.loop = loop; video.loop = loop;
if (loop && video.currentTime >= video.duration) { if (loop && video.currentTime >= video.duration) {
video.currentTime = 0; video.currentTime = 0;
} }
} }
loopControls[i].style.fontWeight = "bold"; loopControls[i].style.fontWeight = "bold";
loopControls[1-i].style.fontWeight = "inherit"; loopControls[1-i].style.fontWeight = "inherit";
}, false); }, false);
} }
loopControls[0].textContent = _("[play once]"); loopControls[0].textContent = _("[play once]");
loopControls[1].textContent = _("[loop]"); loopControls[1].textContent = _("[loop]");
loopControls[1].style.fontWeight = "bold"; loopControls[1].style.fontWeight = "bold";
for (var i = 0; i < 2; i++) { for (var i = 0; i < 2; i++) {
setupLoopControl(i); setupLoopControl(i);
loopControls[i].style.whiteSpace = "nowrap"; loopControls[i].style.whiteSpace = "nowrap";
fileInfo.appendChild(document.createTextNode(" ")); fileInfo.appendChild(document.createTextNode(" "));
fileInfo.appendChild(loopControls[i]); fileInfo.appendChild(loopControls[i]);
} }
} }
function setupVideosIn(element) { function setupVideosIn(element) {
var thumbs = element.querySelectorAll("a.file"); let thumbs = element.querySelectorAll("a.file");
for (var i = 0; i < thumbs.length; i++) { for (let i = 0; i < thumbs.length; i++) {
if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) { if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) {
setupVideo(thumbs[i], thumbs[i].href); setupVideo(thumbs[i], thumbs[i].href);
} else { } else {
var m = thumbs[i].search.match(/\bv=([^&]*)/); let m = thumbs[i].search.match(/\bv=([^&]*)/);
if (m != null) { if (m != null) {
var url = decodeURIComponent(m[1]); let url = decodeURIComponent(m[1]);
if (/\.webm$|\.mp4$/.test(url)) setupVideo(thumbs[i], url); if (/\.webm$|\.mp4$/.test(url)) {
} setupVideo(thumbs[i], url);
} }
} }
}
}
} }
onready(function(){ onReady(function(){
// Insert menu from settings.js // Insert menu from settings.js
if (typeof settingsMenu != "undefined" && typeof Options == "undefined") if (typeof settingsMenu != "undefined" && typeof Options == "undefined") {
document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]); document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]);
}
// Setup Javascript events for videos in document now // Setup Javascript events for videos in document now
setupVideosIn(document); setupVideosIn(document);
// Setup Javascript events for videos added by updater // Setup Javascript events for videos added by updater
if (window.MutationObserver) { if (window.MutationObserver) {
var observer = new MutationObserver(function(mutations) { let observer = new MutationObserver(function(mutations) {
for (var i = 0; i < mutations.length; i++) { for (let i = 0; i < mutations.length; i++) {
var additions = mutations[i].addedNodes; let additions = mutations[i].addedNodes;
if (additions == null) continue; if (additions == null) {
for (var j = 0; j < additions.length; j++) { continue;
var node = additions[j]; }
if (node.nodeType == 1) { for (let j = 0; j < additions.length; j++) {
setupVideosIn(node); let node = additions[j];
} if (node.nodeType == 1) {
} setupVideosIn(node);
} }
}); }
observer.observe(document.body, {childList: true, subtree: true}); }
} });
observer.observe(document.body, {childList: true, subtree: true});
}
}); });

View File

@ -13,21 +13,21 @@
* *
*/ */
onready(function(){ onReady(function() {
var inline_expanding_filename = function() { let inlineExpandingFilename = function() {
$(this).find(".fileinfo > a").click(function(){ $(this).find(".fileinfo > a").click(function() {
var imagelink = $(this).parent().parent().find('a[target="_blank"]:first'); let imagelink = $(this).parent().parent().find('a[target="_blank"]:first');
if(imagelink.length > 0) { if (imagelink.length > 0) {
imagelink.click(); imagelink.click();
return false; return false;
} }
}); });
}; };
$('div[id^="thread_"]').each(inline_expanding_filename); $('div[id^="thread_"]').each(inlineExpandingFilename);
// allow to work with auto-reload.js, etc. // allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) { $(document).on('new_post', function(e, post) {
inline_expanding_filename.call(post); inlineExpandingFilename.call(post);
}); });
}); });

View File

@ -13,59 +13,62 @@
* *
*/ */
onready(function(){ onReady(function() {
var dont_fetch_again = []; let dontFetchAgain = [];
init_hover = function() { initHover = function() {
var $link = $(this); let link = $(this);
let id;
var id; let matches;
var matches;
if ($link.is('[data-thread]')) { if (link.is('[data-thread]')) {
id = $link.attr('data-thread'); id = link.attr('data-thread');
} } else if (matches = link.text().match(/^>>(?:>\/([^\/]+)\/)?(\d+)$/)) {
else if(matches = $link.text().match(/^>>(?:>\/([^\/]+)\/)?(\d+)$/)) {
id = matches[2]; id = matches[2];
} } else {
else {
return; return;
} }
var board = $(this); let board = $(this);
while (board.data('board') === undefined) { while (board.data('board') === undefined) {
board = board.parent(); board = board.parent();
} }
var threadid; let threadid;
if ($link.is('[data-thread]')) threadid = 0; if (link.is('[data-thread]')) {
else threadid = board.attr('id').replace("thread_", ""); threadid = 0;
} else {
threadid = board.attr('id').replace("thread_", "");
}
board = board.data('board'); board = board.data('board');
var parentboard = board; let parentboard = board;
if ($link.is('[data-thread]')) parentboard = $('form[name="post"] input[name="board"]').val();
else if (matches[1] !== undefined) board = matches[1];
var $post = false; if (link.is('[data-thread]')) {
var hovering = false; parentboard = $('form[name="post"] input[name="board"]').val();
var hovered_at; } else if (matches[1] !== undefined) {
$link.hover(function(e) { board = matches[1];
}
let post = false;
let hovering = false;
let hoveredAt;
link.hover(function(e) {
hovering = true; hovering = true;
hovered_at = {'x': e.pageX, 'y': e.pageY}; hoveredAt = {'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();
$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('id', 'post-hover-' + id)
.attr('data-board', board) .attr('data-board', board)
.addClass('post-hover') .addClass('post-hover')
@ -76,95 +79,99 @@ onready(function(){
.css('font-style', 'normal') .css('font-style', 'normal')
.css('z-index', '100') .css('z-index', '100')
.addClass('reply').addClass('post') .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); post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id);
if($post.length > 0) { if (post.length > 0) {
start_hover($(this)); startHover($(this));
} else { } else {
var url = $link.attr('href').replace(/#.*$/, ''); let url = link.attr('href').replace(/#.*$/, '');
if($.inArray(url, dont_fetch_again) != -1) { if ($.inArray(url, dontFetchAgain) != -1) {
return; return;
} }
dont_fetch_again.push(url); dontFetchAgain.push(url);
$.ajax({ $.ajax({
url: url, url: url,
context: document.body, context: document.body,
success: function(data) { 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) { if (mythreadid == threadid && parentboard == board) {
$(data).find('div.post.reply').each(function() { $(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')); $('[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() { $(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')); $('[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"]'); $(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) { if (hovering && post.length > 0) {
start_hover($link); startHover(link);
} }
} }
}); });
} }
}, function() { }, function() {
hovering = false; hovering = false;
if(!$post) if (!post) {
return; return;
}
$post.removeClass('highlighted');
if($post.hasClass('hidden') || $post.data('cached') == 'yes') post.removeClass('highlighted');
$post.css('display', 'none'); if (post.hasClass('hidden') || post.data('cached') == 'yes') {
post.css('display', 'none');
}
$('.post-hover').remove(); $('.post-hover').remove();
}).mousemove(function(e) { }).mousemove(function(e) {
if(!$post) if (!post) {
return; 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;
} }
let hover = $('#post-hover-' + id + '[data-board="' + board + '"]');
$hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top); 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. // allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) { $(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);
}); });
}); });

View File

@ -4,7 +4,7 @@
* *
* Released under the MIT license * Released under the MIT license
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org> * 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: * Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/jquery.min.js';
@ -13,46 +13,50 @@
* *
*/ */
onready(function(){ onReady(function() {
var showBackLinks = function() { let showBackLinks = function() {
var reply_id = $(this).attr('id').replace(/(^reply_)|(^op_)/, ''); let reply_id = $(this).attr('id').replace(/(^reply_)|(^op_)/, '');
$(this).find('div.body a:not([rel="nofollow"])').each(function() { $(this).find('div.body a:not([rel="nofollow"])').each(function() {
var id, post, $mentioned; let id, post, $mentioned;
if(id = $(this).text().match(/^>>(\d+)$/)) if (id = $(this).text().match(/^>>(\d+)$/)) {
id = id[1]; id = id[1];
else } else {
return; 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'); $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')); $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; return;
}
var $link = $('<a class="mentioned-' + reply_id + '" onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">&gt;&gt;' +
let link = $('<a class="mentioned-' + reply_id + '" onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">&gt;&gt;' +
reply_id + '</a>'); reply_id + '</a>');
$link.appendTo($mentioned) link.appendTo($mentioned)
if (window.init_hover) { if (window.init_hover) {
$link.each(init_hover); link.each(init_hover);
} }
}); });
}; };
$('div.post.reply').each(showBackLinks); $('div.post.reply').each(showBackLinks);
$('div.post.op').each(showBackLinks); $('div.post.op').each(showBackLinks);
$(document).on('new_post', function(e, post) { $(document).on('new_post', function(e, post) {
showBackLinks.call(post); showBackLinks.call(post);
if ($(post).hasClass("op")) { if ($(post).hasClass("op")) {
$(post).find('div.post.reply').each(showBackLinks); $(post).find('div.post.reply').each(showBackLinks);

View File

@ -4,7 +4,7 @@
* *
* Released under the MIT license * Released under the MIT license
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org> * 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: * Usage:
* $config['additional_javascript'][] = 'js/mobile-style.js'; * $config['additional_javascript'][] = 'js/mobile-style.js';
@ -12,11 +12,11 @@
* *
*/ */
onready(function(){ onReady(function() {
if(device_type == 'mobile') { if (device_type == 'mobile') {
var fix_spoilers = function(where) { let fix_spoilers = function(where) {
var spoilers = where.getElementsByClassName('spoiler'); let spoilers = where.getElementsByClassName('spoiler');
for(var i = 0; i < spoilers.length; i++) { for (let i = 0; i < spoilers.length; i++) {
spoilers[i].onmousedown = function() { spoilers[i].onmousedown = function() {
this.style.color = 'white'; this.style.color = 'white';
}; };
@ -24,11 +24,10 @@ onready(function(){
}; };
fix_spoilers(document); fix_spoilers(document);
// allow to work with auto-reload.js, etc. // allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) { $(document).on('new_post', function(e, post) {
fix_spoilers(post); fix_spoilers(post);
}); });
} }
}); });

View File

@ -6,7 +6,7 @@
* *
* Released under the MIT license * Released under the MIT license
* Copyright (c) 2013 Michael Save <savetheinternet@tinyboard.org> * 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: * Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/jquery.min.js';
@ -14,32 +14,32 @@
* *
*/ */
onready(function(){ onReady(function() {
var stylesDiv = $('div.styles'); let stylesDiv = $('div.styles');
var stylesSelect = $('<select></select>'); let stylesSelect = $('<select></select>');
var i = 1; let i = 1;
stylesDiv.children().each(function() { stylesDiv.children().each(function() {
var opt = $('<option></option>') let opt = $('<option></option>')
.html(this.innerHTML.replace(/(^\[|\]$)/g, '')) .html(this.innerHTML.replace(/(^\[|\]$)/g, ''))
.val(i); .val(i);
if ($(this).hasClass('selected')) if ($(this).hasClass('selected')) {
opt.attr('selected', true); opt.attr('selected', true);
}
stylesSelect.append(opt); stylesSelect.append(opt);
$(this).attr('id', 'style-select-' + i); $(this).attr('id', 'style-select-' + i);
i++; i++;
}); });
stylesSelect.change(function() { stylesSelect.change(function() {
$('#style-select-' + $(this).val()).click(); $('#style-select-' + $(this).val()).click();
}); });
stylesDiv.hide(); stylesDiv.hide();
stylesDiv.after( stylesDiv.after(
$('<div id="style-select" style="float:right;margin-bottom:10px"></div>') $('<div id="style-select" style="float:right;margin-bottom:10px"></div>')
.text(_('Style: ')) .text(_('Style: '))
.append(stylesSelect) .append(stylesSelect)
); );
}); });

View File

@ -10,7 +10,7 @@
* *
* Released under the MIT license * Released under the MIT license
* Copyright (c) 2013 Michael Save <savetheinternet@tinyboard.org> * 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: * Usage:
* $config['embedding'] = array(); * $config['embedding'] = array();
@ -22,13 +22,12 @@
* *
*/ */
onReady(function() {
onready(function(){ let do_embed_yt = function(tag) {
var do_embed_yt = function(tag) {
$('div.video-container a', tag).click(function() { $('div.video-container a', tag).click(function() {
var videoID = $(this.parentNode).data('video'); let videoID = $(this.parentNode).data('video');
$(this.parentNode).html('<iframe style="float:left;margin: 10px 20px" type="text/html" '+ $(this.parentNode).html('<iframe style="float:left;margin: 10px 20px" type="text/html" ' +
'width="360" height="270" src="//www.youtube.com/embed/' + videoID + 'width="360" height="270" src="//www.youtube.com/embed/' + videoID +
'?autoplay=1&html5=1" allowfullscreen frameborder="0"/>'); '?autoplay=1&html5=1" allowfullscreen frameborder="0"/>');
@ -37,9 +36,8 @@ onready(function(){
}; };
do_embed_yt(document); do_embed_yt(document);
// allow to work with auto-reload.js, etc. // allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) { $(document).on('new_post', function(e, post) {
do_embed_yt(post); do_embed_yt(post);
}); });
}); });

View File

@ -18,92 +18,92 @@ function _(s) {
* > alert(fmt(_("{0} users"), [3])); * > alert(fmt(_("{0} users"), [3]));
* 3 uzytkownikow * 3 uzytkownikow
*/ */
function fmt(s,a) { function fmt(s, a) {
return s.replace(/\{([0-9]+)\}/g, function(x) { return a[x[1]]; }); return s.replace(/\{([0-9]+)\}/g, function(x) { return a[x[1]]; });
} }
function until($timestamp) { function until(timestamp) {
var $difference = $timestamp - Date.now()/1000|0, $num; let difference = timestamp - Date.now() / 1000 | 0;
switch(true){ switch (true) {
case ($difference < 60): case (difference < 60):
return "" + $difference + ' ' + _('second(s)'); return "" + difference + ' ' + _('second(s)');
case ($difference < 3600): //60*60 = 3600 case (difference < 3600): // 60 * 60 = 3600
return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); return "" + Math.round(difference / 60) + ' ' + _('minute(s)');
case ($difference < 86400): //60*60*24 = 86400 case (difference < 86400): // 60 * 60 * 24 = 86400
return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); return "" + Math.round(difference / 3600) + ' ' + _('hour(s)');
case ($difference < 604800): //60*60*24*7 = 604800 case (difference < 604800): // 60 * 60 * 24 * 7 = 604800
return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); return "" + Math.round(difference / 86400) + ' ' + _('day(s)');
case ($difference < 31536000): //60*60*24*365 = 31536000 case (difference < 31536000): // 60 * 60 * 24 * 365 = 31536000
return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); return "" + Math.round(difference / 604800) + ' ' + _('week(s)');
default: default:
return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); return "" + Math.round(difference / 31536000) + ' ' + _('year(s)');
} }
} }
function ago($timestamp) { function ago(timestamp) {
var $difference = (Date.now()/1000|0) - $timestamp, $num; let difference = (Date.now() / 1000 | 0) - timestamp;
switch(true){ switch (true) {
case ($difference < 60) : case (difference < 60):
return "" + $difference + ' ' + _('second(s)'); return "" + difference + ' ' + _('second(s)');
case ($difference < 3600): //60*60 = 3600 case (difference < 3600): /// 60 * 60 = 3600
return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); return "" + Math.round(difference/(60)) + ' ' + _('minute(s)');
case ($difference < 86400): //60*60*24 = 86400 case (difference < 86400): // 60 * 60 * 24 = 86400
return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); return "" + Math.round(difference/(3600)) + ' ' + _('hour(s)');
case ($difference < 604800): //60*60*24*7 = 604800 case (difference < 604800): // 60 * 60 * 24 * 7 = 604800
return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); return "" + Math.round(difference/(86400)) + ' ' + _('day(s)');
case ($difference < 31536000): //60*60*24*365 = 31536000 case (difference < 31536000): // 60 * 60 * 24 * 365 = 31536000
return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); return "" + Math.round(difference/(604800)) + ' ' + _('week(s)');
default: default:
return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); return "" + Math.round(difference/(31536000)) + ' ' + _('year(s)');
} }
} }
var datelocale = var datelocale =
{ days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] { days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
, shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")] , shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")]
, months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')] , 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')] , shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')]
, AM: _('AM') , AM: _('AM')
, PM: _('PM') , PM: _('PM')
, am: _('am') , am: _('am')
, pm: _('pm') , pm: _('pm')
}; };
function alert(a, do_confirm, confirm_ok_action, confirm_cancel_action) { function alert(a, do_confirm, confirm_ok_action, confirm_cancel_action) {
var handler, div, bg, closebtn, okbtn; var handler, div, bg, closebtn, okbtn;
var close = function() { let close = function() {
handler.fadeOut(400, function() { handler.remove(); }); handler.fadeOut(400, function() { handler.remove(); });
return false; 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); div = $("<div id='alert_div'></div>").appendTo(handler);
closebtn = $("<a id='alert_close' href='javascript:void(0)'><i class='fa fa-times'></i></div>") closebtn = $("<a id='alert_close' href='javascript:void(0)'><i class='fa fa-times'></i></div>")
.appendTo(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) { if (do_confirm) {
confirm_ok_action = (typeof confirm_ok_action !== "function") ? function(){} : confirm_ok_action; confirm_ok_action = (typeof confirm_ok_action !== "function") ? function(){} : confirm_ok_action;
confirm_cancel_action = (typeof confirm_cancel_action !== "function") ? function(){} : confirm_cancel_action; confirm_cancel_action = (typeof confirm_cancel_action !== "function") ? function(){} : confirm_cancel_action;
okbtn.click(confirm_ok_action); okbtn.click(confirm_ok_action);
$("<button class='button alert_button'>"+_("Cancel")+"</button>").click(confirm_cancel_action).click(close).appendTo(div); $("<button class='button alert_button'>"+_("Cancel")+"</button>").click(confirm_cancel_action).click(close).appendTo(div);
bg.click(confirm_cancel_action); bg.click(confirm_cancel_action);
okbtn.click(confirm_cancel_action); okbtn.click(confirm_cancel_action);
closebtn.click(confirm_cancel_action); closebtn.click(confirm_cancel_action);
} }
bg.click(close); bg.click(close);
okbtn.click(close); okbtn.click(close);
closebtn.click(close); closebtn.click(close);
handler.fadeIn(400); handler.fadeIn(400);
} }
var saved = {}; var saved = {};
@ -131,7 +131,7 @@ function changeStyle(styleName, link) {
localStorage.stylesheet = styleName; localStorage.stylesheet = styleName;
{% endif %} {% endif %}
{% verbatim %} {% verbatim %}
if (!document.getElementById('stylesheet')) { if (!document.getElementById('stylesheet')) {
var s = document.createElement('link'); var s = document.createElement('link');
s.rel = 'stylesheet'; s.rel = 'stylesheet';
@ -140,34 +140,35 @@ function changeStyle(styleName, link) {
var x = document.getElementsByTagName('head')[0]; var x = document.getElementsByTagName('head')[0];
x.appendChild(s); x.appendChild(s);
} }
document.getElementById('stylesheet').href = styles[styleName]; document.getElementById('stylesheet').href = styles[styleName];
selectedstyle = styleName; selectedstyle = styleName;
if (document.getElementsByClassName('styles').length != 0) { if (document.getElementsByClassName('styles').length != 0) {
var styleLinks = document.getElementsByClassName('styles')[0].childNodes; var styleLinks = document.getElementsByClassName('styles')[0].childNodes;
for (var i = 0; i < styleLinks.length; i++) { for (var i = 0; i < styleLinks.length; i++) {
styleLinks[i].className = ''; styleLinks[i].className = '';
} }
} }
if (link) { if (link) {
link.className = 'selected'; link.className = 'selected';
} }
if (typeof $ != 'undefined') if (typeof $ != 'undefined') {
$(window).trigger('stylesheet', styleName); $(window).trigger('stylesheet', styleName);
}
} }
{% endverbatim %} {% endverbatim %}
{% if config.stylesheets_board %} {% if config.stylesheets_board %}
{% verbatim %} {% verbatim %}
if (!localStorage.board_stylesheets) { if (!localStorage.board_stylesheets) {
localStorage.board_stylesheets = '{}'; localStorage.board_stylesheets = '{}';
} }
var stylesheet_choices = JSON.parse(localStorage.board_stylesheets); var stylesheet_choices = JSON.parse(localStorage.board_stylesheets);
if (board_name && stylesheet_choices[board_name]) { if (board_name && stylesheet_choices[board_name]) {
for (var styleName in styles) { for (var styleName in styles) {
@ -192,10 +193,10 @@ function changeStyle(styleName, link) {
{% endif %} {% endif %}
{% verbatim %} {% verbatim %}
function init_stylechooser() { function initStyleChooser() {
var newElement = document.createElement('div'); var newElement = document.createElement('div');
newElement.className = 'styles'; newElement.className = 'styles';
for (styleName in styles) { for (styleName in styles) {
var style = document.createElement('a'); var style = document.createElement('a');
style.innerHTML = '[' + styleName + ']'; style.innerHTML = '[' + styleName + ']';
@ -207,17 +208,18 @@ function init_stylechooser() {
} }
style.href = 'javascript:void(0);'; style.href = 'javascript:void(0);';
newElement.appendChild(style); newElement.appendChild(style);
} }
document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling); document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling);
} }
function get_cookie(cookie_name) { function getCookie(cookie_name) {
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); let results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
if (results) if (results) {
return (unescape(results[2])); return unescape(results[2]);
else } else {
return null; return null;
}
} }
function highlightReply(id) { function highlightReply(id) {
@ -225,33 +227,35 @@ function highlightReply(id) {
// don't highlight on middle click // don't highlight on middle click
return true; return true;
} }
var divs = document.getElementsByTagName('div'); let divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) 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/, ''); divs[i].className = divs[i].className.replace(/highlighted/, '');
}
} }
if (id) { if (id) {
var post = document.getElementById('reply_'+id); let post = document.getElementById('reply_' + id);
if (post) if (post) {
post.className += ' highlighted'; post.className += ' highlighted';
window.location.hash = id; }
window.location.hash = id;
} }
return true; return true;
} }
function generatePassword() { function generatePassword() {
var pass = ''; let pass = '';
var chars = '{% endverbatim %}{{ config.genpassword_chars }}{% verbatim %}'; let chars = '{% endverbatim %}{{ config.genpassword_chars }}{% verbatim %}';
for (var i = 0; i < 8; i++) { for (let i = 0; i < 8; i++) {
var rnd = Math.floor(Math.random() * chars.length); let rnd = Math.floor(Math.random() * chars.length);
pass += chars.substring(rnd, rnd + 1); pass += chars.substring(rnd, rnd + 1);
} }
return pass; return pass;
} }
function dopost(form) { function doPost(form) {
if (form.elements['name']) { if (form.elements['name']) {
localStorage.name = form.elements['name'].value.replace(/( |^)## .+$/, ''); localStorage.name = form.elements['name'].value.replace(/( |^)## .+$/, '');
} }
@ -261,28 +265,29 @@ function dopost(form) {
if (form.elements['email'] && form.elements['email'].value != 'sage') { if (form.elements['email'] && form.elements['email'].value != 'sage') {
localStorage.email = form.elements['email'].value; localStorage.email = form.elements['email'].value;
} }
saved[document.location] = form.elements['body'].value; saved[document.location] = form.elements['body'].value;
sessionStorage.body = JSON.stringify(saved); 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 != ""); 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) { 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) { if (document.selection) {
// IE // IE
textarea.focus(); textarea.focus();
var sel = document.selection.createRange(); let sel = document.selection.createRange();
sel.text = '>>' + id + '\n'; sel.text = '>>' + id + '\n';
} else if (textarea.selectionStart || textarea.selectionStart == '0') { } else if (textarea.selectionStart || textarea.selectionStart == '0') {
var start = textarea.selectionStart; let start = textarea.selectionStart;
var end = textarea.selectionEnd; let end = textarea.selectionEnd;
textarea.value = textarea.value.substring(0, start) + '>>' + id + '\n' + textarea.value.substring(end, textarea.value.length); textarea.value = textarea.value.substring(0, start) + '>>' + id + '\n' + textarea.value.substring(end, textarea.value.length);
textarea.selectionStart += ('>>' + id).length + 1; textarea.selectionStart += ('>>' + id).length + 1;
textarea.selectionEnd = textarea.selectionStart; textarea.selectionEnd = textarea.selectionStart;
} else { } else {
@ -290,10 +295,10 @@ function citeReply(id, with_link) {
textarea.value += '>>' + id + '\n'; textarea.value += '>>' + id + '\n';
} }
if (typeof $ != 'undefined') { if (typeof $ != 'undefined') {
var select = document.getSelection().toString(); let select = document.getSelection().toString();
if (select) { if (select) {
var body = $('#reply_' + id + ', #op_' + id).find('div.body'); // TODO: support for OPs let 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 index = body.text().indexOf(select.replace('\n', '')); // for some reason this only works like this
if (index > -1) { if (index > -1) {
textarea.value += '>' + select + '\n'; textarea.value += '>' + select + '\n';
} }
@ -308,36 +313,40 @@ function citeReply(id, with_link) {
function rememberStuff() { function rememberStuff() {
if (document.forms.post) { if (document.forms.post) {
if (document.forms.post.password) { if (document.forms.post.password) {
if (!localStorage.password) if (!localStorage.password) {
localStorage.password = generatePassword(); localStorage.password = generatePassword();
}
document.forms.post.password.value = localStorage.password; 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; 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; 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); citeReply(window.location.hash.substring(2), true);
}
if (sessionStorage.body) { if (sessionStorage.body) {
var saved = JSON.parse(sessionStorage.body); let saved = JSON.parse(sessionStorage.body);
if (get_cookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}')) { if (getCookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}')) {
// Remove successful posts // Remove successful posts
var successful = JSON.parse(get_cookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}')); let successful = JSON.parse(getCookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}'));
for (var url in successful) { for (let url in successful) {
saved[url] = null; saved[url] = null;
} }
sessionStorage.body = JSON.stringify(saved); sessionStorage.body = JSON.stringify(saved);
document.cookie = '{% endverbatim %}{{ config.cookies.js }}{% verbatim %}={};expires=0;path=/;'; document.cookie = '{% endverbatim %}{{ config.cookies.js }}{% verbatim %}={};expires=0;path=/;';
} }
if (saved[document.location]) { if (saved[document.location]) {
document.forms.post.body.value = saved[document.location]; document.forms.post.body.value = saved[document.location];
} }
} }
if (localStorage.body) { if (localStorage.body) {
document.forms.post.body.value = localStorage.body; document.forms.post.body.value = localStorage.body;
localStorage.body = ''; localStorage.body = '';
@ -350,23 +359,24 @@ var script_settings = function(script_name) {
this.get = function(var_name, default_val) { this.get = function(var_name, default_val) {
if (typeof tb_settings == 'undefined' || if (typeof tb_settings == 'undefined' ||
typeof tb_settings[this.script_name] == '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 default_val;
}
return tb_settings[this.script_name][var_name]; return tb_settings[this.script_name][var_name];
} }
}; };
function init() { function init() {
init_stylechooser(); initStyleChooser();
{% endverbatim %} {% endverbatim %}
{% if config.allow_delete %} {% if config.allow_delete %}
if (document.forms.postcontrols) { if (document.forms.postcontrols) {
document.forms.postcontrols.password.value = localStorage.password; document.forms.postcontrols.password.value = localStorage.password;
} }
{% endif %} {% endif %}
{% verbatim %} {% verbatim %}
if (window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1)) if (window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1))
highlightReply(window.location.hash.substring(1)); highlightReply(window.location.hash.substring(1));
} }
@ -376,12 +386,12 @@ var RecaptchaOptions = {
}; };
onready_callbacks = []; onready_callbacks = [];
function onready(fnc) { function onReady(fnc) {
onready_callbacks.push(fnc); onready_callbacks.push(fnc);
} }
function ready() { function ready() {
for (var i = 0; i < onready_callbacks.length; i++) { for (let i = 0; i < onready_callbacks.length; i++) {
onready_callbacks[i](); onready_callbacks[i]();
} }
} }
@ -391,7 +401,7 @@ function ready() {
var post_date = "{{ config.post_date }}"; var post_date = "{{ config.post_date }}";
var max_images = {{ config.max_images }}; var max_images = {{ config.max_images }};
onready(init); onReady(init);
{% if config.google_analytics %}{% verbatim %} {% 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]; var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(sc, s); s.parentNode.insertBefore(sc, s);
{% endif %} {% endif %}

View File

@ -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() }} {{ antibot.html() }}
{% if id %}<input type="hidden" name="thread" value="{{ id }}">{% endif %} {% if id %}<input type="hidden" name="thread" value="{{ id }}">{% endif %}
{{ antibot.html() }} {{ antibot.html() }}
@ -112,7 +112,7 @@
</td> </td>
</tr> </tr>
{% elseif config.new_thread_capt %} {% elseif config.new_thread_capt %}
{% if not id %} {% if not id %}
<tr class='captcha'> <tr class='captcha'>
<th> <th>
{% trans %}Verification{% endtrans %} {% trans %}Verification{% endtrans %}
@ -165,7 +165,7 @@
{% if config.allow_upload_by_url %} {% if config.allow_upload_by_url %}
<div style="float:none;text-align:left" id="upload_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"> <input style="display:inline" type="text" id="file_url" name="file_url" size="35">
</div> </div>
{% endif %} {% endif %}
@ -210,7 +210,7 @@
{{ antibot.html() }} {{ antibot.html() }}
</th> </th>
<td> <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> <span class="unimportant">{% trans %}(For file deletion.){% endtrans %}</span>
{{ antibot.html() }} {{ antibot.html() }}
</td> </td>
@ -221,7 +221,7 @@
{{ antibot.html() }} {{ antibot.html() }}
</th> </th>
<td> <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() }} {{ antibot.html() }}
</td> </td>
</tr>{% endif %} </tr>{% endif %}

View File

@ -80,7 +80,7 @@
{% endverbatim %} {% endverbatim %}
{% for name, uri in config.stylesheets %}{% verbatim %}'{% endverbatim %}{{ name|addslashes }}{% verbatim %}' : '{% endverbatim %}/stylesheets/{{ uri|addslashes }}{% verbatim %}', {% for name, uri in config.stylesheets %}{% verbatim %}'{% endverbatim %}{{ name|addslashes }}{% verbatim %}' : '{% endverbatim %}/stylesheets/{{ uri|addslashes }}{% verbatim %}',
{% endverbatim %}{% endfor %}{% verbatim %} {% endverbatim %}{% endfor %}{% verbatim %}
}; onready(init); }; onReady(init);
{% endverbatim %}</script> {% endverbatim %}</script>
<script type="text/javascript">{% verbatim %} <script type="text/javascript">{% verbatim %}