From df36d56fa71605bf540b359ccfd48faf6d5d6bcc Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Sat, 19 Dec 2015 15:44:34 +0100 Subject: [PATCH] Implement infinite scrolling I't not perfect but it's a start. --- index.html | 3 ++- js/glowingbear.js | 11 +++++++++++ js/whenscrolled-directive.js | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 js/whenscrolled-directive.js diff --git a/index.html b/index.html index bbbef49..249a2b8 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,7 @@ + @@ -264,7 +265,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel -
+
  • diff --git a/js/glowingbear.js b/js/glowingbear.js index 8102930..e2f48fc 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -539,6 +539,17 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', return connection.fetchMoreLines(numLines); }; + $scope.infiniteScroll = function() { + // Check if we are already fetching + if ($rootScope.loadingLines) { + return; + } + var buffer = models.getActiveBuffer(); + if (!buffer.allLinesFetched) { + $scope.fetchMoreLines(); + } + }; + $rootScope.updateBufferBottom = function(bottom) { var eob = document.getElementById("end-of-buffer"); var bl = document.getElementById('bufferlines'); diff --git a/js/whenscrolled-directive.js b/js/whenscrolled-directive.js new file mode 100644 index 0000000..39a43e5 --- /dev/null +++ b/js/whenscrolled-directive.js @@ -0,0 +1,21 @@ +(function() { +'use strict'; + +var weechat = angular.module('weechat'); +weechat.directive('whenScrolled', function() { + return function(scope, elm, attr) { + var raw = elm[0]; + + var fun = function() { + if (raw.scrollTop === 0) { + scope.$apply(attr.whenScrolled); + } + }; + + elm.bind('scroll', function() { + _.debounce(fun, 200)(); + }); + }; +}); + +})();