Merge lp:~cmiller/adium-theme-ubuntu/lp959084-avoid-scroll-infinite-loop into lp:adium-theme-ubuntu

Proposed by Chad Miller
Status: Merged
Merged at revision: 16
Proposed branch: lp:~cmiller/adium-theme-ubuntu/lp959084-avoid-scroll-infinite-loop
Merge into: lp:adium-theme-ubuntu
Diff against target: 68 lines (+28/-5)
1 file modified
ubuntu.AdiumMessageStyle/Contents/Resources/Template.html (+28/-5)
To merge this branch: bzr merge lp:~cmiller/adium-theme-ubuntu/lp959084-avoid-scroll-infinite-loop
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+131474@code.launchpad.net

Commit message

Avoid infinite loop in scrolling to bottom of message window.

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks great, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu.AdiumMessageStyle/Contents/Resources/Template.html'
2--- ubuntu.AdiumMessageStyle/Contents/Resources/Template.html 2010-06-13 12:25:55 +0000
3+++ ubuntu.AdiumMessageStyle/Contents/Resources/Template.html 2012-10-25 20:06:25 +0000
4@@ -7,7 +7,7 @@
5
6 <script type="text/javascript">
7 //<![CDATA[
8- isDebug = false;
9+ var isDebug = false;
10
11 //Do this on load
12 function initEvents() {
13@@ -83,14 +83,29 @@
14 alignChat(shouldScroll);
15 }
16
17-
18- //Auto-scroll to bottom. Use nearBottom to determine if a scrollToBottom is desired.
19 function nearBottom() {
20- return ( document.body.scrollTop >= ( document.body.offsetHeight - ( window.innerHeight * 1.2 ) ) );
21+ var fastResizeSafety = 20; //px
22+ // Quick window shrink may move marker offscreen before we notice
23+ // and re-scroll to catch up. With a little buffer here, the
24+ // bottom marker has to go off-screen more before we forget that we
25+ // were at the end.
26+
27+ var bottomOfConversation = document.getElementById("bottomMarker").offsetTop - 20;
28+ var bottomOfWindow = document.body.scrollTop + window.innerHeight;
29+ return (bottomOfConversation <= bottomOfWindow);
30+
31 }
32
33 var intervall_scroll;
34 function scrollToBottom() {
35+ var bottomMarker = document.getElementById("bottomMarker");
36+
37+ // Use smart scroll function if we have it. (We probably do.)
38+ if (bottomMarker && bottomMarker.scrollIntoView) {
39+ bottomMarker.scrollIntoView(true);
40+ return;
41+ }
42+
43 //document.body.scrollTop = (document.body.scrollHeight-window.innerHeight);
44 //return;
45 if( intervall_scroll ) clearInterval( intervall_scroll );
46@@ -141,7 +156,13 @@
47 }
48
49 function windowDidResize() {
50- alignChat(false); //nearBottom buggy with inavtive tabs
51+ // Window is changing size. Should we keep up with the bottom,
52+ // where new messages are coming in, or at the top, where the user
53+ // is perhaps reading? Use a heuristic of checking to see if we're
54+ // scrolled to the bottom to decide whether to stick with the
55+ // bottom.
56+
57+ alignChat(nearBottom());
58 }
59
60 window.onresize = windowDidResize;
61@@ -158,5 +179,7 @@
62 %@
63 <div id="debug"></div>
64
65+<div id="bottomMarker" />
66+
67 </body>
68 </html>

Subscribers

People subscribed via source and target branches

to all changes: