smarter scrolling

This commit is contained in:
James Campos 2010-11-18 23:18:37 -08:00
parent 6af0eca109
commit a100ba91dd
2 changed files with 59 additions and 31 deletions

View File

@ -376,11 +376,6 @@ keypress = (e) ->
e.preventDefault() e.preventDefault()
char = String.fromCharCode kc char = String.fromCharCode kc
hash = location.hash hash = location.hash
if not hash or hash == '#navtop'
position = -1
else
temp = Number(hash.substring 2)
position = if temp is NaN then -1 else temp
count = g.count count = g.count
if char in '1234567890' if char in '1234567890'
temp = Number char temp = Number char
@ -416,13 +411,9 @@ keypress = (e) ->
qrLink = $ "#{hash} ~ span[id] a:not(:first-child)" qrLink = $ "#{hash} ~ span[id] a:not(:first-child)"
quickReply.call qrLink quickReply.call qrLink
when "J" when "J"
temp = position + count scroll count
if temp > 9 then temp = 9
location.hash = 'p' + temp
when "K" when "K"
temp = position - count scroll count * -1
if temp < 0 then temp = 'navtop' else temp = 'p' + temp
location.hash = temp
when "L" when "L"
temp = g.PAGENUM + count temp = g.PAGENUM + count
if temp > 15 then temp = 15 if temp > 15 then temp = 15
@ -618,6 +609,30 @@ report = ->
$('input[value="Report"]').click() $('input[value="Report"]').click()
input.click() input.click()
scroll = (count) ->
threads = $$ 'div.thread'
for thread in threads
bottom = thread.getBoundingClientRect().bottom
if bottom > 0 #we have not scrolled past
top = thread.getBoundingClientRect().top
idx = _i
break
if idx is 0 and top > 1
#we haven't scrolled to the first thread
idx = -1
if count < 0 and top < -1
#we've started scrolling past this thread,
# but now want to read from the beginning
count++
temp = idx + count
if temp < 0
hash = ''
else if temp > 9
hash = 'p9'
else
hash = "p#{temp}"
location.hash = hash
showReply = -> showReply = ->
div = this.parentNode div = this.parentNode
table = div.nextSibling table = div.nextSibling

View File

@ -1,5 +1,5 @@
(function() { (function() {
var $, $$, AEOS, DAY, _, _i, _len, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, form, formSubmit, g, getConfig, getTime, hide, hideReply, hideThread, href, html, id, iframe, iframeLoad, inAfter, inBefore, input, inputs, keybindAdd, keybindRem, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, show, showReply, showThread, slice, span, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watcher, watcherUpdate, x; var $, $$, AEOS, DAY, _, _i, _len, _ref, _ref2, a, addTo, arr, as, autoWatch, autohide, b, board, callback, clearHidden, closeQR, config, cooldown, cutoff, d, delform, down, editSauce, el, expandComment, expandThread, form, formSubmit, g, getConfig, getTime, hide, hideReply, hideThread, href, html, id, iframe, iframeLoad, inAfter, inBefore, input, inputs, keybindAdd, keybindRem, keydown, keypress, l1, lastChecked, m, n, navbotr, navtopr, nodeInserted, now, omitted, onloadComment, onloadThread, options, optionsClose, parseResponse, pathname, quickReply, recaptcha, recaptchaListener, recaptchaReload, redirect, remove, replace, replyNav, report, scroll, show, showReply, showThread, slice, span, stopPropagation, temp, text, textContent, thread, threadF, threads, tn, up, watch, watchX, watcher, watcherUpdate, x;
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty; var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
config = { config = {
'Thread Hiding': [true, 'Hide entire threads'], 'Thread Hiding': [true, 'Hide entire threads'],
@ -457,7 +457,7 @@
return d.removeEventListener('keypress', keypress, true); return d.removeEventListener('keypress', keypress, true);
}; };
keypress = function(e) { keypress = function(e) {
var _i, _len, char, count, hash, href, img, kc, position, qrLink, temp; var _i, _len, char, count, hash, href, img, kc, qrLink, temp;
kc = g.keyCode; kc = g.keyCode;
if (kc === -1) { if (kc === -1) {
return null; return null;
@ -465,12 +465,6 @@
e.preventDefault(); e.preventDefault();
char = String.fromCharCode(kc); char = String.fromCharCode(kc);
hash = location.hash; hash = location.hash;
if (!hash || hash === '#navtop') {
position = -1;
} else {
temp = Number(hash.substring(2));
position = temp === NaN ? -1 : temp;
}
count = g.count; count = g.count;
if ((function(){ for (var _i=0, _len='1234567890'.length; _i<_len; _i++) { if ('1234567890'[_i] === char) return true; } return false; }).call(this)) { if ((function(){ for (var _i=0, _len='1234567890'.length; _i<_len; _i++) { if ('1234567890'[_i] === char) return true; } return false; }).call(this)) {
temp = Number(char); temp = Number(char);
@ -518,20 +512,10 @@
quickReply.call(qrLink); quickReply.call(qrLink);
break; break;
case "J": case "J":
temp = position + count; scroll(count);
if (temp > 9) {
temp = 9;
}
location.hash = 'p' + temp;
break; break;
case "K": case "K":
temp = position - count; scroll(count * -1);
if (temp < 0) {
temp = 'navtop';
} else {
temp = 'p' + temp;
}
location.hash = temp;
break; break;
case "L": case "L":
temp = g.PAGENUM + count; temp = g.PAGENUM + count;
@ -801,6 +785,35 @@
$('input[value="Report"]').click(); $('input[value="Report"]').click();
return input.click(); return input.click();
}; };
scroll = function(count) {
var _i, _len, _ref, bottom, hash, idx, temp, thread, threads, top;
threads = $$('div.thread');
_ref = threads;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
thread = _ref[_i];
bottom = thread.getBoundingClientRect().bottom;
if (bottom > 0) {
top = thread.getBoundingClientRect().top;
idx = _i;
break;
}
}
if (idx === 0 && top > 1) {
idx = -1;
}
if (count < 0 && top < -1) {
count++;
}
temp = idx + count;
if (temp < 0) {
hash = '';
} else if (temp > 9) {
hash = 'p9';
} else {
hash = ("p" + (temp));
}
return (location.hash = hash);
};
showReply = function() { showReply = function() {
var div, id, table; var div, id, table;
div = this.parentNode; div = this.parentNode;