J and K now jump between posts





By popular demand: J and K now jump between posts on the Dashboard.

Works great with endless scrolling.

<script type="text/javascript">
    // Key commands
	document.onkeydown = function(e) { 
	    if (! key_commands_are_suspended) {
    	    if (! e) var e = window.event;
    	    var code = e.charCode ? e.charCode : e.keyCode;
    	    if (! e.shiftKey && ! e.ctrlKey && ! e.altKey && ! e.metaKey) {
        	    if (code == Event.KEY_LEFT) {
        	        if ($('previous_page_link')) location.href = $('previous_page_link').href;
        	    } else if (code == Event.KEY_RIGHT) {
        	        if ($('next_page_link')) location.href = $('next_page_link').href;
        	    } else if (code == 74 || code == 75) {
        	        var post_positions = new Hash();        	        
        	        $('new_post').nextSiblings().each(function(post){
        	            if (post.id) post_positions.set(post.id, post.offsetTop);
        	        });
        	        
        	        var go_to_position = 0;
        	        
        	        post_positions.each(function(pair){
        	            var post_id = pair.key;
        	            var post_position = pair.value;
        	            var current_position = document.viewport.getScrollOffsets().top + 7;
        	            
        	            if (code == 74) {
        	                // Next
        	                if (
        	                    post_position > current_position &&
        	                    (post_position < go_to_position || ! go_to_position)
        	                ) {
            	                go_to_position = post_position;
            	            }
    	                } else if (code == 75) {
    	                    // Previous
        	                if (
        	                    post_position < current_position &&
        	                    post_position > go_to_position
        	                ) {
            	                go_to_position = post_position;
            	            }
    	                }
        	        });
        	        
        	        window.scrollTo(0, go_to_position - 7);
        	    }
	        }
        }
    }
</script>