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

@ -8,21 +8,21 @@
* $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');

View File

@ -15,9 +15,9 @@
* *
*/ */
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;
@ -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,23 +16,26 @@
* *
*/ */
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) { if (!$('#shrink-all-images').length) {
@ -43,10 +46,12 @@ onready(function(){
.text(_('Shrink all images')) .text(_('Shrink all images'))
.click(function() { .click(function() {
$('a img.full-image').each(function() { $('a img.full-image').each(function() {
if ($(this).parent().data('expanded')) if ($(this).parent().data('expanded')) {
$(this).parent().click(); $(this).parent().click();
}
}); });
$(this).parent().remove(); $(this).parent().remove();
}); });
}); });
}); });
}

View File

@ -2,26 +2,32 @@
/* 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) {
return;
}
thumb.videoAlreadySetUp = true; 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) {
video.pause();
}
videoContainer.style.display = "none"; videoContainer.style.display = "none";
thumb.style.display = "inline"; thumb.style.display = "inline";
video.style.maxWidth = "inherit"; video.style.maxWidth = "inherit";
@ -32,7 +38,9 @@ function setupVideo(thumb, url) {
function unhover() { function unhover() {
if (hovering) { if (hovering) {
hovering = false; hovering = false;
if (video.pause) video.pause(); if (video.pause) {
video.pause();
}
videoContainer.style.display = "none"; videoContainer.style.display = "none";
video.style.maxWidth = "inherit"; video.style.maxWidth = "inherit";
video.style.maxHeight = "inherit"; video.style.maxHeight = "inherit";
@ -129,16 +137,18 @@ function setupVideo(thumb, url) {
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";
@ -161,10 +171,18 @@ function setupVideo(thumb, url) {
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) {
volume += 0.1;
}
if (volume < 0) {
volume = 0;
}
if (volume > 1) {
volume = 1;
}
if (video != null) { if (video != null) {
video.muted = (volume == 0); video.muted = (volume == 0);
video.volume = volume; video.volume = volume;
@ -202,36 +220,41 @@ function setupVideo(thumb, url) {
} }
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]; }
for (let j = 0; j < additions.length; j++) {
let node = additions[j];
if (node.nodeType == 1) { if (node.nodeType == 1) {
setupVideosIn(node); setupVideosIn(node);
} }
@ -241,4 +264,3 @@ onready(function(){
observer.observe(document.body, {childList: true, subtree: true}); observer.observe(document.body, {childList: true, subtree: true});
} }
}); });

View File

@ -13,10 +13,10 @@
* *
*/ */
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;
@ -24,10 +24,10 @@ onready(function(){
}); });
}; };
$('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;
let matches;
var id; if (link.is('[data-thread]')) {
var matches; 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]; 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(); if (link.is('[data-thread]')) {
else if (matches[1] !== undefined) board = matches[1]; parentboard = $('form[name="post"] input[name="board"]').val();
} else if (matches[1] !== undefined) {
board = matches[1];
}
var $post = false; let post = false;
var hovering = false; let hovering = false;
var hovered_at; let hoveredAt;
$link.hover(function(e) { 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) { let startHover = function(link) {
if ($post.is(':visible') && if (post.is(':visible') &&
$post.offset().top >= $(window).scrollTop() && post.offset().top >= $(window).scrollTop() &&
$post.offset().top + $post.height() <= $(window).scrollTop() + $(window).height()) { post.offset().top + post.height() <= $(window).scrollTop() + $(window).height()) {
// post is in view // post is in view
$post.addClass('highlighted'); post.addClass('highlighted');
} else { } else {
var $newPost = $post.clone(); let newPost = post.clone();
$newPost.find('>.reply, >br').remove(); newPost.find('>.reply, >br').remove();
$newPost.find('span.mentioned').remove(); newPost.find('span.mentioned').remove();
$newPost.find('a.post_anchor').remove(); newPost.find('a.post_anchor').remove();
$newPost 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,28 +79,28 @@ 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() {
@ -105,66 +108,70 @@ onready(function(){
$('[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'); post.removeClass('highlighted');
if($post.hasClass('hidden') || $post.data('cached') == 'yes') if (post.hasClass('hidden') || post.data('cached') == 'yes') {
$post.css('display', 'none'); 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 + '"]'); let hover = $('#post-hover-' + id + '[data-board="' + board + '"]');
if($hover.length == 0) if (hover.length == 0) {
return; return;
}
var scrollTop = $(window).scrollTop(); let scrollTop = $(window).scrollTop();
if ($link.is("[data-thread]")) scrollTop = 0; if (link.is("[data-thread]")) {
var epy = e.pageY; scrollTop = 0;
if ($link.is("[data-thread]")) epy -= $(window).scrollTop(); }
let epy = e.pageY;
if (link.is("[data-thread]")) {
epy -= $(window).scrollTop();
}
var top = (epy ? epy : hovered_at['y']) - 10; let top = (epy ? epy : hoveredAt['y']) - 10;
if (epy < scrollTop + 15) { if (epy < scrollTop + 15) {
top = scrollTop; top = scrollTop;
} else if(epy > scrollTop + $(window).height() - $hover.height() - 15) { } else if (epy > scrollTop + $(window).height() - hover.height() - 15) {
top = 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);
$hover.css('left', (e.pageX ? e.pageX : hovered_at['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

@ -13,38 +13,42 @@
* *
*/ */
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); $post = $('#reply_' + id);
if ($post.length == 0){ if ($post.length == 0){
$post = $('#op_' + id); $post = $('#op_' + id);
if($post.length == 0) if ($post.length == 0) {
return; 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);
} }
}); });
}; };

View File

@ -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';
}; };
@ -31,4 +31,3 @@ onready(function(){
} }
}); });

View File

@ -14,17 +14,18 @@
* *
*/ */
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++;
@ -42,4 +43,3 @@ onready(function(){
.append(stylesSelect) .append(stylesSelect)
); );
}); });

View File

@ -22,11 +22,10 @@
* *
*/ */
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 +
@ -42,4 +41,3 @@ onready(function(){
do_embed_yt(post); do_embed_yt(post);
}); });
}); });

View File

@ -22,39 +22,39 @@ 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)');
} }
} }
@ -72,7 +72,7 @@ var datelocale =
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;
}; };
@ -155,9 +155,10 @@ function changeStyle(styleName, link) {
link.className = 'selected'; link.className = 'selected';
} }
if (typeof $ != 'undefined') if (typeof $ != 'undefined') {
$(window).trigger('stylesheet', styleName); $(window).trigger('stylesheet', styleName);
} }
}
{% endverbatim %} {% endverbatim %}
@ -192,7 +193,7 @@ 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';
@ -212,13 +213,14 @@ function init_stylechooser() {
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) {
if (typeof window.event != "undefined" && event.which == 2) { if (typeof window.event != "undefined" && event.which == 2) {
@ -226,32 +228,34 @@ function highlightReply(id) {
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(/( |^)## .+$/, '');
} }
@ -269,18 +273,19 @@ function dopost(form) {
} }
function citeReply(id, with_link) { function citeReply(id, with_link) {
var textarea = document.getElementById('body'); let textarea = document.getElementById('body');
if (!textarea) {
if (!textarea) return false; 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;
@ -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,25 +313,29 @@ 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);
@ -350,14 +359,15 @@ 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 %}
@ -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() }}

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 %}