Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onNavigate function to register event handlers #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions resources/script.js
Expand Up @@ -6,6 +6,16 @@ function currentPosition() {
}


/**
* Register event handlers for slide navigation
*/
var onNavigateHandlers = [];
function onNavigate(fn) {
if (onNavigateHandlers.indexOf(fn) < 0) {
onNavigateHandlers.push(fn);
}
}

/**
* Navigates forward n pages
* If n is negative, we will navigate in reverse
Expand All @@ -23,9 +33,9 @@ function navigate(n) {
document.getElementById('slide-' + position).classList.add('hidden');
document.getElementById('slide-' + nextPosition).classList.remove('hidden');

updateProgress();
updateURL();
updateTabIndex();
for (var i = 0; i < onNavigateHandlers.length; i++) {
onNavigateHandlers[i](nextPosition, numSlides);
}
}


Expand Down Expand Up @@ -111,6 +121,11 @@ function toggleFullScreen() {
}

document.addEventListener('DOMContentLoaded', function () {

onNavigate(updateProgress);
onNavigate(updateURL);
onNavigate(updateTabIndex);

// Update the tabindex to prevent weird slide transitioning
updateTabIndex();

Expand Down