Skip to content

Commit

Permalink
Merge pull request #23 from regebro/goto-function
Browse files Browse the repository at this point in the history
Add a goto function
  • Loading branch information
regebro authored Oct 7, 2017
2 parents 82c8444 + de48d4f commit 2dbdde6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
3 changes: 3 additions & 0 deletions HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ No changes yet

- Add file css for styling slides of console. [Alberto Sartori]

- Added a G shortcut to Goto a slide number.
[Based on work by Frederik Möllers]


1.3 - 2015-04-28
----------------
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ scrolling. If there is, it will instead scroll down one page.
text needs scrolling. <left>, <up> and <page up> will move to the previous
<slide.

<g> Will ask for a slide number and then move to that slide.

The preview is based on the assumption that the presentation is linear and
that the next slide is well, the next slide. If it isn't and you move around
the presentation by clicking with the mouse, then the preview will not be
Expand Down
37 changes: 28 additions & 9 deletions js/impressConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'loading' : 'initalisiere',
'ready' : 'Bereit',
'moving' : 'in Bewegung',
'useAMPM' : false
'useAMPM' : false,
'gotoSlideNo': 'Gehe zur Foliennummer' // By Google translate
};
break;
case 'en':
Expand All @@ -41,7 +42,8 @@
'loading' : 'Loading',
'ready' : 'Ready',
'moving' : 'Moving',
'useAMPM' : false
'useAMPM' : false,
'gotoSlideNo': 'Go to slide number:'
};
break;
}
Expand Down Expand Up @@ -207,6 +209,20 @@
consoleWindow.timerStart = new Date();
};

var gotoSlide = function (event) {
var target = event.view.prompt("Enter slide number");

if (isNaN(target)) {
var goto_status = impress().goto(target);
} else {
// goto(0) goes to step-1, so substract
var goto_status = impress().goto(parseInt(target) - 1);
}
if (goto_status === false) {
event.view.alert("Slide not found: '" + target + "'");
}
};

// Show a clock
var clockTick = function () {
var now = new Date();
Expand Down Expand Up @@ -239,22 +255,22 @@
}
};

var registerKeyEvent = function(keyCodes, handler, window) {
if (window === undefined) {
window = consoleWindow;
var registerKeyEvent = function(keyCodes, handler, wnd) {
if (wnd === undefined) {
wnd = consoleWindow;
}

// prevent default keydown action when one of supported key is pressed
window.document.addEventListener("keydown", function ( event ) {
wnd.document.addEventListener("keydown", function ( event ) {
if ( !event.ctrlKey && !event.altKey && !event.shiftKey && !event.metaKey && keyCodes.indexOf(event.keyCode) !== -1) {
event.preventDefault();
}
}, false);

// trigger impress action on keyup
window.document.addEventListener("keyup", function ( event ) {
wnd.document.addEventListener("keyup", function ( event ) {
if ( !event.ctrlKey && !event.altKey && !event.shiftKey && !event.metaKey && keyCodes.indexOf(event.keyCode) !== -1) {
handler();
handler(event);
event.preventDefault();
}
}, false);
Expand Down Expand Up @@ -315,7 +331,7 @@
consoleWindow.document.write(consoleTemplate.replace("{{cssFile}}", cssFile).replace(/{{.*?}}/gi, function (x){ return lang[x.substring(2, x.length-2)]; }));
consoleWindow.document.title = 'Speaker Console (' + document.title + ')';
consoleWindow.impress = window.impress;
// We set this flag so we can detect it later, to prevent infinite popups.
// We set this flag so we can d etect it later, to prevent infinite popups.
consoleWindow.isconsoleWindow = true;
// Set the onload function:
consoleWindow.onload = consoleOnLoad;
Expand All @@ -333,6 +349,9 @@
registerKeyEvent([32], spaceHandler);
// 82: R
registerKeyEvent([82], timerReset);
// 71: G
registerKeyEvent([71], gotoSlide, consoleWindow);
registerKeyEvent([71], gotoSlide, window);

// Cleanup
consoleWindow.onbeforeunload = function() {
Expand Down

0 comments on commit 2dbdde6

Please sign in to comment.