Skip to content

Commit

Permalink
add more keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
medicalwei committed Nov 2, 2011
1 parent 4c044cc commit eeff7aa
Showing 1 changed file with 49 additions and 26 deletions.
75 changes: 49 additions & 26 deletions cleanslide.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
page = 0;
subpage = 0;
var page = 0;
var subpage = 0;
var blocks;

$(document).ready(function(){
blocks = $('body>*');

Expand Down Expand Up @@ -33,33 +35,16 @@ $(document).ready(function(){
});

$(window).keyup(function(event){
var current = blocks.eq(page);

switch (event.keyCode)
{
case 40:
innerBottom = current.position().top + (current.outerHeight()-current.height()) / 2 + current.height();
console.log(innerBottom);
if (innerBottom > $(window).height()) { // if the block does not reach the screen bottom
subpage += 1;
} else if (page < (blocks.size()-1)) {
page += 1;
subpage = 0;
}
break;

case 38:
if (subpage > 0) {
subpage -= 1;
} else if (page > 0) {
page -= 1;
subpage = 0;
}
break;
case 38: case 37: pageUp(false); break; // up, left
case 32: case 40: case 39: pageDown(false); break; // down, right, space
case 33: pageUp(true); break; // PgUp
case 34: pageDown(true); break; // PgDn
case 36: goHome(); break; // Home
case 35: goToEnd(); break; // End
}

blocks.eq(page).setToCenter(subpage);
window.location.hash = "#" + page;
console.log(event.keyCode);
});

// get hash
Expand All @@ -71,3 +56,41 @@ $(document).ready(function(){
blocks.eq(page).setToCenter(subpage);
});

pageDown = function(toNextSection) {
var current = blocks.eq(page);

innerBottom = current.position().top + (current.outerHeight()-current.height()) / 2 + current.height();
if (!toNextSection && innerBottom > $(window).height()) { // if the block does not reach the screen bottom
subpage += 1;
} else if (page < (blocks.size()-1)) {
page += 1;
subpage = 0;
}
blocks.eq(page).setToCenter(subpage);
window.location.hash = "#" + page;
}

pageUp = function(toPrevSection) {
if (!toPrevSection && subpage > 0) {
subpage -= 1;
} else if (page > 0) {
page -= 1;
subpage = 0;
}
blocks.eq(page).setToCenter(subpage);
window.location.hash = "#" + page;
}

goHome = function() {
page = 0;
subpage = 0;
blocks.eq(page).setToCenter(subpage);
window.location.hash = "#" + page;
}

goToEnd = function() {
page = blocks.size()-1;
subpage = 0;
blocks.eq(page).setToCenter(subpage);
window.location.hash = "#" + page;
}

0 comments on commit eeff7aa

Please sign in to comment.