From dc1cd65e1131936d362cddd9812b29af8579477b Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Fri, 23 Jan 2015 14:08:52 +0800 Subject: [PATCH 01/11] Fix thumbnail overlapping on external preview Fix the occasional thumbnail and filename overlap by truncating longer filenames and set file container width according to thumbnail width. --- js/post-hover.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/post-hover.js b/js/post-hover.js index aa4f5c60..4f4e7448 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -217,6 +217,12 @@ onready(function(){ } else { thumb_url = (this.isSpoiler) ? '/static/spoiler.png' : '/static/file.png'; } + + // truncate long filenames + if (this.filename.length > 23) { + this.filename = this.filename.substr(0, 22) + '…'; + } + // file infos var $ele = $('
') .append($('

') @@ -224,7 +230,7 @@ onready(function(){ .append(''+ this.filename + file_ext +'') .append(' ('+ bytesToSize(this.fsize) +', '+ this.w +'x'+ this.h +')') ); - if (multifile) $ele.addClass('multifile').css('max-width', '200px'); + if (multifile) $ele.addClass('multifile').css('width', this.thumb_w + 30); // image var $img = $('') From 1cc5da0f137e333c485a83f898f0fdbf8f6b6a65 Mon Sep 17 00:00:00 2001 From: wholelotofhs Date: Fri, 23 Jan 2015 04:39:55 -0500 Subject: [PATCH 02/11] Moved the post hide link to the left side Several users on /meta/ have voiced their displeasure over the hide post button appearing on the right side of posts by default, and they suggested moving it to the left side to be consistent with the hide thread button. --- js/hide-threads.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/js/hide-threads.js b/js/hide-threads.js index 64f0a384..bc1526eb 100644 --- a/js/hide-threads.js +++ b/js/hide-threads.js @@ -87,23 +87,22 @@ $(document).ready(function(){ hidden_data[board] = {}; // id : timestamp } - $('[–]') - .insertAfter(post.children('p.intro').children('a.post_no:last')) + $('[–]') + .insertBefore(post.children('p.intro').children('input.delete')) .click(function() { hidden_data[board][id] = Math.round(Date.now() / 1000); store_data(); var hide_link = $(this); post.children('div').hide(); hide_link.hide(); - $('[+]') - .insertAfter(post.children('p.intro').children('a.post_no:last')) + $('[+]') + .insertBefore(post.children('p.intro').children('input.delete')) .click(function() { delete hidden_data[board][id]; store_data(); post.children('div').show(); hide_link.show(); $(this).remove(); - }); }); if (hidden_data[board][id]) From b81ee15e84a9deae33426ee053b87888efb9bc69 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Fri, 23 Jan 2015 23:26:41 +0800 Subject: [PATCH 03/11] Adds user option for thread updater Adds checkbox to the Options panel Convert stray space indents to tabs --- js/auto-reload.js | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/js/auto-reload.js b/js/auto-reload.js index 0bfae3e8..ff015a80 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -37,7 +37,30 @@ $(document).ready(function(){ var countdown_interval; // Add an update link - $('.boardlist.bottom').prev().after("["+_("Update")+"] ( "+_("Auto")+") "); + $('.boardlist.bottom').prev().after("["+_("Update")+"] ( "+_("Auto")+") "); + + // Adds Options panel item + if (typeof localStorage.auto_thread_update === 'undefined') { + localStorage.auto_thread_update = 'true'; //default value + } + if (window.Options && Options.get_tab('general')) { + Options.extend_tab('general', ''); + $('#auto-thread-update>input').on('click', function() { + if ($('#auto-thread-update>input').is(':checked')) { + localStorage.auto_thread_update = 'true'; + } else { + localStorage.auto_thread_update = 'false'; + } + }); + if (localStorage.auto_thread_update === 'true') { + $('#show-relative-time>input').prop('checked', true); + } + } + + // Set the updater checkbox according to user setting + if (localStorage.auto_thread_update === 'true') { + $('#auto_update_status').prop('checked', true); + } // Grab the settings var settings = new script_settings('auto-reload'); @@ -51,19 +74,19 @@ $(document).ready(function(){ var end_of_page = false; - var new_posts = 0; + var new_posts = 0; var first_new_post = null; var title = document.title; if (typeof update_title == "undefined") { - var update_title = function() { - if (new_posts) { - document.title = "("+new_posts+") "+title; - } else { - document.title = title; - } - }; + var update_title = function() { + if (new_posts) { + document.title = "("+new_posts+") "+title; + } else { + document.title = title; + } + }; } if (typeof add_title_collector != "undefined") @@ -130,9 +153,9 @@ $(document).ready(function(){ clearInterval(countdown_interval); } - var epoch = (new Date).getTime(); - var epochold = epoch; - + var epoch = (new Date).getTime(); + var epochold = epoch; + var timeDiff = function (delay) { if((epoch-epochold) > delay) { epochold = epoch = (new Date).getTime(); From f548a03e69422b486ff9cb8bedb631b715ee15bb Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Sun, 25 Jan 2015 17:55:26 +0800 Subject: [PATCH 04/11] Add 'esc' keybind to close quick-reply. --- js/quick-reply.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/quick-reply.js b/js/quick-reply.js index 7156b224..eaa152fd 100644 --- a/js/quick-reply.js +++ b/js/quick-reply.js @@ -278,7 +278,13 @@ } }); - $postForm.find('textarea[name="body"]').removeAttr('id').removeAttr('cols').attr('placeholder', _('Comment')); + $postForm.find('textarea[name="body"]').removeAttr('id').removeAttr('cols').attr('placeholder', _('Comment')) + .on('keydown', function (e) { + //close quick reply when esc is prssed + if (e.which === 27) { + $('.close-btn').trigger('click'); + } + }); $postForm.find('textarea:not([name="body"]),input[type="hidden"]:not(.captcha_cookie)').removeAttr('id').appendTo($dummyStuff); From 3b5acb7df802790dd46de624be1419aaf3d638dd Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Sun, 25 Jan 2015 18:03:01 +0800 Subject: [PATCH 05/11] Focus keyboard cursor on quick-reply box --- js/quick-reply.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/quick-reply.js b/js/quick-reply.js index eaa152fd..9ac1a593 100644 --- a/js/quick-reply.js +++ b/js/quick-reply.js @@ -379,7 +379,8 @@ } else { $postForm.show(); } - + + $postForm.find('textarea[name="body"]').focus(); $(window).on('stylesheet', function() { do_css(); if ($('link#stylesheet').attr('href')) { From 5acdf16f5e7f754c99703862666479235ee642fc Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Sun, 25 Jan 2015 22:08:25 +0800 Subject: [PATCH 06/11] reply quoting improvement - multi line quoting - ability to quote from board index - works in Chrome --- templates/main.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/templates/main.js b/templates/main.js index 254e12c0..76cb5347 100644 --- a/templates/main.js +++ b/templates/main.js @@ -334,13 +334,18 @@ function citeReply(id, with_link) { textarea.value += '>>' + id + '\n'; } if (typeof $ != 'undefined') { - var select = document.getSelection().toString(); + // multiline quotes + var select = sessionStorage.quoteClipboard; if (select) { - var body = $('#reply_' + id + ', #op_' + id).find('div.body'); // TODO: support for OPs - var index = body.text().indexOf(select.replace('\n', '')); // for some reason this only works like this - if (index > -1) { - textarea.value += '>' + select + '\n'; - } + select = select.split('\n'); + $(select).each(function () { + if (this !== '') + var str = '>'+ this +'\n'; + else + var str = '\n'; + textarea.value += str; + }); + delete sessionStorage.quoteClipboard; } $(window).trigger('cite', [id, with_link]); @@ -403,6 +408,13 @@ var script_settings = function(script_name) { function init() { init_stylechooser(); + if (typeof $ != 'undefined') { + // store highlighted text for citeReply() + $('form[name="postcontrols"]').on('mouseup', function (e) { + sessionStorage.quoteClipboard = window.getSelection().toString(); + }); + } + {% endraw %} {% if config.allow_delete %} if (document.forms.postcontrols) { From 61bd5c648e63c0ed65eeb51c0a77ee235da282fd Mon Sep 17 00:00:00 2001 From: Mark Taiwan Date: Sun, 25 Jan 2015 23:48:26 +0800 Subject: [PATCH 07/11] highlightReply: check for linking to external post Fix for linking to external posts not working in Chrome. --- templates/main.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/templates/main.js b/templates/main.js index 254e12c0..8572c0a8 100644 --- a/templates/main.js +++ b/templates/main.js @@ -254,6 +254,17 @@ function get_cookie(cookie_name) { } function highlightReply(id, event) { + if (typeof $ != 'undefined') { + // check if external post + // TODO: Don't use jQuery + var post_list = $('a.post_no').filter(':not([id])').filter(function(){ + if (!$(this).parent().parent().hasClass('hidden')) return true; + }); + post_list = $.map($.makeArray(post_list), function(ele) {return $(ele).html()}); + if (post_list.indexOf(id) == -1) + return true; + } + if (typeof window.event != "undefined") { // don't highlight on middle click var e = event || window.event; From f484d28e055134834b13a74d58ba36f88802445f Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Wed, 28 Jan 2015 21:55:15 +0800 Subject: [PATCH 08/11] highlightReply no longer requires jQuery Also accidentally converted a bunch of space to tabs --- templates/main.js | 110 +++++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/templates/main.js b/templates/main.js index 8572c0a8..061c40c1 100644 --- a/templates/main.js +++ b/templates/main.js @@ -22,58 +22,58 @@ function fmt(s,a) { } function until($timestamp) { - var $difference = $timestamp - Date.now()/1000|0, $num; - switch(true){ - case ($difference < 60): - return "" + $difference + ' ' + _('second(s)'); - case ($difference < 3600): //60*60 = 3600 - return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); - case ($difference < 86400): //60*60*24 = 86400 - return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); - case ($difference < 604800): //60*60*24*7 = 604800 - return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); - case ($difference < 31536000): //60*60*24*365 = 31536000 - return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); - default: - return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); - } + var $difference = $timestamp - Date.now()/1000|0, $num; + switch(true){ + case ($difference < 60): + return "" + $difference + ' ' + _('second(s)'); + case ($difference < 3600): //60*60 = 3600 + return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); + case ($difference < 86400): //60*60*24 = 86400 + return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); + case ($difference < 604800): //60*60*24*7 = 604800 + return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); + case ($difference < 31536000): //60*60*24*365 = 31536000 + return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); + default: + return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); + } } function ago($timestamp) { - var $difference = (Date.now()/1000|0) - $timestamp, $num; - switch(true){ - case ($difference < 60) : - return "" + $difference + ' ' + _('second(s)'); - case ($difference < 3600): //60*60 = 3600 - return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); - case ($difference < 86400): //60*60*24 = 86400 - return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); - case ($difference < 604800): //60*60*24*7 = 604800 - return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); - case ($difference < 31536000): //60*60*24*365 = 31536000 - return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); - default: - return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); - } + var $difference = (Date.now()/1000|0) - $timestamp, $num; + switch(true){ + case ($difference < 60) : + return "" + $difference + ' ' + _('second(s)'); + case ($difference < 3600): //60*60 = 3600 + return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); + case ($difference < 86400): //60*60*24 = 86400 + return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); + case ($difference < 604800): //60*60*24*7 = 604800 + return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); + case ($difference < 31536000): //60*60*24*365 = 31536000 + return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); + default: + return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); + } } var datelocale = - { days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] - , shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")] - , months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')] - , shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')] - , AM: _('AM') - , PM: _('PM') - , am: _('am') - , pm: _('pm') - }; + { days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] + , shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")] + , months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')] + , shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')] + , AM: _('AM') + , PM: _('PM') + , am: _('am') + , pm: _('pm') + }; function alert(a) { var handler, div; var close = function() { - handler.fadeOut(400, function() { handler.remove(); }); - return false; + handler.fadeOut(400, function() { handler.remove(); }); + return false; }; handler = $("

").hide().appendTo('body'); @@ -254,16 +254,26 @@ function get_cookie(cookie_name) { } function highlightReply(id, event) { - if (typeof $ != 'undefined') { - // check if external post - // TODO: Don't use jQuery - var post_list = $('a.post_no').filter(':not([id])').filter(function(){ - if (!$(this).parent().parent().hasClass('hidden')) return true; - }); - post_list = $.map($.makeArray(post_list), function(ele) {return $(ele).html()}); - if (post_list.indexOf(id) == -1) - return true; + // check if external post + var post_list, arr, i; + + post_list = document.querySelectorAll('a.post_no'); + for (i = 0, arr = []; i