Browse Source

Added scroll handling to dynamically loaded elements

Rafał Pitoń 10 years ago
parent
commit
2146c7012e

+ 0 - 1
misago/static/misago/css/misago/notifications.less

@@ -17,7 +17,6 @@
     ul {
       margin: 0px;
       max-height: @line-height-computed * 8.75;
-      overflow: auto;
 
       li {
         border-bottom: 1px solid @dropdown-divider-bg;

+ 23 - 8
misago/static/misago/js/misago-scrolling.js

@@ -1,13 +1,28 @@
-$('.scrollable').on('mousewheel', function(e) {
-  var scroll = $(this).scrollTop();
+$(function() {
+  function handle_scroll($element, e) {
+    var scroll = $element.scrollTop();
 
-  if (scroll == 0 && e.deltaY > 0 ) {
-    // block scroll of whole page when user ends scrolling item up
-    e.preventDefault();
+    if (scroll == 0 && e.deltaY > 0 ) {
+      // block scroll of whole page when user ends scrolling item up
+      e.preventDefault();
+    }
+
+    if ($element[0].scrollHeight - $element.innerHeight() - scroll == 0 && e.deltaY < 0 ) {
+      // block scroll of whole page when user ends scrolling item down
+      e.preventDefault();
+    }
   }
 
-  if ($(this)[0].scrollHeight - $(this).innerHeight() - scroll == 0 && e.deltaY < 0 ) {
-    // block scroll of whole page when user ends scrolling item down
-    e.preventDefault();
+  function add_scroll_handlers() {
+    $('.scrollable').each(function() {
+      if ($(this).data('misago-scroolable') == undefined) {
+        $(this).data('misago-scroolable', true);
+        $(this).on('mousewheel', function(e) {
+          handle_scroll($(this), e);
+        });
+      }
+    });
   }
+
+  $.misago_dom().change(add_scroll_handlers);
 });