Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[livejournal] r19322: LJSUP-8973: Page scroller - keyboard pag...

Committer: gariev
LJSUP-8973: Page scroller - keyboard page navigation

U   trunk/htdocs/js/pagescroller.js
Modified: trunk/htdocs/js/pagescroller.js
===================================================================
--- trunk/htdocs/js/pagescroller.js	2011-06-20 06:54:34 UTC (rev 19321)
+++ trunk/htdocs/js/pagescroller.js	2011-06-20 07:57:53 UTC (rev 19322)
@@ -6,17 +6,18 @@
         for (var i=0; i<entries.length; ++i) {
             // there is no exact equality between offset and scrollTop after call to scrollTo:
             // there may be offset=180.1, scrollTop=180
-            //alert(entries.eq(i).offset().top + ", " + scrollTop);
+            // console.log("entry=" + i + ", entries.eq(i).offset().top=" + entries.eq(i).offset().top + ", scrollTop=" + scrollTop);
             if (entries.eq(i).offset().top-20 > scrollTop) {
                 return i-1;
             }
         }
-        return -1;
+        return entries.length-1;
     }
 
 	function keyCheck(e) {
 
     	if (!entries.length) {
+            // console.log("No entries");
 			return;
 		}
 
@@ -25,16 +26,19 @@
         if (activeElement) {
             var nodeName = activeElement.nodeName.toLowerCase();
             if (nodeName=="input" || nodeName=="textarea" || nodeName=="select") {
+                // console.log("returning from form element: " + nodeName);
                 return;
             }
         }
+        // console.log("Key code = " + e.keyCode);
 
 		var pos;
 		if (e.keyCode === 78) {
 			// next
             var anchor = getCurrentEntry()+1;
+            // console.log("next, anchor=" + anchor + ", entries.length=" + entries.length);
 			if (anchor >= entries.length) {
-				anchor=0;
+				return;
 			}
 			pos = entries.eq(anchor).offset();
 			window.scrollTo(pos.left, pos.top-10);
@@ -42,8 +46,9 @@
 		if (e.keyCode === 80) {
 			//previous
 			var anchor = getCurrentEntry()-1;
+            // console.log("prev, anchor=" + anchor + ", entries.length=" + entries.length);
 			if (anchor < 0) {
-				anchor = entries.length-1;
+                return; 
 			}
 			pos = entries.eq(anchor).offset();
 			window.scrollTo(pos.left, pos.top-10);
@@ -51,6 +56,7 @@
 	}
 
     if (entries.length>1) {
+        // console.log("Installing keyCheck");
 	    jQuery(document).keyup(keyCheck);
     }
 });

Tags: gariev, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments