diff --git a/js/catalog-search.js b/js/catalog-search.js index ff9af785..a5405bc3 100644 --- a/js/catalog-search.js +++ b/js/catalog-search.js @@ -2,27 +2,27 @@ * catalog-search.js * - Search and filters threads when on catalog view * - Optional shortcuts 's' and 'esc' to open and close the search. - * + * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/comment-toolbar.js'; */ if (active_page == 'catalog') { - onready(function () { + onReady(function() { 'use strict'; - // 'true' = enable shortcuts - var useKeybinds = true; + // 'true' = enable shortcuts + let useKeybinds = true; - // trigger the search 400ms after last keystroke - var delay = 400; - var timeoutHandle; + // trigger the search 400ms after last keystroke + let delay = 400; + let timeoutHandle; - //search and hide none matching threads + // search and hide none matching threads function filter(search_term) { $('.replies').each(function () { - var subject = $(this).children('.intro').text().toLowerCase(); - var comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase(); + let subject = $(this).children('.intro').text().toLowerCase(); + let comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase(); search_term = search_term.toLowerCase(); if (subject.indexOf(search_term) == -1 && comment.indexOf(search_term) == -1) { @@ -34,7 +34,7 @@ if (active_page == 'catalog') { } function searchToggle() { - var button = $('#catalog_search_button'); + let button = $('#catalog_search_button'); if (!button.data('expanded')) { button.data('expanded', '1'); @@ -59,18 +59,18 @@ if (active_page == 'catalog') { }); if (useKeybinds) { - // 's' + // 's' $('body').on('keydown', function (e) { if (e.which === 83 && e.target.tagName === 'BODY' && !(e.ctrlKey || e.altKey || e.shiftKey)) { e.preventDefault(); - if ($('#search_field').length !== 0) { + if ($('#search_field').length !== 0) { $('#search_field').focus(); } else { searchToggle(); } } }); - // 'esc' + // 'esc' $('.catalog_search').on('keydown', 'input#search_field', function (e) { if (e.which === 27 && !(e.ctrlKey || e.altKey || e.shiftKey)) { window.clearTimeout(timeoutHandle); diff --git a/js/download-original.js b/js/download-original.js index cf9635ac..7c0050a0 100644 --- a/js/download-original.js +++ b/js/download-original.js @@ -15,16 +15,16 @@ * */ -onready(function(){ - var do_original_filename = function() { - var filename, truncated; +onReady(function() { + let doOriginalFilename = function() { + let filename, truncated; if ($(this).attr('title')) { filename = $(this).attr('title'); truncated = true; } else { filename = $(this).text(); } - + $(this).replaceWith( $('') .attr('download', filename) @@ -34,9 +34,9 @@ onready(function(){ ); }; - $('.postfilename').each(do_original_filename); + $('.postfilename').each(doOriginalFilename); - $(document).on('new_post', function(e, post) { - $(post).find('.postfilename').each(do_original_filename); + $(document).on('new_post', function(e, post) { + $(post).find('.postfilename').each(doOriginalFilename); }); }); diff --git a/js/expand-all-images.js b/js/expand-all-images.js index c110f51c..e313f9bd 100644 --- a/js/expand-all-images.js +++ b/js/expand-all-images.js @@ -16,37 +16,42 @@ * */ -if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index') -onready(function(){ - $('hr:first').before('
'); - $('div#expand-all-images a') - .text(_('Expand all images')) - .click(function() { - $('a img.post-image').each(function() { - // Don't expand YouTube embeds - if ($(this).parent().parent().hasClass('video-container')) - return; +if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index') { + onReady(function() { + $('hr:first').before('
'); + $('div#expand-all-images a') + .text(_('Expand all images')) + .click(function() { + $('a img.post-image').each(function() { + // Don't expand YouTube embeds + if ($(this).parent().parent().hasClass('video-container')) { + return; + } - // or WEBM - if (/^\/player\.php\?/.test($(this).parent().attr('href'))) - return; + // or WEBM + if (/^\/player\.php\?/.test($(this).parent().attr('href'))) { + return; + } - if (!$(this).parent().data('expanded')) - $(this).parent().click(); - }); - - if (!$('#shrink-all-images').length) { - $('hr:first').before('
'); - } - - $('div#shrink-all-images a') - .text(_('Shrink all images')) - .click(function(){ - $('a img.full-image').each(function() { - if ($(this).parent().data('expanded')) - $(this).parent().click(); - }); - $(this).parent().remove(); + if (!$(this).parent().data('expanded')) { + $(this).parent().click(); + } }); - }); -}); + + if (!$('#shrink-all-images').length) { + $('hr:first').before('
'); + } + + $('div#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(); + }); + }); + }); +} \ No newline at end of file diff --git a/js/expand-video.js b/js/expand-video.js index 08b474c1..3aa88a2c 100644 --- a/js/expand-video.js +++ b/js/expand-video.js @@ -2,243 +2,265 @@ /* Note: This code expects the global variable configRoot to be set. */ if (typeof _ == 'undefined') { - var _ = function(a) { return a; }; + var _ = function(a) { + return a; + }; } function setupVideo(thumb, url) { - if (thumb.videoAlreadySetUp) return; - thumb.videoAlreadySetUp = true; + if (thumb.videoAlreadySetUp) { + return; + } + thumb.videoAlreadySetUp = true; - var video = null; - var videoContainer, videoHide; - var expanded = false; - var hovering = false; - var loop = true; - var loopControls = [document.createElement("span"), document.createElement("span")]; - var fileInfo = thumb.parentNode.querySelector(".fileinfo"); - var mouseDown = false; + let video = null; + let videoContainer, videoHide; + let expanded = false; + let hovering = false; + let loop = true; + let loopControls = [document.createElement("span"), document.createElement("span")]; + let fileInfo = thumb.parentNode.querySelector(".fileinfo"); + let mouseDown = false; - function unexpand() { - if (expanded) { - expanded = false; - if (video.pause) video.pause(); - videoContainer.style.display = "none"; - thumb.style.display = "inline"; - video.style.maxWidth = "inherit"; - video.style.maxHeight = "inherit"; - } - } + function unexpand() { + if (expanded) { + expanded = false; + if (video.pause) { + video.pause(); + } + videoContainer.style.display = "none"; + thumb.style.display = "inline"; + video.style.maxWidth = "inherit"; + video.style.maxHeight = "inherit"; + } + } - function unhover() { - if (hovering) { - hovering = false; - if (video.pause) video.pause(); - videoContainer.style.display = "none"; - video.style.maxWidth = "inherit"; - video.style.maxHeight = "inherit"; - } - } + function unhover() { + if (hovering) { + hovering = false; + if (video.pause) { + video.pause(); + } + videoContainer.style.display = "none"; + video.style.maxWidth = "inherit"; + video.style.maxHeight = "inherit"; + } + } - // Create video element if does not exist yet - function getVideo() { - if (video == null) { - video = document.createElement("video"); - video.src = url; - video.loop = loop; - video.innerText = _("Your browser does not support HTML5 video."); + // Create video element if does not exist yet + function getVideo() { + if (video == null) { + video = document.createElement("video"); + video.src = url; + video.loop = loop; + video.innerText = _("Your browser does not support HTML5 video."); - videoHide = document.createElement("img"); - videoHide.src = configRoot + "static/collapse.gif"; - videoHide.alt = "[ - ]"; - videoHide.title = "Collapse video"; - videoHide.style.marginLeft = "-15px"; - videoHide.style.cssFloat = "left"; - videoHide.addEventListener("click", unexpand, false); + videoHide = document.createElement("img"); + videoHide.src = configRoot + "static/collapse.gif"; + videoHide.alt = "[ - ]"; + videoHide.title = "Collapse video"; + videoHide.style.marginLeft = "-15px"; + videoHide.style.cssFloat = "left"; + videoHide.addEventListener("click", unexpand, false); - videoContainer = document.createElement("div"); - videoContainer.style.paddingLeft = "15px"; - videoContainer.style.display = "none"; - videoContainer.appendChild(videoHide); - videoContainer.appendChild(video); - thumb.parentNode.insertBefore(videoContainer, thumb.nextSibling); + videoContainer = document.createElement("div"); + videoContainer.style.paddingLeft = "15px"; + videoContainer.style.display = "none"; + videoContainer.appendChild(videoHide); + videoContainer.appendChild(video); + thumb.parentNode.insertBefore(videoContainer, thumb.nextSibling); - // Dragging to the left collapses the video - video.addEventListener("mousedown", function(e) { - if (e.button == 0) mouseDown = true; - }, false); - video.addEventListener("mouseup", function(e) { - if (e.button == 0) mouseDown = false; - }, false); - video.addEventListener("mouseenter", function(e) { - mouseDown = false; - }, false); - video.addEventListener("mouseout", function(e) { - if (mouseDown && e.clientX - video.getBoundingClientRect().left <= 0) { - unexpand(); - } - mouseDown = false; - }, false); - } - } + // Dragging to the left collapses the video + video.addEventListener("mousedown", function(e) { + if (e.button == 0) mouseDown = true; + }, false); + video.addEventListener("mouseup", function(e) { + if (e.button == 0) mouseDown = false; + }, false); + video.addEventListener("mouseenter", function(e) { + mouseDown = false; + }, false); + video.addEventListener("mouseout", function(e) { + if (mouseDown && e.clientX - video.getBoundingClientRect().left <= 0) { + unexpand(); + } + mouseDown = false; + }, false); + } + } - // Clicking on thumbnail expands video - thumb.addEventListener("click", function(e) { - if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { - getVideo(); - expanded = true; - hovering = false; + // Clicking on thumbnail expands video + thumb.addEventListener("click", function(e) { + if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { + getVideo(); + expanded = true; + hovering = false; - video.style.position = "static"; - video.style.pointerEvents = "inherit"; - video.style.display = "inline"; - videoHide.style.display = "inline"; - videoContainer.style.display = "block"; - videoContainer.style.position = "static"; - video.parentNode.parentNode.removeAttribute('style'); - thumb.style.display = "none"; + video.style.position = "static"; + video.style.pointerEvents = "inherit"; + video.style.display = "inline"; + videoHide.style.display = "inline"; + videoContainer.style.display = "block"; + videoContainer.style.position = "static"; + video.parentNode.parentNode.removeAttribute('style'); + thumb.style.display = "none"; - video.muted = (setting("videovolume") == 0); - video.volume = setting("videovolume"); - video.controls = true; - if (video.readyState == 0) { - video.addEventListener("loadedmetadata", expand2, false); - } else { - setTimeout(expand2, 0); - } - video.play(); - e.preventDefault(); - } - }, false); + video.muted = (setting("videovolume") == 0); + video.volume = setting("videovolume"); + video.controls = true; + if (video.readyState == 0) { + video.addEventListener("loadedmetadata", expand2, false); + } else { + setTimeout(expand2, 0); + } + video.play(); + e.preventDefault(); + } + }, false); - function expand2() { - video.style.maxWidth = "100%"; - video.style.maxHeight = window.innerHeight + "px"; - var bottom = video.getBoundingClientRect().bottom; - if (bottom > window.innerHeight) { - window.scrollBy(0, bottom - window.innerHeight); - } - // work around Firefox volume control bug - video.volume = Math.max(setting("videovolume") - 0.001, 0); - video.volume = setting("videovolume"); - } + function expand2() { + video.style.maxWidth = "100%"; + video.style.maxHeight = window.innerHeight + "px"; + var bottom = video.getBoundingClientRect().bottom; + if (bottom > window.innerHeight) { + window.scrollBy(0, bottom - window.innerHeight); + } + // work around Firefox volume control bug + video.volume = Math.max(setting("videovolume") - 0.001, 0); + video.volume = setting("videovolume"); + } - // Hovering over thumbnail displays video - thumb.addEventListener("mouseover", function(e) { - if (setting("videohover")) { - getVideo(); - expanded = false; - hovering = true; + // Hovering over thumbnail displays video + thumb.addEventListener("mouseover", function(e) { + if (setting("videohover")) { + getVideo(); + expanded = false; + hovering = true; - var docRight = document.documentElement.getBoundingClientRect().right; - var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right; - var maxWidth = docRight - thumbRight - 20; - if (maxWidth < 250) maxWidth = 250; + let docRight = document.documentElement.getBoundingClientRect().right; + let thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right; + let maxWidth = docRight - thumbRight - 20; + if (maxWidth < 250) { + maxWidth = 250; + } - video.style.position = "fixed"; - video.style.right = "0px"; - video.style.top = "0px"; - var docRight = document.documentElement.getBoundingClientRect().right; - var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right; - video.style.maxWidth = maxWidth + "px"; - video.style.maxHeight = "100%"; - video.style.pointerEvents = "none"; + video.style.position = "fixed"; + video.style.right = "0px"; + video.style.top = "0px"; + docRight = document.documentElement.getBoundingClientRect().right; + thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right; + video.style.maxWidth = maxWidth + "px"; + video.style.maxHeight = "100%"; + video.style.pointerEvents = "none"; - video.style.display = "inline"; - videoHide.style.display = "none"; - videoContainer.style.display = "inline"; - videoContainer.style.position = "fixed"; + video.style.display = "inline"; + videoHide.style.display = "none"; + videoContainer.style.display = "inline"; + videoContainer.style.position = "fixed"; - video.muted = (setting("videovolume") == 0); - video.volume = setting("videovolume"); - video.controls = false; - video.play(); - } - }, false); + video.muted = (setting("videovolume") == 0); + video.volume = setting("videovolume"); + video.controls = false; + video.play(); + } + }, false); - thumb.addEventListener("mouseout", unhover, false); + thumb.addEventListener("mouseout", unhover, false); - // Scroll wheel on thumbnail adjusts default volume - thumb.addEventListener("wheel", function(e) { - if (setting("videohover")) { - var volume = setting("videovolume"); - if (e.deltaY > 0) volume -= 0.1; - if (e.deltaY < 0) volume += 0.1; - if (volume < 0) volume = 0; - if (volume > 1) volume = 1; - if (video != null) { - video.muted = (volume == 0); - video.volume = volume; - } - changeSetting("videovolume", volume); - e.preventDefault(); - } - }, false); + // Scroll wheel on thumbnail adjusts default volume + thumb.addEventListener("wheel", function(e) { + if (setting("videohover")) { + var volume = setting("videovolume"); + if (e.deltaY > 0) { + volume -= 0.1; + } + if (e.deltaY < 0) { + volume += 0.1; + } + if (volume < 0) { + volume = 0; + } + if (volume > 1) { + volume = 1; + } + if (video != null) { + video.muted = (volume == 0); + video.volume = volume; + } + changeSetting("videovolume", volume); + e.preventDefault(); + } + }, false); - // [play once] vs [loop] controls - function setupLoopControl(i) { - loopControls[i].addEventListener("click", function(e) { - loop = (i != 0); - thumb.href = thumb.href.replace(/([\?&])loop=\d+/, "$1loop=" + i); - if (video != null) { - video.loop = loop; - if (loop && video.currentTime >= video.duration) { - video.currentTime = 0; - } - } - loopControls[i].style.fontWeight = "bold"; - loopControls[1-i].style.fontWeight = "inherit"; - }, false); - } + // [play once] vs [loop] controls + function setupLoopControl(i) { + loopControls[i].addEventListener("click", function(e) { + loop = (i != 0); + thumb.href = thumb.href.replace(/([\?&])loop=\d+/, "$1loop=" + i); + if (video != null) { + video.loop = loop; + if (loop && video.currentTime >= video.duration) { + video.currentTime = 0; + } + } + loopControls[i].style.fontWeight = "bold"; + loopControls[1-i].style.fontWeight = "inherit"; + }, false); + } - loopControls[0].textContent = _("[play once]"); - loopControls[1].textContent = _("[loop]"); - loopControls[1].style.fontWeight = "bold"; - for (var i = 0; i < 2; i++) { - setupLoopControl(i); - loopControls[i].style.whiteSpace = "nowrap"; - fileInfo.appendChild(document.createTextNode(" ")); - fileInfo.appendChild(loopControls[i]); - } + loopControls[0].textContent = _("[play once]"); + loopControls[1].textContent = _("[loop]"); + loopControls[1].style.fontWeight = "bold"; + for (var i = 0; i < 2; i++) { + setupLoopControl(i); + loopControls[i].style.whiteSpace = "nowrap"; + fileInfo.appendChild(document.createTextNode(" ")); + fileInfo.appendChild(loopControls[i]); + } } function setupVideosIn(element) { - var thumbs = element.querySelectorAll("a.file"); - for (var i = 0; i < thumbs.length; i++) { - if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) { - setupVideo(thumbs[i], thumbs[i].href); - } else { - var m = thumbs[i].search.match(/\bv=([^&]*)/); - if (m != null) { - var url = decodeURIComponent(m[1]); - if (/\.webm$|\.mp4$/.test(url)) setupVideo(thumbs[i], url); - } - } - } + let thumbs = element.querySelectorAll("a.file"); + for (let i = 0; i < thumbs.length; i++) { + if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) { + setupVideo(thumbs[i], thumbs[i].href); + } else { + let m = thumbs[i].search.match(/\bv=([^&]*)/); + if (m != null) { + let url = decodeURIComponent(m[1]); + if (/\.webm$|\.mp4$/.test(url)) { + setupVideo(thumbs[i], url); + } + } + } + } } -onready(function(){ - // Insert menu from settings.js - if (typeof settingsMenu != "undefined" && typeof Options == "undefined") - document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]); +onReady(function(){ + // Insert menu from settings.js + if (typeof settingsMenu != "undefined" && typeof Options == "undefined") { + document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]); + } - // Setup Javascript events for videos in document now - setupVideosIn(document); + // Setup Javascript events for videos in document now + setupVideosIn(document); - // Setup Javascript events for videos added by updater - if (window.MutationObserver) { - var observer = new MutationObserver(function(mutations) { - for (var i = 0; i < mutations.length; i++) { - var additions = mutations[i].addedNodes; - if (additions == null) continue; - for (var j = 0; j < additions.length; j++) { - var node = additions[j]; - if (node.nodeType == 1) { - setupVideosIn(node); - } - } - } - }); - observer.observe(document.body, {childList: true, subtree: true}); - } + // Setup Javascript events for videos added by updater + if (window.MutationObserver) { + let observer = new MutationObserver(function(mutations) { + for (let i = 0; i < mutations.length; i++) { + let additions = mutations[i].addedNodes; + if (additions == null) { + continue; + } + for (let j = 0; j < additions.length; j++) { + let node = additions[j]; + if (node.nodeType == 1) { + setupVideosIn(node); + } + } + } + }); + observer.observe(document.body, {childList: true, subtree: true}); + } }); - diff --git a/js/inline-expanding-filename.js b/js/inline-expanding-filename.js index ac79fcf0..c5d325e6 100644 --- a/js/inline-expanding-filename.js +++ b/js/inline-expanding-filename.js @@ -13,21 +13,21 @@ * */ -onready(function(){ - var inline_expanding_filename = function() { - $(this).find(".fileinfo > a").click(function(){ - var imagelink = $(this).parent().parent().find('a[target="_blank"]:first'); - if(imagelink.length > 0) { +onReady(function() { + let inlineExpandingFilename = function() { + $(this).find(".fileinfo > a").click(function() { + let imagelink = $(this).parent().parent().find('a[target="_blank"]:first'); + if (imagelink.length > 0) { imagelink.click(); return false; } }); }; - $('div[id^="thread_"]').each(inline_expanding_filename); - - // allow to work with auto-reload.js, etc. - $(document).on('new_post', function(e, post) { - inline_expanding_filename.call(post); - }); + $('div[id^="thread_"]').each(inlineExpandingFilename); + + // allow to work with auto-reload.js, etc. + $(document).on('new_post', function(e, post) { + inlineExpandingFilename.call(post); + }); }); diff --git a/js/post-hover.js b/js/post-hover.js index 780f8cff..d7970871 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -13,59 +13,62 @@ * */ -onready(function(){ - var dont_fetch_again = []; - init_hover = function() { - var $link = $(this); - - var id; - var matches; +onReady(function() { + let dontFetchAgain = []; + initHover = function() { + let link = $(this); + let id; + let matches; - if ($link.is('[data-thread]')) { - id = $link.attr('data-thread'); - } - else if(matches = $link.text().match(/^>>(?:>\/([^\/]+)\/)?(\d+)$/)) { + if (link.is('[data-thread]')) { + id = link.attr('data-thread'); + } else if (matches = link.text().match(/^>>(?:>\/([^\/]+)\/)?(\d+)$/)) { id = matches[2]; - } - else { + } else { return; } - - var board = $(this); + + let board = $(this); while (board.data('board') === undefined) { board = board.parent(); } - var threadid; - if ($link.is('[data-thread]')) threadid = 0; - else threadid = board.attr('id').replace("thread_", ""); + let threadid; + if (link.is('[data-thread]')) { + threadid = 0; + } else { + threadid = board.attr('id').replace("thread_", ""); + } board = board.data('board'); - var parentboard = board; - - if ($link.is('[data-thread]')) parentboard = $('form[name="post"] input[name="board"]').val(); - else if (matches[1] !== undefined) board = matches[1]; + let parentboard = board; - var $post = false; - var hovering = false; - var hovered_at; - $link.hover(function(e) { + if (link.is('[data-thread]')) { + parentboard = $('form[name="post"] input[name="board"]').val(); + } else if (matches[1] !== undefined) { + board = matches[1]; + } + + let post = false; + let hovering = false; + let hoveredAt; + link.hover(function(e) { hovering = true; - hovered_at = {'x': e.pageX, 'y': e.pageY}; - - var start_hover = function($link) { - if ($post.is(':visible') && - $post.offset().top >= $(window).scrollTop() && - $post.offset().top + $post.height() <= $(window).scrollTop() + $(window).height()) { - // post is in view - $post.addClass('highlighted'); - } else { - var $newPost = $post.clone(); - $newPost.find('>.reply, >br').remove(); - $newPost.find('span.mentioned').remove(); - $newPost.find('a.post_anchor').remove(); + hoveredAt = {'x': e.pageX, 'y': e.pageY}; - $newPost + let startHover = function(link) { + if (post.is(':visible') && + post.offset().top >= $(window).scrollTop() && + post.offset().top + post.height() <= $(window).scrollTop() + $(window).height()) { + // post is in view + post.addClass('highlighted'); + } else { + let newPost = post.clone(); + newPost.find('>.reply, >br').remove(); + newPost.find('span.mentioned').remove(); + newPost.find('a.post_anchor').remove(); + + newPost .attr('id', 'post-hover-' + id) .attr('data-board', board) .addClass('post-hover') @@ -76,95 +79,99 @@ onready(function(){ .css('font-style', 'normal') .css('z-index', '100') .addClass('reply').addClass('post') - .insertAfter($link.parent()) + .insertAfter(link.parent()) - $link.trigger('mousemove'); + link.trigger('mousemove'); } }; - - $post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id); - if($post.length > 0) { - start_hover($(this)); + + post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id); + if (post.length > 0) { + startHover($(this)); } else { - var url = $link.attr('href').replace(/#.*$/, ''); - - if($.inArray(url, dont_fetch_again) != -1) { + let url = link.attr('href').replace(/#.*$/, ''); + + if ($.inArray(url, dontFetchAgain) != -1) { return; } - dont_fetch_again.push(url); - + dontFetchAgain.push(url); + $.ajax({ url: url, context: document.body, success: function(data) { - var mythreadid = $(data).find('div[id^="thread_"]').attr('id').replace("thread_", ""); + let mythreadid = $(data).find('div[id^="thread_"]').attr('id').replace("thread_", ""); if (mythreadid == threadid && parentboard == board) { $(data).find('div.post.reply').each(function() { - if($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) { + if ($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) { $('[data-board="' + board + '"]#thread_' + threadid + " .post.reply:first").before($(this).hide().addClass('hidden')); } }); - } - else if ($('[data-board="' + board + '"]#thread_'+mythreadid).length > 0) { + } else if ($('[data-board="' + board + '"]#thread_' + mythreadid).length > 0) { $(data).find('div.post.reply').each(function() { - if($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) { + if ($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) { $('[data-board="' + board + '"]#thread_' + mythreadid + " .post.reply:first").before($(this).hide().addClass('hidden')); } }); - } - else { + } else { $(data).find('div[id^="thread_"]').hide().attr('data-cached', 'yes').prependTo('form[name="postcontrols"]'); } - $post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id); + post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id); - if(hovering && $post.length > 0) { - start_hover($link); + if (hovering && post.length > 0) { + startHover(link); } } }); } }, function() { hovering = false; - if(!$post) + if (!post) { return; - - $post.removeClass('highlighted'); - if($post.hasClass('hidden') || $post.data('cached') == 'yes') - $post.css('display', 'none'); + } + + post.removeClass('highlighted'); + if (post.hasClass('hidden') || post.data('cached') == 'yes') { + post.css('display', 'none'); + } $('.post-hover').remove(); }).mousemove(function(e) { - if(!$post) + if (!post) { return; - - var $hover = $('#post-hover-' + id + '[data-board="' + board + '"]'); - if($hover.length == 0) - return; - - var scrollTop = $(window).scrollTop(); - if ($link.is("[data-thread]")) scrollTop = 0; - var epy = e.pageY; - if ($link.is("[data-thread]")) epy -= $(window).scrollTop(); - - var top = (epy ? epy : hovered_at['y']) - 10; - - if(epy < scrollTop + 15) { - top = scrollTop; - } else if(epy > scrollTop + $(window).height() - $hover.height() - 15) { - top = scrollTop + $(window).height() - $hover.height() - 15; } - - - $hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top); + + let hover = $('#post-hover-' + id + '[data-board="' + board + '"]'); + if (hover.length == 0) { + return; + } + + let scrollTop = $(window).scrollTop(); + if (link.is("[data-thread]")) { + scrollTop = 0; + } + let epy = e.pageY; + if (link.is("[data-thread]")) { + epy -= $(window).scrollTop(); + } + + let top = (epy ? epy : hoveredAt['y']) - 10; + + if (epy < scrollTop + 15) { + top = scrollTop; + } else if (epy > scrollTop + $(window).height() - hover.height() - 15) { + top = scrollTop + $(window).height() - hover.height() - 15; + } + + hover.css('left', (e.pageX ? e.pageX : hoveredAt['x'])).css('top', top); }); }; - - $('div.body a:not([rel="nofollow"])').each(init_hover); - + + $('div.body a:not([rel="nofollow"])').each(initHover); + // allow to work with auto-reload.js, etc. $(document).on('new_post', function(e, post) { - $(post).find('div.body a:not([rel="nofollow"])').each(init_hover); + $(post).find('div.body a:not([rel="nofollow"])').each(initHover); }); }); - diff --git a/js/show-backlinks.js b/js/show-backlinks.js index fc3125db..19a3d5dd 100644 --- a/js/show-backlinks.js +++ b/js/show-backlinks.js @@ -4,7 +4,7 @@ * * Released under the MIT license * Copyright (c) 2012 Michael Save - * Copyright (c) 2013-2014 Marcin Łabanowski + * Copyright (c) 2013-2014 Marcin Łabanowski * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; @@ -13,46 +13,50 @@ * */ -onready(function(){ - var showBackLinks = function() { - var reply_id = $(this).attr('id').replace(/(^reply_)|(^op_)/, ''); - +onReady(function() { + let showBackLinks = function() { + let reply_id = $(this).attr('id').replace(/(^reply_)|(^op_)/, ''); + $(this).find('div.body a:not([rel="nofollow"])').each(function() { - var id, post, $mentioned; - - if(id = $(this).text().match(/^>>(\d+)$/)) + let id, post, $mentioned; + + if (id = $(this).text().match(/^>>(\d+)$/)) { id = id[1]; - else + } else { return; - - $post = $('#reply_' + id); - if($post.length == 0){ - $post = $('#op_' + id); - if($post.length == 0) - return; } - + + $post = $('#reply_' + id); + if ($post.length == 0){ + $post = $('#op_' + id); + if ($post.length == 0) { + return; + } + } + $mentioned = $post.find('p.intro span.mentioned'); - if($mentioned.length == 0) + if($mentioned.length == 0) { $mentioned = $('').appendTo($post.find('p.intro')); - - if ($mentioned.find('a.mentioned-' + reply_id).length != 0) + } + + if ($mentioned.find('a.mentioned-' + reply_id).length != 0) { return; - - var $link = $('>>' + + } + + let link = $('>>' + reply_id + ''); - $link.appendTo($mentioned) - + link.appendTo($mentioned) + if (window.init_hover) { - $link.each(init_hover); + link.each(init_hover); } }); }; - + $('div.post.reply').each(showBackLinks); $('div.post.op').each(showBackLinks); - $(document).on('new_post', function(e, post) { + $(document).on('new_post', function(e, post) { showBackLinks.call(post); if ($(post).hasClass("op")) { $(post).find('div.post.reply').each(showBackLinks); diff --git a/js/smartphone-spoiler.js b/js/smartphone-spoiler.js index 05273c19..21ba2284 100644 --- a/js/smartphone-spoiler.js +++ b/js/smartphone-spoiler.js @@ -4,7 +4,7 @@ * * Released under the MIT license * Copyright (c) 2012 Michael Save - * Copyright (c) 2013-2014 Marcin Łabanowski + * Copyright (c) 2013-2014 Marcin Łabanowski * * Usage: * $config['additional_javascript'][] = 'js/mobile-style.js'; @@ -12,11 +12,11 @@ * */ -onready(function(){ - if(device_type == 'mobile') { - var fix_spoilers = function(where) { - var spoilers = where.getElementsByClassName('spoiler'); - for(var i = 0; i < spoilers.length; i++) { +onReady(function() { + if (device_type == 'mobile') { + let fix_spoilers = function(where) { + let spoilers = where.getElementsByClassName('spoiler'); + for (let i = 0; i < spoilers.length; i++) { spoilers[i].onmousedown = function() { this.style.color = 'white'; }; @@ -24,11 +24,10 @@ onready(function(){ }; fix_spoilers(document); - // allow to work with auto-reload.js, etc. - $(document).on('new_post', function(e, post) { - fix_spoilers(post); - }); - + // allow to work with auto-reload.js, etc. + $(document).on('new_post', function(e, post) { + fix_spoilers(post); + }); + } }); - diff --git a/js/style-select.js b/js/style-select.js index f0fe3c16..0b6821b8 100644 --- a/js/style-select.js +++ b/js/style-select.js @@ -6,7 +6,7 @@ * * Released under the MIT license * Copyright (c) 2013 Michael Save - * Copyright (c) 2013-2014 Marcin Łabanowski + * Copyright (c) 2013-2014 Marcin Łabanowski * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; @@ -14,32 +14,32 @@ * */ -onready(function(){ - var stylesDiv = $('div.styles'); - var stylesSelect = $(''); - - var i = 1; +onReady(function() { + let stylesDiv = $('div.styles'); + let stylesSelect = $(''); + + let i = 1; stylesDiv.children().each(function() { - var opt = $('') + let opt = $('') .html(this.innerHTML.replace(/(^\[|\]$)/g, '')) .val(i); - if ($(this).hasClass('selected')) + if ($(this).hasClass('selected')) { opt.attr('selected', true); + } stylesSelect.append(opt); $(this).attr('id', 'style-select-' + i); i++; }); - + stylesSelect.change(function() { $('#style-select-' + $(this).val()).click(); }); - + stylesDiv.hide(); - + stylesDiv.after( $('
') .text(_('Style: ')) .append(stylesSelect) ); }); - diff --git a/js/youtube.js b/js/youtube.js index 9fe81b60..5537b931 100644 --- a/js/youtube.js +++ b/js/youtube.js @@ -10,7 +10,7 @@ * * Released under the MIT license * Copyright (c) 2013 Michael Save -* Copyright (c) 2013-2014 Marcin Łabanowski +* Copyright (c) 2013-2014 Marcin Łabanowski * * Usage: * $config['embedding'] = array(); @@ -22,13 +22,12 @@ * */ - -onready(function(){ - var do_embed_yt = function(tag) { +onReady(function() { + let do_embed_yt = function(tag) { $('div.video-container a', tag).click(function() { - var videoID = $(this.parentNode).data('video'); - - $(this.parentNode).html('