Quellcode durchsuchen

Fix scroll glue behavior (#923)

Fixes #18.
vortex852456 vor 5 Jahren
Ursprung
Commit
3e1f7e0bbe
2 geänderte Dateien mit 5 neuen und 31 gelöschten Zeilen
  1. 0 26
      src/helpers.ts
  2. 5 5
      src/partials/messenger.ts

+ 0 - 26
src/helpers.ts

@@ -219,32 +219,6 @@ export function isString(val: any): boolean {
     return typeof val === 'string' || val instanceof String;
 }
 
-/**
- * Throttle function.
- *
- * Taken from https://remysharp.com/2010/07/21/throttling-function-calls
- */
-export function throttle(fn, threshold: number = 250, scope) {
-    let last;
-    let deferTimer;
-    return function() {
-        const context = scope || this;
-        const now = +(new Date());
-        const args = arguments;
-        if (last && now < last + threshold) {
-            // hold on to it
-            clearTimeout(deferTimer);
-            deferTimer = setTimeout(function() {
-                last = now;
-                fn.apply(context, args);
-            }, threshold);
-        } else {
-            last = now;
-            fn.apply(context, args);
-        }
-    };
-}
-
 /**
  * Detect whether browser supports passive event listeners.
  *

+ 5 - 5
src/partials/messenger.ts

@@ -27,7 +27,7 @@ import {Logger} from 'ts-log';
 import {ContactControllerModel} from '../controller_model/contact';
 import {DialogController} from '../controllers/dialog';
 import {TroubleshootingController} from '../controllers/troubleshooting';
-import {bufferToUrl, hasValue, supportsPassive, throttle, u8aToHex} from '../helpers';
+import {bufferToUrl, hasValue, supportsPassive, u8aToHex} from '../helpers';
 import {emojify} from '../helpers/emoji';
 import {ContactService} from '../services/contact';
 import {ControllerService} from '../services/controller';
@@ -406,11 +406,11 @@ class ConversationController {
             this.domChatElement = document.querySelector('#conversation-chat') as HTMLElement;
 
             // Add custom event handlers
-            this.domChatElement.addEventListener('scroll', throttle(() => {
+            this.domChatElement.addEventListener('scroll', () => {
                 $rootScope.$apply(() => {
                     this.updateScrollJump();
                 });
-            }, 100, this), supportsPassive() ? {passive: true} : false);
+            }, supportsPassive() ? {passive: true} : false);
         }
 
         // Set receiver, conversation and type
@@ -915,12 +915,12 @@ class ConversationController {
     }
 
     /**
-     * Only show the scroll to bottom button if user scrolled more than 10px
+     * Only show the scroll to bottom button if user scrolled more than 1px
      * away from bottom.
      */
     private updateScrollJump(): void {
         const chat = this.domChatElement;
-        this.showScrollJump = chat.scrollHeight - (chat.scrollTop + chat.offsetHeight) > 10;
+        this.showScrollJump = chat.scrollHeight - (chat.scrollTop + chat.offsetHeight) > 1;
     }
 
     /**