1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-02 12:57:35 +01:00

Merge pull request #873 from Zankaria/cleanup-pre-mobile-ui

Cleanup pre mobile UI
This commit is contained in:
Lorenzo Yario 2025-01-05 02:00:20 -06:00 committed by GitHub
commit f39988229a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 271 additions and 264 deletions

View File

@ -17,38 +17,37 @@
*
* You must have boardlinks or else this script will not load.
* Search for "$config['boards'] = array(" within your inc/config.php and add something similar to your instance-config.php.
*
*/
auto_reload_enabled = true; // for watch.js to interop
auto_reload_enabled = true; // For watch.js to interop.
$(document).ready(function(){
if($('div.banner').length == 0)
return; // not index
if($('div.banner').length == 0) {
// Not index.
return;
}
if($(".post.op").size() != 1)
return; //not thread page
if($(".post.op").size() != 1) {
// Not thread page.
return;
}
var countdown_interval;
// Add an update link
// Add an update link.
$('.boardlist.bottom').prev().after("<span id='updater'><a href='#' id='update_thread' style='padding-left:10px'>["+_("Update")+"]</a> (<input type='checkbox' id='auto_update_status' checked> "+_("Auto")+") <span id='update_secs'></span></span>");
// Grab the settings
// Grab the settings.
var settings = new script_settings('auto-reload');
var poll_interval_mindelay = settings.get('min_delay_bottom', 5000);
var poll_interval_maxdelay = settings.get('max_delay', 600000);
var poll_interval_errordelay = settings.get('error_delay', 30000);
// number of ms to wait before reloading
// number of ms to wait before reloading.
var poll_interval_delay = poll_interval_mindelay;
var poll_current_time = poll_interval_delay;
var end_of_page = false;
var new_posts = 0;
var first_new_post = null;
var title = document.title;
@ -62,17 +61,18 @@ $(document).ready(function(){
};
}
if (typeof add_title_collector != "undefined")
if (typeof add_title_collector != "undefined") {
add_title_collector(function() {
return new_posts;
});
}
var window_active = true;
$(window).focus(function() {
window_active = true;
recheck_activated();
// Reset the delay if needed
// Reset the delay if needed.
if(settings.get('reset_focus', true)) {
poll_interval_delay = poll_interval_mindelay;
}
@ -89,7 +89,6 @@ $(document).ready(function(){
stop_auto_update();
$('#update_secs').text("");
}
});
@ -110,7 +109,6 @@ $(document).ready(function(){
new_posts = 0;
}
update_title();
first_new_post = null;
};
// automatically updates the thread after a specified delay
@ -152,9 +150,6 @@ $(document).ready(function(){
$(data).find('div.post.reply').each(function() {
var id = $(this).attr('id');
if($('#' + id).length == 0) {
if (!new_posts) {
first_new_post = this;
}
new_posts++;
loaded_posts++;
elementsToAppend.push($(this));
@ -225,16 +220,14 @@ $(document).ready(function(){
$(window).scroll(function() {
recheck_activated();
// if the newest post is not visible
// If the newest post is not visible.
if($(this).scrollTop() + $(this).height() <
$('div.post:last').position().top + $('div.post:last').height()) {
end_of_page = false;
return;
} else {
if($("#auto_update_status").is(':checked') && timeDiff(poll_interval_mindelay)) {
poll(manualUpdate = true);
}
end_of_page = true;
}
});

View File

@ -10,60 +10,61 @@
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/expand.js';
*
*/
$(document).ready(function() {
if($('span.omitted').length == 0)
return; // nothing to expand
if ($('span.omitted').length === 0) {
// Nothing to expand.
return;
}
var do_expand = function() {
let doExpand = function() {
$(this)
.html($(this).text().replace(_("Click reply to view."), '<a href="javascript:void(0)">' + _("Click to expand") + '</a>.'))
.find('a').click(window.expand_fun = function() {
var thread = $(this).parents('[id^="thread_"]');
var id = thread.attr('id').replace(/^thread_/, '');
.find('a').click(window.expandFun = function() {
let thread = $(this).parents('[id^="thread_"]');
$.ajax({
url: thread.find('p.intro a.post_no:first').attr('href'),
context: document.body,
success: function(data) {
var last_expanded = false;
let lastExpanded = false;
$(data).find('div.post.reply').each(function() {
thread.find('div.hidden').remove();
var post_in_doc = thread.find('#' + $(this).attr('id'));
if(post_in_doc.length == 0) {
if(last_expanded) {
$(this).addClass('expanded').insertAfter(last_expanded).before('<br class="expanded">');
let postInDoc = thread.find('#' + $(this).attr('id'));
if (postInDoc.length === 0) {
if (lastExpanded) {
$(this).addClass('expanded').insertAfter(lastExpanded).before('<br class="expanded">');
} else {
$(this).addClass('expanded').insertAfter(thread.find('div.post:first')).after('<br class="expanded">');
}
last_expanded = $(this);
lastExpanded = $(this);
$(document).trigger('new_post', this);
} else {
last_expanded = post_in_doc;
lastExpanded = postInDoc;
}
});
thread.find("span.omitted").css('display', 'none');
thread.find('span.omitted').css('display', 'none');
$('<span class="omitted hide-expanded"><a href="javascript:void(0)">' + _('Hide expanded replies') + '</a>.</span>')
.insertAfter(thread.find('.op div.body, .op span.omitted').last())
.click(function() {
thread.find('.expanded').remove();
$(this).parent().find(".omitted:not(.hide-expanded)").css('display', '');
$(this).parent().find(".hide-expanded").remove();
let parent = $(this).parent();
parent.find('.omitted:not(.hide-expanded)').css('display', '');
parent.find('.hide-expanded').remove();
});
}
});
});
}
$('div.post.op span.omitted').each(do_expand);
$('div.post.op span.omitted').each(doExpand);
$(document).on("new_post", function(e, post) {
if (!$(post).hasClass("reply")) {
$(post).find('div.post.op span.omitted').each(do_expand);
$(document).on('new_post', function(e, post) {
if (!$(post).hasClass('reply')) {
$(post).find('div.post.op span.omitted').each(doExpand);
}
});
});

View File

@ -9,31 +9,31 @@
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/inline-expanding.js';
*
*/
$(document).ready(function() {
'use strict';
var DEFAULT_MAX = 5; // default maximum image loads
var inline_expand_post = function() {
var link = this.getElementsByTagName('a');
// Default maximum image loads.
const DEFAULT_MAX = 5;
var loadingQueue = (function () {
var MAX_IMAGES = localStorage.inline_expand_max || DEFAULT_MAX; // maximum number of images to load concurrently, 0 to disable
var loading = 0; // number of images that is currently loading
var waiting = []; // waiting queue
let inline_expand_post = function() {
let link = this.getElementsByTagName('a');
var enqueue = function (ele) {
let loadingQueue = (function() {
let MAX_IMAGES = localStorage.inline_expand_max || DEFAULT_MAX; // Maximum number of images to load concurrently, 0 to disable.
let loading = 0; // Number of images that is currently loading.
let waiting = []; // Waiting queue.
let enqueue = function(ele) {
waiting.push(ele);
};
var dequeue = function () {
let dequeue = function() {
return waiting.shift();
};
var update = function() {
var ele;
let update = function() {
while (loading < MAX_IMAGES || MAX_IMAGES === 0) {
ele = dequeue();
let ele = dequeue();
if (ele) {
++loading;
ele.deferred.resolve();
@ -44,7 +44,7 @@ $(document).ready(function(){
};
return {
remove: function(ele) {
var i = waiting.indexOf(ele);
let i = waiting.indexOf(ele);
if (i > -1) {
waiting.splice(i, 1);
}
@ -57,11 +57,11 @@ $(document).ready(function(){
add: function(ele) {
ele.deferred = $.Deferred();
ele.deferred.done(function () {
var $loadstart = $.Deferred();
var thumb = ele.childNodes[0];
var img = ele.childNodes[1];
let $loadstart = $.Deferred();
let thumb = ele.childNodes[0];
let img = ele.childNodes[1];
var onLoadStart = function (img) {
let onLoadStart = function (img) {
if (img.naturalWidth) {
$loadstart.resolve(img, thumb);
} else {
@ -71,7 +71,7 @@ $(document).ready(function(){
$(img).one('load', function () {
$.when($loadstart).done(function () {
// once fully loaded, update the waiting queue
// Once fully loaded, update the waiting queue.
--loading;
$(ele).data('imageLoading', 'false');
update();
@ -93,35 +93,36 @@ $(document).ready(function(){
} else {
enqueue(ele);
}
}
};
})();
for (var i = 0; i < link.length; i++) {
for (let i = 0; i < link.length; i++) {
if (typeof link[i] == "object" && link[i].childNodes && typeof link[i].childNodes[0] !== 'undefined' &&
link[i].childNodes[0].src && link[i].childNodes[0].className.match(/post-image/) && !link[i].className.match(/file/)) {
link[i].onclick = function(e) {
var img, post_body, still_open, canvas, scroll;
var thumb = this.childNodes[0];
var padding = 5;
var boardlist = $('.boardlist')[0];
let thumb = this.childNodes[0];
let padding = 5;
let boardlist = $('.boardlist')[0];
if (thumb.className == 'hidden')
if (thumb.className == 'hidden') {
return false;
if (e.which == 2 || e.ctrlKey) // open in new tab
}
if (e.which == 2 || e.ctrlKey) {
// Open in new tab.
return true;
}
if (!$(this).data('expanded')) {
if (~this.parentNode.className.indexOf('multifile'))
if (~this.parentNode.className.indexOf('multifile')) {
$(this).data('width', this.parentNode.style.width);
}
this.parentNode.removeAttribute('style');
$(this).data('expanded', 'true');
if (thumb.tagName === 'CANVAS') {
canvas = thumb;
let canvas = thumb;
thumb = thumb.nextSibling;
this.removeChild(canvas);
canvas.style.display = 'block';
@ -130,7 +131,7 @@ $(document).ready(function(){
thumb.style.opacity = '0.4';
thumb.style.filter = 'alpha(opacity=40)';
img = document.createElement('img');
let img = document.createElement('img');
img.className = 'full-image';
img.style.display = 'none';
img.setAttribute('alt', 'Fullsized image');
@ -140,43 +141,50 @@ $(document).ready(function(){
} else {
loadingQueue.remove(this);
scroll = false;
let scroll = false;
// scroll to thumb if not triggered by 'shrink all image'
// Scroll to thumb if not triggered by 'shrink all image'.
if (e.target.className == 'full-image') {
scroll = true;
}
if (~this.parentNode.className.indexOf('multifile'))
if (~this.parentNode.className.indexOf('multifile')) {
this.parentNode.style.width = $(this).data('width');
}
thumb.style.opacity = '';
thumb.style.display = '';
if (thumb.nextSibling) this.removeChild(thumb.nextSibling); //full image loaded or loading
if (thumb.nextSibling) {
// Full image loaded or loading.
this.removeChild(thumb.nextSibling);
}
$(this).removeData('expanded');
delete thumb.style.filter;
// do the scrolling after page reflow
// Do the scrolling after page reflow.
if (scroll) {
post_body = $(thumb).parentsUntil('form > div').last();
let post_body = $(thumb).parentsUntil('form > div').last();
// on multifile posts, determin how many other images are still expanded
still_open = post_body.find('.post-image').filter(function(){
// On multifile posts, determine how many other images are still expanded.
let still_open = post_body.find('.post-image').filter(function() {
return $(this).parent().data('expanded') == 'true';
}).length;
// deal with differnt boards' menu styles
if ($(boardlist).css('position') == 'fixed')
// Deal with different boards menu styles.
if ($(boardlist).css('position') == 'fixed') {
padding += boardlist.getBoundingClientRect().height;
}
if (still_open > 0) {
if (thumb.getBoundingClientRect().top - padding < 0)
if (thumb.getBoundingClientRect().top - padding < 0) {
$(document).scrollTop($(thumb).parent().parent().offset().top - padding);
}
} else {
if (post_body[0].getBoundingClientRect().top - padding < 0)
if (post_body[0].getBoundingClientRect().top - padding < 0) {
$(document).scrollTop(post_body.offset().top - padding);
}
}
}
if (localStorage.no_animated_gif === 'true' && typeof unanimate_gif === 'function') {
unanimate_gif(thumb);
@ -188,17 +196,18 @@ $(document).ready(function(){
}
};
// setting up user option
// Setting up user option.
if (window.Options && Options.get_tab('general')) {
Options.extend_tab('general', '<span id="inline-expand-max">'+ _('Number of simultaneous image downloads (0 to disable): ') +
Options.extend_tab('general', '<span id="inline-expand-max">' +
_('Number of simultaneous image downloads (0 to disable): ') +
'<input type="number" step="1" min="0" size="4"></span>');
$('#inline-expand-max input')
.css('width', '50px')
.val(localStorage.inline_expand_max || DEFAULT_MAX)
.on('change', function (e) {
// validation in case some fucktard tries to enter a negative floating point number
var n = parseInt(e.target.value);
var val = (n<0) ? 0 : n;
// Validation in case some fucktard tries to enter a negative floating point number.
let n = parseInt(e.target.value);
let val = (n < 0) ? 0 : n;
localStorage.inline_expand_max = val;
});
@ -207,7 +216,7 @@ $(document).ready(function(){
if (window.jQuery) {
$('div[id^="thread_"]').each(inline_expand_post);
// allow to work with auto-reload.js, etc.
// Allow to work with auto-reload.js, etc.
$(document).on('new_post', function(e, post) {
inline_expand_post.call(post);
});

View File

@ -85,7 +85,7 @@ if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?|
if ($(th).find(".new-posts").html() != msg) {
$(th).find(".new-posts").html(msg);
$(th).find(".new-posts a").click(window.expand_fun);
$(th).find(".new-posts a").click(window.expandFun);
}
};

View File

@ -1,3 +1,9 @@
/* Depends on post-menu.js
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/post-menu.js';
* $config['additional_javascript'][] = 'js/post-filter.js';
*/
if (active_page === 'thread' || active_page === 'index' || active_page === 'catalog' || active_page === 'ukko') {
$(document).on('menu_ready', function () {
'use strict';

View File

@ -10,17 +10,15 @@
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/quick-post-controls.js';
*
*/
$(document).ready(function() {
var open_form = function() {
var thread = $(this).parent().parent().hasClass('op');
var id = $(this).attr('name').match(/^delete_(\d+)$/)[1];
var submitButton;
let open_form = function() {
let thread = $(this).parent().parent().hasClass('op');
let id = $(this).attr('name').match(/^delete_(\d+)$/)[1];
if (this.checked) {
var post_form = $('<form class="post-actions" method="post" style="margin:10px 0 0 0">' +
let post_form = $('<form class="post-actions" method="post" style="margin:10px 0 0 0">' +
'<div style="text-align:right">' +
(!thread ? '<hr>' : '') +
@ -63,22 +61,23 @@ $(document).ready(function(){
post_form.prependTo($(this).parent().parent().find('div.body'));
} else {
post_form.appendTo($(this).parent().parent());
//post_form.insertBefore($(this));
}
$(window).trigger('quick-post-controls', post_form);
} else {
var elm = $(this).parent().parent().find('form');
let elm = $(this).parent().parent().find('form');
if(elm.attr('class') == 'post-actions')
if (elm.attr('class') == 'post-actions') {
elm.remove();
}
}
};
var init_qpc = function() {
let init_qpc = function() {
$(this).change(open_form);
if(this.checked)
if (this.checked) {
$(this).trigger('change');
}
};
$('div.post input[type=checkbox].delete').each(init_qpc);
@ -87,4 +86,3 @@ $(document).ready(function(){
$(post).find('input[type=checkbox].delete').each(init_qpc);
});
});

View File

@ -8,9 +8,8 @@
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* // $config['additional_javascript'][] = 'js/post-hover'; (optional; must come first)
* // $config['additional_javascript'][] = 'js/post-hover.js'; (optional; must come first)
* $config['additional_javascript'][] = 'js/show-backlinks.js';
*
*/
onReady(function() {
@ -18,34 +17,33 @@ onReady(function() {
let reply_id = $(this).attr('id').replace(/(^reply_)|(^op_)/, '');
$(this).find('div.body a:not([rel="nofollow"])').each(function() {
let id, post, $mentioned;
if (id = $(this).text().match(/^>>(\d+)$/)) {
let id = $(this).text().match(/^>>(\d+)$/);
if (id) {
id = id[1];
} else {
return;
}
$post = $('#reply_' + id);
if ($post.length == 0){
$post = $('#op_' + id);
if ($post.length == 0) {
let 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) {
$mentioned = $('<span class="mentioned unimportant"></span>').appendTo($post.find('p.intro'));
let mentioned = post.find('p.intro span.mentioned');
if(mentioned.length == 0) {
mentioned = $('<span class="mentioned unimportant"></span>').appendTo(post.find('p.intro'));
}
if ($mentioned.find('a.mentioned-' + reply_id).length != 0) {
if (mentioned.find('a.mentioned-' + reply_id).length != 0) {
return;
}
let link = $('<a class="mentioned-' + reply_id + '" onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">&gt;&gt;' +
reply_id + '</a>');
link.appendTo($mentioned)
link.appendTo(mentioned)
if (window.init_hover) {
link.each(init_hover);
@ -54,13 +52,12 @@ onReady(function() {
};
$('div.post.reply').each(showBackLinks);
$('div.post.op').each(showBackLinks);
$(document).on('new_post', function(e, post) {
if ($(post).hasClass("op")) {
$(post).find('div.post.reply').each(showBackLinks);
if ($(post).hasClass('reply')) {
showBackLinks.call(post);
} else {
$(post).parent().find('div.post.reply').each(showBackLinks);
$(post).find('div.post.reply').each(showBackLinks);
}
});
});

View File

@ -20,13 +20,17 @@ var watchlist = {};
*/
watchlist.render = function(reset) {
/* jshint eqnull:true */
if (reset == null) reset = false;
if (reset == null) {
reset = false;
}
/* jshint eqnull:false */
if (reset && $('#watchlist').length) $('#watchlist').remove();
var threads = [];
if (reset && $('#watchlist').length) {
$('#watchlist').remove();
}
let threads = [];
// Read the watchlist and create a new container for each thread.
JSON.parse(localStorage.watchlist).forEach(function(e, i) {
//look at line 69, that's what (e) is here.
// Look at line 69, that's what (e) is here.
threads.push('<div class="watchlist-inner" id="watchlist-'+i+'">' +
'<span>/'+e[0]+'/ - ' +
'<a href="'+e[3]+'">'+e[1].replace("thread_", _("Thread #"))+'</a>' +
@ -40,7 +44,7 @@ watchlist.render = function(reset) {
$('#watchlist').append(threads.join(''));
} else {
// If the watchlist has not yet been rendered, create it.
var menuStyle = getComputedStyle($('.boardlist')[0]);
let menuStyle = getComputedStyle($('.boardlist')[0]);
$((active_page == 'ukko') ? 'hr:first' : (active_page == 'catalog') ? 'body>span:first' : 'form[name="post"]').before(
$('<div id="watchlist">'+
'<div class="watchlist-controls">'+
@ -48,7 +52,8 @@ watchlist.render = function(reset) {
'<span><a id="clearGhosts">['+_('Clear Ghosts')+']</a></span>'+
'</div>'+
threads.join('')+
'</div>').css("background-color", menuStyle.backgroundColor).css("border", menuStyle.borderBottomWidth+" "+menuStyle.borderBottomStyle+" "+menuStyle.borderBottomColor));
'</div>').css("background-color", menuStyle.backgroundColor).css("border", menuStyle.borderBottomWidth+" "+menuStyle.borderBottomStyle+" "+menuStyle.borderBottomColor)
);
}
return this;
};
@ -58,9 +63,10 @@ watchlist.render = function(reset) {
* @param {[Obj/Str]} sel [An unwrapped jquery selector.]
*/
watchlist.add = function(sel) {
var threadName, threadInfo;
let threadName;
let threadInfo;
var board_name = $(sel).parents('.thread').data('board');
let board_name = $(sel).parents('.thread').data('board');
if (active_page === 'thread') {
if ($('.subject').length) {
@ -69,12 +75,10 @@ watchlist.add = function(sel) {
} else { //Otherwise use the thread id.
threadName = $('.op').parent().attr('id');
}
//board name, thread name as defined above, current amount of posts, thread url
// Board name, thread name as defined above, current amount of posts, thread url
threadInfo = [board_name, threadName, $('.post').length, location.href];
} else if (active_page === 'index' || active_page === 'ukko') {
var postCount;
let postCount;
// Figure out the post count.
if ($(sel).parents('.op').children('.omitted').length) {
postCount = $(sel).parents('.op').children('.omitted').text().split(' ')[0];
@ -82,7 +86,7 @@ watchlist.add = function(sel) {
postCount = $(sel).parents('.op').siblings('.post').length+1;
}
// Grab the reply link.;
var threadLink = $(sel).siblings('a:not(.watchThread)').last().attr('href');
let threadLink = $(sel).siblings('a:not(.watchThread)').last().attr('href');
// Figure out the thread name. If anon, use the thread id.
if ($(sel).parent().find('.subject').length) {
threadName = $(sel).parent().find('.subject').text().substring(0,20);
@ -91,7 +95,6 @@ watchlist.add = function(sel) {
}
threadInfo = [board_name, threadName, postCount, threadLink];
} else {
alert('Functionality not yet implemented for this type of page.');
return this;
@ -102,7 +105,7 @@ watchlist.add = function(sel) {
return this;
}
var _watchlist = JSON.parse(localStorage.watchlist); //Read the watchlist
let _watchlist = JSON.parse(localStorage.watchlist); //Read the watchlist
_watchlist.push(threadInfo); //Add the new watch item.
localStorage.watchlist = JSON.stringify(_watchlist); //Save the watchlist.
return this;
@ -113,7 +116,7 @@ watchlist.add = function(sel) {
* @param {[Int]} n [The index at which to remove.]
*/
watchlist.remove = function(n) {
var _watchlist = JSON.parse(localStorage.watchlist);
let _watchlist = JSON.parse(localStorage.watchlist);
_watchlist.splice(n, 1);
localStorage.watchlist = JSON.stringify(_watchlist);
return this;
@ -181,7 +184,7 @@ $(document).ready(function(){
// $('.watchlist-remove').on('click') won't work in case of re-renders and
// the page will need refreshing. This works around that.
$(document).on('click', '.watchlist-remove', function() {
var item = parseInt($(this).parent().attr('id').split('-')[1]);
let item = parseInt($(this).parent().attr('id').split('-')[1]);
watchlist.remove(item).render();
});
@ -196,6 +199,4 @@ $(document).ready(function(){
watchlist.exists(this);
});
});
});

View File

@ -929,9 +929,11 @@ pre {
display: inline-block;
user-select: none;
}
.poster_id:hover {
color: #800000!important;
}
.poster_id::before {
content: " ID: ";
}

View File

@ -12,7 +12,7 @@
var modRoot = "{{ config.root }}" + (inMod ? "mod.php?/" : "");
</script>
{% if not nojavascript %}
<script type="text/javascript" src="{{ config.url_javascript }}?v={{ config.resource_version }} data-resource-version="{{ config.resource_version }}"></script>
<script type="text/javascript" src="{{ config.url_javascript }}?v={{ config.resource_version }}"></script>
{% if not config.additional_javascript_compile %}
{% for javascript in config.additional_javascript %}<script type="text/javascript" src="{{ config.additional_javascript_url }}{{ javascript }}?v={{ config.resource_version }}"></script>{% endfor %}
{% endif %}