Mayhem's unread scroll fixes

This commit is contained in:
Jordan Bates 2013-04-24 12:59:07 -07:00
parent 867ba2bf0e
commit eb0386c82f
4 changed files with 64 additions and 71 deletions

View File

@ -6585,13 +6585,14 @@
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
$.on(d, 'visibilitychange', Unread.setLine); $.on(d, 'visibilitychange', Unread.setLine);
} }
if (!Conf['Scroll to Last Read Post']) { if (Conf['Scroll to Last Read Post']) {
return; return $.on(window, 'load', Unread.scroll);
} }
return $.on(window, 'load', function() { },
var hash, root; scroll: function() {
var hash, posts, root;
if ((hash = location.hash.match(/\d+/)) && hash[0] in this.posts) { if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) {
return; return;
} }
if (Unread.posts.length) { if (Unread.posts.length) {
@ -6600,14 +6601,11 @@
break; break;
} }
} }
if (!root) { root.scrollIntoView(false);
return; return;
} }
return root.scrollIntoView(false); posts = Object.keys(Unread.thread.posts);
} else if (posts.length) { return Header.scrollToPost(Unread.thread.posts[posts[posts.length - 1]].nodes.root);
return Header.scrollToPost(posts[posts.length - 1].nodes.root);
}
});
}, },
sync: function() { sync: function() {
var lastReadPost; var lastReadPost;

View File

@ -6576,13 +6576,14 @@
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
$.on(d, 'visibilitychange', Unread.setLine); $.on(d, 'visibilitychange', Unread.setLine);
} }
if (!Conf['Scroll to Last Read Post']) { if (Conf['Scroll to Last Read Post']) {
return; return $.on(window, 'load', Unread.scroll);
} }
return $.on(window, 'load', function() { },
var hash, root; scroll: function() {
var hash, posts, root;
if ((hash = location.hash.match(/\d+/)) && hash[0] in this.posts) { if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) {
return; return;
} }
if (Unread.posts.length) { if (Unread.posts.length) {
@ -6591,14 +6592,11 @@
break; break;
} }
} }
if (!root) { root.scrollIntoView(false);
return; return;
} }
return root.scrollIntoView(false); posts = Object.keys(Unread.thread.posts);
} else if (posts.length) { return Header.scrollToPost(Unread.thread.posts[posts[posts.length - 1]].nodes.root);
return Header.scrollToPost(posts[posts.length - 1].nodes.root);
}
});
}, },
sync: function() { sync: function() {
var lastReadPost; var lastReadPost;

View File

@ -6440,13 +6440,14 @@
if (Conf['Unread Line']) { if (Conf['Unread Line']) {
$.on(d, 'visibilitychange', Unread.setLine); $.on(d, 'visibilitychange', Unread.setLine);
} }
if (!Conf['Scroll to Last Read Post']) { if (Conf['Scroll to Last Read Post']) {
return; return $.on(window, 'load', Unread.scroll);
} }
return $.on(window, 'load', function() { },
var hash, root; scroll: function() {
var hash, posts, root;
if ((hash = location.hash.match(/\d+/)) && hash[0] in this.posts) { if ((hash = location.hash.match(/\d+/)) && hash[0] in Unread.thread.posts) {
return; return;
} }
if (Unread.posts.length) { if (Unread.posts.length) {
@ -6455,14 +6456,11 @@
break; break;
} }
} }
if (!root) { root.scrollIntoView(false);
return; return;
} }
return root.scrollIntoView(false); posts = Object.keys(Unread.thread.posts);
} else if (posts.length) { return Header.scrollToPost(Unread.thread.posts[posts[posts.length - 1]].nodes.root);
return Header.scrollToPost(posts[posts.length - 1].nodes.root);
}
});
}, },
sync: function() { sync: function() {
var lastReadPost; var lastReadPost;

View File

@ -26,21 +26,20 @@ Unread =
$.on d, 'ThreadUpdate', Unread.onUpdate $.on d, 'ThreadUpdate', Unread.onUpdate
$.on d, 'scroll visibilitychange', Unread.read $.on d, 'scroll visibilitychange', Unread.read
$.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] $.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line']
$.on window, 'load', Unread.scroll if Conf['Scroll to Last Read Post']
return unless Conf['Scroll to Last Read Post'] scroll: ->
$.on window, 'load', ->
# Let the header's onload callback handle it. # Let the header's onload callback handle it.
return if (hash = location.hash.match /\d+/) and hash[0] of @posts return if (hash = location.hash.match /\d+/) and hash[0] of Unread.thread.posts
if Unread.posts.length if Unread.posts.length
# Scroll to before the first unread post. # Scroll to before the first unread post.
while root = $.x 'preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root while root = $.x 'preceding-sibling::div[contains(@class,"postContainer")][1]', Unread.posts[0].nodes.root
break unless (Get.postFromRoot root).isHidden break unless (Get.postFromRoot root).isHidden
return unless root
root.scrollIntoView false root.scrollIntoView false
else if posts.length return
# Scroll to the last read post. # Scroll to the last read post.
Header.scrollToPost (posts[posts.length - 1]).nodes.root posts = Object.keys Unread.thread.posts
Header.scrollToPost Unread.thread.posts[posts[posts.length - 1]].nodes.root
sync: -> sync: ->
lastReadPost = Unread.db.get lastReadPost = Unread.db.get