first attempt at drag-to-pan. does not work in IE.
authorrajbot <raj@archive.org>
Sat, 14 Feb 2009 13:13:33 +0000 (13:13 +0000)
committerrajbot <raj@archive.org>
Mon, 2 Mar 2009 22:06:51 +0000 (22:06 +0000)
GnuBook/GnuBook.js

index 6b7b6cf..c319984 100644 (file)
@@ -99,6 +99,10 @@ GnuBook.prototype.init = function() {
             e.data.prepareTwoPageView();
         }
     });
+    
+    $('.GBpagediv1up').bind('mousedown', this, function(e) {
+        //console.log('mousedown!');
+    });
 
     if (1 == this.mode) {
         this.resizePageView();
@@ -188,6 +192,36 @@ GnuBook.prototype.drawLeafs = function() {
     }
 }
 
+// setDragHandler1up()
+//______________________________________________________________________________
+GnuBook.prototype.setDragHandler1up = function(div) {
+
+    $(div).bind('mousedown', function(e) {
+        var startX    = e.pageX;
+        var startY    = e.pageY;
+        var startTop  = $('#GBcontainer').attr('scrollTop');
+        var startLeft =  $('#GBcontainer').attr('scrollLeft');
+        //console.log('mousedown at ' + e.pageY);
+        
+        $(this).bind('mousemove', function(ee) {
+            //console.log('mousemove ' + startY);
+            $('#GBcontainer').attr('scrollTop',  startTop  + (startY - ee.pageY));
+            $('#GBcontainer').attr('scrollLeft', startLeft + (startX - ee.pageX));
+        });
+        
+        $(this).bind('mouseup', function(ee) {
+            //console.log('mouseup');
+            $(this).unbind('mousemove mouseup');                    
+        });
+        
+        return false; //stops the image from being dragged off
+    });
+    
+    $(div).bind('mouseout', function(e) {
+        $(this).unbind('mousemove mouseup');
+        //console.log('mouseout');
+    });
+}
 
 // drawLeafsOnePage()
 //______________________________________________________________________________
@@ -264,6 +298,8 @@ GnuBook.prototype.drawLeafsOnePage = function() {
             $(div).css('height', height+'px');
             //$(div).text('loading...');
             
+            this.setDragHandler1up(div);
+            
             $('#GBpageview').append(div);
 
             var img = document.createElement("img");