Skip to content

Commit

Permalink
neater slides js
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Matter committed Jul 20, 2022
1 parent d233466 commit b07e62a
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/clld_document_plugin/static/clld-slides.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
function nextSlide() {
var target = $('.slide.active').next('.slide');
if (target.length == 0) {
target = $('.slide:first');
function changeSlide(direction="forward") {
var dict = {
"back": "first",
"forward": "last"
}
if (direction=="back") {
var target = $('.slide.active').prev('.slide');
} else {
var target = $('.slide.active').next('.slide');
}
$('.slide.active').removeClass('active');
target.addClass('active');
$('html, body').scrollTop(target.offset().top - 40);
}

function previousSlide() {
var target = $('.slide.active').prev('.slide');
if (target.length == 0) {
target = $('.slide:last');
target = $('.slide:'+dict[direction]);
}
$('.slide.active').removeClass('active');
target.addClass('active');
$('html, body').scrollTop(target.offset().top -40);
$('html, body').scrollTop(target.offset().top - 40);
}


window.addEventListener("keydown", (e) => {
if (e.key === "ArrowLeft") {
previousSlide();
changeSlide("back");
} else if (e.key === "ArrowRight") {
nextSlide();
changeSlide();
}
})

$(".next").click(function() {
nextSlide();
changeSlide();
});

$(".previous").click(function() {
previousSlide();
});
changeSlide("back");
});

0 comments on commit b07e62a

Please sign in to comment.