summary refs log tree commit diff
path: root/syweb/webclient/js/ng-infinite-scroll-matrix.js
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-11-14 11:16:50 +0000
committerMark Haines <mark.haines@matrix.org>2014-11-14 11:16:50 +0000
commite903c941cb1bed18026f00ed1d3495a8d172f13a (patch)
tree894da7441d913361b70da4cc13cd73ead86d2e67 /syweb/webclient/js/ng-infinite-scroll-matrix.js
parentRemove unused 'context' variables to appease pyflakes (diff)
parentAdd notification-service unit tests. (diff)
downloadsynapse-e903c941cb1bed18026f00ed1d3495a8d172f13a.tar.xz
Merge branch 'develop' into request_logging
Conflicts:
	setup.py
	synapse/storage/_base.py
	synapse/util/async.py
Diffstat (limited to 'syweb/webclient/js/ng-infinite-scroll-matrix.js')
-rw-r--r--syweb/webclient/js/ng-infinite-scroll-matrix.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/syweb/webclient/js/ng-infinite-scroll-matrix.js b/syweb/webclient/js/ng-infinite-scroll-matrix.js
new file mode 100644
index 0000000000..045ec8d93e
--- /dev/null
+++ b/syweb/webclient/js/ng-infinite-scroll-matrix.js
@@ -0,0 +1,63 @@
+/* ng-infinite-scroll - v1.0.0 - 2013-02-23 
+  Matrix: Modified to support scrolling UP to get infinite loading and to listen
+  to scroll events on the PARENT element, not the window.
+*/
+var mod;
+
+mod = angular.module('infinite-scroll', []);
+
+mod.directive('infiniteScroll', [
+  '$rootScope', '$window', '$timeout', function($rootScope, $window, $timeout) {
+    return {
+      link: function(scope, elem, attrs) {
+        var checkWhenEnabled, handler, scrollDistance, scrollEnabled;
+        $window = angular.element($window);
+        scrollDistance = 0;
+        if (attrs.infiniteScrollDistance != null) {
+          scope.$watch(attrs.infiniteScrollDistance, function(value) {
+            return scrollDistance = parseInt(value, 10);
+          });
+        }
+        scrollEnabled = true;
+        checkWhenEnabled = false;
+        if (attrs.infiniteScrollDisabled != null) {
+          scope.$watch(attrs.infiniteScrollDisabled, function(value) {
+            scrollEnabled = !value;
+            if (scrollEnabled && checkWhenEnabled) {
+              checkWhenEnabled = false;
+              return handler();
+            }
+          });
+        }
+        handler = function() {
+          var elementTop, remaining, shouldScroll, windowTop;
+          windowTop = 0;
+          elementTop = elem.offset().top;
+          shouldScroll = elementTop >= 0; // top of list is at the top of the window or further down the page
+          if (shouldScroll && scrollEnabled) {
+            if ($rootScope.$$phase) {
+              return scope.$eval(attrs.infiniteScroll);
+            } else {
+              return scope.$apply(attrs.infiniteScroll);
+            }
+          } else if (shouldScroll) {
+            return checkWhenEnabled = true;
+          }
+        };
+        elem.parent().on('scroll', handler);
+        scope.$on('$destroy', function() {
+          return elem.parent().off('scroll', handler);
+        });
+        return $timeout((function() {
+          if (attrs.infiniteScrollImmediateCheck) {
+            if (scope.$eval(attrs.infiniteScrollImmediateCheck)) {
+              return handler();
+            }
+          } else {
+            return handler();
+          }
+        }), 0);
+      }
+    };
+  }
+]);