From 61bd5c648e63c0ed65eeb51c0a77ee235da282fd Mon Sep 17 00:00:00 2001 From: Mark Taiwan Date: Sun, 25 Jan 2015 23:48:26 +0800 Subject: [PATCH 1/2] 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 2/2] 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