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

feat: auto start rough notation animation on slide change #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.Rdata
.httr-oauth
.DS_Store
example_files
example.html
78 changes: 42 additions & 36 deletions _extensions/roughnotation/rough.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,51 @@ document.addEventListener("DOMContentLoaded", function () {
return out;
}

Reveal.addKeyBinding(
{ keyCode: 82, key: "R", description: "Trigger RoughNotation" },
function () {
rn_counter = rn_counter + 1;
function reveal_rough() {
rn_counter = rn_counter + 1;

const slide = Reveal.getCurrentSlide();
const divs = Array.from(slide.querySelectorAll(".rn"));
const new_divs = divs
.filter(function (rn) {
if (rn_counter == 1) {
if (rn.dataset.rnIndex > 1) {
return false;
}
} else {
if (typeof rn.dataset.rnIndex == "undefined") {
return false;
}
if (rn.dataset.rnIndex != rn_counter) {
return false;
}
const slide = Reveal.getCurrentSlide();
const divs = Array.from(slide.querySelectorAll(".rn"));
const new_divs = divs
.filter(function (rn) {
if (rn_counter == 1) {
if (rn.dataset.rnIndex > 1) {
return false;
}
} else {
if (typeof rn.dataset.rnIndex == "undefined") {
return false;
}
return true;
})
.map(function (rn) {
return RoughNotation.annotate(rn, {
type: rn.dataset.rnType || "highlight",
animate: strictly_false(rn.dataset.rnAnimate),
animationDuration: parseInt(rn.dataset.rnAnimationduration) || 800,
color: rn.dataset.rnColor || "#fff17680",
strokeWidth: parseInt(rn.dataset.rnStrokewidth) || 1,
multiline: strictly_false(rn.dataset.rnMultiline),
iterations: parseInt(rn.dataset.rnIterations) || 2,
rtl: !strictly_false(rn.dataset.rnRtl),
});
if (rn.dataset.rnIndex != rn_counter) {
return false;
}
}
return true;
})
.map(function (rn) {
return RoughNotation.annotate(rn, {
type: rn.dataset.rnType || "highlight",
animate: strictly_false(rn.dataset.rnAnimate),
animationDuration: parseInt(rn.dataset.rnAnimationduration) || 800,
color: rn.dataset.rnColor || "#fff17680",
strokeWidth: parseInt(rn.dataset.rnStrokewidth) || 1,
multiline: strictly_false(rn.dataset.rnMultiline),
iterations: parseInt(rn.dataset.rnIterations) || 2,
rtl: !strictly_false(rn.dataset.rnRtl),
});

new_divs.map(function (rn) {
rn.show();
});
}

new_divs.map(function (rn) {
rn.show();
});
}

Reveal.on( 'slidechanged', event => {
reveal_rough(event.currentSlide);
} );

Reveal.addKeyBinding(
{ keyCode: 82, key: "R", description: "Trigger RoughNotation" },
reveal_rough
);
})