Commit 3115491a authored by Vadim Makeev's avatar Vadim Makeev

Merge pull request #147 from pepelsbey/master

Key handling refactoring
parents 25382541 1731ffbf
......@@ -798,30 +798,34 @@ window.shower = window.shower || (function(window, document, undefined) {
}, false);
document.addEventListener('keydown', function(e) {
var currentSlideNumber,
slide;
// Shortcut for alt, ctrl and meta keys
if (e.altKey || e.ctrlKey || e.metaKey) { return; }
currentSlideNumber = shower.getCurrentSlideNumber();
slide = shower.slideList[currentSlideNumber];
var currentSlideNumber = shower.getCurrentSlideNumber(),
slide = shower.slideList[ currentSlideNumber !== -1 ? currentSlideNumber : 0 ],
slideNumber;
switch (e.which) {
case 116: // F5
case 80: // P Alt Cmd
if (shower.isListMode() && e.altKey && e.metaKey) {
e.preventDefault();
slideNumber = slide.number;
shower.go(slideNumber);
shower.enterSlideMode();
shower.showPresenterNotes(slideNumber);
slide.timing && slide.initTimer(shower);
}
break;
case 116: // F5 (Shift)
e.preventDefault();
if (shower.isListMode()) {
var slideNumber = e.shiftKey ? currentSlideNumber : 0,
slide;
slideNumber = e.shiftKey ? slide.number : 0;
// Warning: go must be before enterSlideMode.
// Otherwise there is a bug in Chrome
shower.go(slideNumber);
shower.enterSlideMode();
shower.showPresenterNotes(slideNumber);
slide = shower.slideList[currentSlideNumber];
slide.timing && slide.initTimer(shower);
} else {
shower.enterListMode();
......@@ -831,12 +835,11 @@ window.shower = window.shower || (function(window, document, undefined) {
case 13: // Enter
if (shower.isListMode() && -1 !== currentSlideNumber) {
e.preventDefault();
shower.enterSlideMode();
shower.showPresenterNotes(currentSlideNumber);
if (slide.timing) {
slide.initTimer(shower);
}
slide.timing && slide.initTimer(shower);
}
break;
......@@ -852,10 +855,9 @@ window.shower = window.shower || (function(window, document, undefined) {
case 37: // Left
case 72: // H
case 75: // K
if (shower.isSlideMode()) {
if (e.altKey || e.ctrlKey || e.metaKey) { return; }
e.preventDefault();
shower._turnPreviousSlide();
}
break;
case 34: // PgDown
......@@ -863,32 +865,25 @@ window.shower = window.shower || (function(window, document, undefined) {
case 39: // Right
case 76: // L
case 74: // J
if (shower.isSlideMode()) {
if (e.altKey || e.ctrlKey || e.metaKey) { return; }
e.preventDefault();
shower._turnNextSlide();
}
break;
case 36: // Home
if (shower.isSlideMode()) {
e.preventDefault();
shower.first();
}
break;
case 35: // End
if (shower.isSlideMode()) {
e.preventDefault();
shower.last();
}
break;
case 9: // Tab = +1; Shift + Tab = -1
case 32: // Space = +1; Shift + Space = -1
if (shower.isSlideMode()) {
case 9: // Tab (Shift)
case 32: // Space (Shift)
e.preventDefault();
shower[e.shiftKey ? '_turnPreviousSlide' : '_turnNextSlide']();
}
break;
default:
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment