Advertisement
tomkiewicz

scrollmode-2

Apr 24th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.81 KB | None | 0 0
  1. diff --git a/pidgin/themes/Template.html b/pidgin/themes/Template.html
  2. --- a/pidgin/themes/Template.html
  3. +++ b/pidgin/themes/Template.html
  4. @@ -156,6 +156,7 @@
  5.  
  6.             // Only call nearBottom() if should scroll is undefined.
  7.             if(undefined === coalescedHTML.shouldScroll) {
  8. +               console.log('appendMessage');
  9.                 shouldScroll = nearBottom();
  10.             } else {
  11.                 shouldScroll = coalescedHTML.shouldScroll;
  12. @@ -172,6 +173,7 @@
  13.         function appendNextMessage(html){
  14.             var shouldScroll;
  15.             if(undefined === coalescedHTML.shouldScroll) {
  16. +               console.log('appendNextMessage');
  17.                 shouldScroll = nearBottom();
  18.             } else {
  19.                 shouldScroll = coalescedHTML.shouldScroll;
  20. @@ -190,12 +192,14 @@
  21.             // only replace messages if we're already coalescing
  22.             if(coalescedHTML.isCoalescing){
  23.                 if(undefined === coalescedHTML.shouldScroll) {
  24. +                   console.log('replaceLastMessage 1');
  25.                     shouldScroll = nearBottom();
  26.                 } else {
  27.                     shouldScroll = coalescedHTML.shouldScroll;
  28.                 }
  29.                 coalescedHTML.replaceLast(html, shouldScroll);
  30.             } else {
  31. +               console.log('replaceLastMessage 2');
  32.                 shouldScroll = nearBottom();
  33.                 //Retrieve the current insertion point, then remove it
  34.                 //This requires that there have been an insertion point... is there a better way to retrieve the last element? -evands
  35. @@ -214,12 +218,89 @@
  36.             }
  37.         }
  38.  
  39. +       var SCROLLMODE_UNKNOWN = 0;
  40. +       var SCROLLMODE_WEBKIT1 = 1;
  41. +       var SCROLLMODE_WEBKIT2 = 2;
  42. +       var scroll_mode = SCROLLMODE_UNKNOWN;
  43. +
  44. +       function detectWebkitScrolling() {
  45. +           if (scroll_mode != SCROLLMODE_UNKNOWN)
  46. +               return scroll_mode;
  47. +           if (document.body.scrollTop > 0)
  48. +               scroll_mode = SCROLLMODE_WEBKIT1;
  49. +           if (document.documentElement.scrollTop > 0)
  50. +               scroll_mode = SCROLLMODE_WEBKIT2;
  51. +           return scroll_mode;
  52. +       }
  53. +
  54. +       var stickyscroll_just_scrolled = false;
  55. +       var stickyscroll_just_scrolled_more = false;
  56. +       var stickyscroll_to_bottom = true;
  57. +       var stickyscroll_to_bottom_new = true;
  58. +
  59. +       function windowDidScroll(ev) {
  60. +           if (stickyscroll_just_scrolled) {
  61. +               stickyscroll_just_scrolled_more = true;
  62. +               return;
  63. +           }
  64. +
  65. +           console.log('windowDidScroll()');
  66. +
  67. +           stickyscroll_just_scrolled = true;
  68. +           var update_to_bottom = function() {
  69. +               console.log('update_to_bottom: ' + stickyscroll_to_bottom_new);
  70. +               stickyscroll_to_bottom = stickyscroll_to_bottom_new;
  71. +               stickyscroll_to_bottom_new = nearBottom2();
  72. +
  73. +               if (stickyscroll_just_scrolled_more) {
  74. +                   stickyscroll_just_scrolled_more = false;
  75. +                   setTimeout(update_to_bottom, 10);
  76. +               } else {
  77. +                   stickyscroll_just_scrolled = false;
  78. +               }
  79. +           };
  80. +           setTimeout(update_to_bottom, 10);
  81. +       }
  82. +
  83. +       function nearBottom() {
  84. +           return stickyscroll_to_bottom;
  85. +       }
  86. +
  87.         //Auto-scroll to bottom.  Use nearBottom to determine if a scrollToBottom is desired.
  88. -       function nearBottom() {
  89. -           return ( document.body.scrollTop >= ( document.body.offsetHeight - ( window.innerHeight * 1.2 ) ) );
  90. +       function nearBottom2() {
  91. +           var mode = detectWebkitScrolling();
  92. +           console.log('nearBottom: mode=' + mode);
  93. +           if (mode == SCROLLMODE_UNKNOWN || mode == SCROLLMODE_WEBKIT1) {
  94. +               x = ( document.body.scrollTop >=
  95. +                   ( document.body.offsetHeight - (window.innerHeight + 20) ) );
  96. +           } else { /* SCROLLMODE_WEBKIT2 */
  97. +               x = ( document.documentElement.scrollTop >=
  98. +                   ( document.documentElement.offsetHeight - (window.innerHeight + 20) ) );
  99. +           }
  100. +           console.log('is near bottom: ' + x);
  101. +           return x;
  102.         }
  103.         function scrollToBottom() {
  104. -           document.body.scrollTop = document.body.offsetHeight;
  105. +           var mode = detectWebkitScrolling();
  106. +           console.log('scrollToBottom: mode=' + mode);
  107. +
  108. +           var scrollfunc;
  109. +           if (mode == SCROLLMODE_UNKNOWN || mode == SCROLLMODE_WEBKIT1) {
  110. +               scrollfunc = function() {
  111. +                   console.log('scroll!');
  112. +                   document.body.scrollTop = document.body.offsetHeight;
  113. +               };
  114. +           } else { /* SCROLLMODE_WEBKIT2 */
  115. +               scrollfunc = function() {
  116. +                   document.documentElement.scrollTop =
  117. +                       document.documentElement.offsetHeight;
  118. +                   window.scrollTo(0, document.body.scrollHeight);
  119. +               };
  120. +           }
  121. +
  122. +           scrollfunc();
  123. +           /* wait for content to load and scroll again */
  124. +           setTimeout(scrollfunc, 10);
  125.         }
  126.  
  127.         //Dynamically exchange the active stylesheet
  128. @@ -242,11 +323,10 @@
  129.                 return;
  130.  
  131.             scrollToBottom();
  132. -           /* wait for images to load and scroll again */
  133. -           setTimeout(scrollToBottom, 10);
  134.         }
  135.  
  136.         function remoteImageIsReady(id) {
  137. +           console.log('remoteImageIsReady');
  138.             var shouldScroll = nearBottom();
  139.             var emoticons;
  140.  
  141. @@ -272,13 +352,16 @@
  142.         }
  143.  
  144.         window.onresize = function windowDidResize(){
  145. -           alignChat(true/*nearBottom()*/); //nearBottom buggy with inactive tabs
  146. +           console.log('window.onresize');
  147. +           alignChat(nearBottom());
  148.         }
  149.  
  150.         function initStyle() {
  151.             alignChat(true);
  152.             if(!coalescedHTML)
  153.                 coalescedHTML = new CoalescedHTML();
  154. +
  155. +           window.addEventListener('scroll', windowDidScroll);
  156.         }
  157.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement