Recenter if no scrollbars during non-autofit 2up resize
authorMichael Ang <mang@archive.org>
Fri, 14 Aug 2009 01:01:15 +0000 (01:01 +0000)
committerMichael Ang <mang@archive.org>
Fri, 14 Aug 2009 01:01:15 +0000 (01:01 +0000)
GnuBook/GnuBook.js

index 16df10a..09c291c 100644 (file)
@@ -143,11 +143,26 @@ GnuBook.prototype.init = function() {
         } else {
             //console.log('drawing 2 page view');
             
-            // We only need to recalculate and center if in autofit
+            // We only need to prepare again in autofit (size of spread changes)
             if (e.data.twoPage.autofit) {
                 e.data.prepareTwoPageView();
                 e.data.twoPageCenterView();
-            }            
+            } else {
+                // Re-center if the scrollbars have disappeared
+                var center = e.data.twoPageGetViewCenter();
+                var doRecenter = false;
+                if (e.data.twoPage.totalWidth < $('#GBcontainer').attr('clientWidth')) {
+                    center.percentageX = 0.5;
+                    doRecenter = true;
+                }
+                if (e.data.twoPage.totalHeight < $('#GBcontainer').attr('clientHeight')) {
+                    center.percentageY = 0.5;
+                    doRecenter = true;
+                }
+                if (doRecenter) {
+                    e.data.twoPageCenterView(center.percentageX, center.percentageY);
+                }
+            }
         }
     });