Commits

ben...@pollen  committed 0d51495

fix a little the scrolling.

  • Participants
  • Parent commits b1bf554

Comments (0)

Files changed (1)

File static/js/src/review.js

 
         this.offset = [point.x - pos.x, point.y - pos.y];
         this.pointer = point;
+        var where = this._getWindowScroll(window);
+        this.scroll = [where.left, where.top];
         
-
         // remove text selection
         document.body.focus();
                
             var bottom =  p[1] + self.divComment.outerHeight()
             var right = p[0] + self.divComment.outerWidth();
 
-            T = document.body.scrollTop;
-            L = document.body.scrolLeft;
-        
-            if (bottom > document.body.offsetHeight -15)
-                window.scrollBy(0, bottom); 
-            else if (bottom < 0)
-                window.scrollBy(0, -bottom);
-            if (right > document.body.offsetWidth -15)
-                 window.scrollBy(right, 0);
-            else if (right < 0)
-                window.scrollBy(-right, 0);
+            var where = self._getWindowScroll(window);
+            var scrollX = where.left;
+            var scrollY = where.top;
 
+            if (right > where.width - 15)
+                scrollX = right;
+
+            if (bottom > where.height -15)
+                scrollY = bottom;
+
+            if (scrollX != where.left || scrollY != where.top)
+                window.scrollTo(scrollX, scrollY);
+            self.pointer = point;
         }, 0); 
 
-        this.pointer = pointer(e);
+        
         e.preventDefault();
         e.stopPropagation();
      },
 
     toJSON: function(obj) {
         return obj !== null ? base2.JSON.toString(obj) : null;
+    },
+
+    _getWindowScroll: function(w) {
+    var T, L, W, H;
+    with (w.document) {
+      if (w.document.documentElement && documentElement.scrollTop) {
+        T = documentElement.scrollTop;
+        L = documentElement.scrollLeft;
+      } else if (w.document.body) {
+        T = body.scrollTop;
+        L = body.scrollLeft;
+      }
+      if (w.innerWidth) {
+        W = w.innerWidth;
+        H = w.innerHeight;
+      } else if (w.document.documentElement && documentElement.clientWidth) {
+        W = documentElement.clientWidth;
+        H = documentElement.clientHeight;
+      } else {
+        W = body.offsetWidth;
+        H = body.offsetHeight
+      }
     }
+    return { top: T, left: L, width: W, height: H };
+  }
 });