Fix down/Page down behavior in dimp viewport
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 14 Jan 2011 23:18:37 +0000 (16:18 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 14 Jan 2011 23:24:29 +0000 (16:24 -0700)
imp/js/dimpbase.js
imp/js/viewport.js

index e9edfd0..f2b5a81 100644 (file)
@@ -99,11 +99,13 @@ var DimpBase = {
     },
 
     // num = (integer) See absolute.
-    // absolute = Is num an absolute row number - from 1 -> page_size (true) -
-    //            or a relative change from the current selected value (false)
+    // absolute = (boolean) Is num an absolute row number - from 1 ->
+    //            page_size (true) - or a relative change from the current
+    //            selected value (false)
     //            If no current selected value, the first message in the
     //            current viewport is selected.
-    moveSelected: function(num, absolute)
+    // bottom = (boolean) Make selected appear at bottom?
+    moveSelected: function(num, absolute, bottom)
     {
         var curr, curr_row, row, row_data, sel;
 
@@ -141,7 +143,7 @@ var DimpBase = {
         if (row.size()) {
             row_data = row.get('dataob').first();
             if (!curr_row || row_data.imapuid != curr_row.imapuid) {
-                this.viewport.scrollTo(row_data.VP_rownum);
+                this.viewport.scrollTo(row_data.VP_rownum, { bottom: bottom });
                 this.viewport.select(row, { delay: 0.3 });
             }
         } else {
@@ -1869,7 +1871,7 @@ var DimpBase = {
                     this.msgSelect(row.VP_domid, { shift: true });
                 }
             } else {
-                this.moveSelected(kc == Event.KEY_UP ? -1 : 1);
+                this.moveSelected(kc == Event.KEY_UP ? -1 : 1, false, kc == Event.KEY_DOWN);
             }
             e.stop();
             break;
@@ -1911,7 +1913,7 @@ var DimpBase = {
                         break;
                     }
                 }
-                this.moveSelected(move);
+                this.moveSelected(move, false, kc == Event.KEY_PAGEDOWN);
                 e.stop();
             }
             break;
index 7f09f3b..29fb3f0 100644 (file)
@@ -350,30 +350,37 @@ var ViewPort = Class.create({
     },
 
     // rownum = (integer) Row number
-    // opts = (Object) [noupdate, top] TODO
+    // opts = (Object) [bottom, noupdate, top] TODO
     scrollTo: function(rownum, opts)
     {
-        var s = this.scroller;
+        var s = this.scroller,
+            to = null;
         opts = opts || {};
 
         s.noupdate = opts.noupdate;
 
         switch (this.isVisible(rownum)) {
         case -1:
-            s.moveScroll(rownum - 1);
+            to = rownum - 1;
             break;
 
         case 0:
             if (opts.top) {
-                s.moveScroll(rownum - 1);
+                to = rownum - 1;
             }
             break;
 
         case 1:
-            s.moveScroll(Math.min(rownum - 1, this.getMetaData('total_rows') - this.getPageSize()));
+            to = opts.bottom
+                ? Math.max(0, rownum - this.getPageSize())
+                : Math.min(rownum - 1, this.getMetaData('total_rows') - this.getPageSize());
             break;
         }
 
+        if (to !== null) {
+            s.moveScroll(to);
+        }
+
         s.noupdate = false;
     },