Skip to content

Commit a01924f

Browse files
committed
adjust controls and progress based on mobile viewport size
1 parent edf1240 commit a01924f

4 files changed

Lines changed: 60 additions & 39 deletions

File tree

css/reveal.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,16 @@ $controlsArrowAngleActive: 36deg;
632632
transform: scaleX(0);
633633
}
634634

635+
@media (pointer: coarse) {
636+
.reveal .controls {
637+
font-size: clamp(10px, 2.5vmin, 40px);
638+
}
639+
640+
.reveal .progress {
641+
height: clamp(3px, 0.75vmin, 10px)
642+
}
643+
}
644+
635645
/*********************************************
636646
* SLIDE NUMBER
637647
*********************************************/

dist/reveal.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.mjs

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ var ee = class {
833833
}
834834
}, k = 500, A = 4, se = 6, j = 8, ce = class {
835835
constructor(e) {
836-
this.Reveal = e, this.active = !1, this.activatedCallbacks = [], this.onScroll = this.onScroll.bind(this);
836+
this.Reveal = e, this.active = !1, this.activeProgressBarPage = null, this.activeProgressBarTrigger = null, this.activatedCallbacks = [], this.onScroll = this.onScroll.bind(this);
837837
}
838838
activate() {
839839
if (this.active) return;
@@ -866,7 +866,7 @@ var ee = class {
866866
deactivate() {
867867
if (!this.active) return;
868868
let e = this.Reveal.getState();
869-
this.active = !1, this.viewportElement.removeEventListener("scroll", this.onScroll), this.viewportElement.classList.remove("reveal-scroll"), this.removeProgressBar(), this.Reveal.getSlidesElement().innerHTML = this.slideHTMLBeforeActivation, this.Reveal.sync(), this.Reveal.setState(e), this.slideHTMLBeforeActivation = null;
869+
this.active = !1, this.viewportElement.removeEventListener("scroll", this.onScroll), this.viewportElement.classList.remove("reveal-scroll"), this.pendingScrollRaf && (cancelAnimationFrame(this.pendingScrollRaf), this.pendingScrollRaf = 0), this.removeProgressBar(), this.Reveal.getSlidesElement().innerHTML = this.slideHTMLBeforeActivation, this.Reveal.sync(), this.Reveal.setState(e), this.slideHTMLBeforeActivation = null;
870870
}
871871
toggle(e) {
872872
typeof e == "boolean" ? e ? this.activate() : this.deactivate() : this.isActive() ? this.deactivate() : this.activate();
@@ -887,7 +887,7 @@ var ee = class {
887887
});
888888
}
889889
removeProgressBar() {
890-
this.progressBar && (this.progressBar.remove(), this.progressBar = null);
890+
this.progressBar && (this.progressBar.remove(), this.progressBar = null), this.activeProgressBarPage = null, this.activeProgressBarTrigger = null;
891891
}
892892
layout() {
893893
this.isActive() && (this.syncPages(), this.syncScrollPosition());
@@ -958,33 +958,41 @@ var ee = class {
958958
return e.scrollTriggers = [], e.indexh = parseInt(e.slideElement.getAttribute("data-index-h"), 10), e.indexv = parseInt(e.slideElement.getAttribute("data-index-v"), 10), e;
959959
}
960960
syncProgressBar() {
961-
this.progressBarInner.querySelectorAll(".scrollbar-slide").forEach((e) => e.remove());
961+
this.progressBarInner.querySelectorAll(".scrollbar-slide").forEach((e) => e.remove()), this.activeProgressBarPage = null, this.activeProgressBarTrigger = null, this.getAllPages().forEach((e) => {
962+
e.progressBarSlide = null, e.scrollTriggers.forEach((e) => e.progressBarElement = null);
963+
});
962964
let e = this.viewportElement.scrollHeight, t = this.viewportElement.offsetHeight, n = t / e;
963965
this.progressBarHeight = this.progressBarInner.offsetHeight, this.playheadHeight = Math.max(n * this.progressBarHeight, j), this.progressBarScrollableHeight = this.progressBarHeight - this.playheadHeight;
964966
let r = t / e * this.progressBarHeight, i = Math.min(r / 8, A);
965-
this.progressBarPlayhead.style.height = this.playheadHeight - i + "px", r > se ? this.slideTriggers.forEach((e) => {
967+
this.progressBarPlayhead.style.height = this.playheadHeight - i + "px", r > se && this.slideTriggers.forEach((e) => {
966968
let { page: t } = e;
967-
t.progressBarSlide = document.createElement("div"), t.progressBarSlide.className = "scrollbar-slide", t.progressBarSlide.style.top = e.range[0] * this.progressBarHeight + "px", t.progressBarSlide.style.height = (e.range[1] - e.range[0]) * this.progressBarHeight - i + "px", t.progressBarSlide.classList.toggle("has-triggers", t.scrollTriggers.length > 0), this.progressBarInner.appendChild(t.progressBarSlide), t.scrollTriggerElements = t.scrollTriggers.map((n, r) => {
969+
t.progressBarSlide = document.createElement("div"), t.progressBarSlide.className = "scrollbar-slide", t.progressBarSlide.style.top = e.range[0] * this.progressBarHeight + "px", t.progressBarSlide.style.height = (e.range[1] - e.range[0]) * this.progressBarHeight - i + "px", t.progressBarSlide.classList.toggle("has-triggers", t.scrollTriggers.length > 0), this.progressBarInner.appendChild(t.progressBarSlide), t.scrollTriggers.forEach((n, r) => {
968970
let a = document.createElement("div");
969-
return a.className = "scrollbar-trigger", a.style.top = (n.range[0] - e.range[0]) * this.progressBarHeight + "px", a.style.height = (n.range[1] - n.range[0]) * this.progressBarHeight - i + "px", t.progressBarSlide.appendChild(a), r === 0 && (a.style.display = "none"), a;
971+
a.className = "scrollbar-trigger", a.style.top = (n.range[0] - e.range[0]) * this.progressBarHeight + "px", a.style.height = (n.range[1] - n.range[0]) * this.progressBarHeight - i + "px", t.progressBarSlide.appendChild(a), r === 0 && (a.style.display = "none"), n.progressBarElement = a;
970972
});
971-
}) : this.pages.forEach((e) => e.progressBarSlide = null);
973+
});
972974
}
973975
syncScrollPosition() {
974-
let e = this.viewportElement.offsetHeight, t = e / this.viewportElement.scrollHeight, n = this.viewportElement.scrollTop, r = this.viewportElement.scrollHeight - e, i = Math.max(Math.min(n / r, 1), 0), a = Math.max(Math.min((n + e / 2) / this.viewportElement.scrollHeight, 1), 0), o;
976+
let e = this.viewportElement.offsetHeight, t = e / this.viewportElement.scrollHeight, n = this.viewportElement.scrollTop, r = this.viewportElement.scrollHeight - e, i = Math.max(Math.min(n / r, 1), 0), a = Math.max(Math.min((n + e / 2) / this.viewportElement.scrollHeight, 1), 0), o, s = null;
975977
this.slideTriggers.forEach((e) => {
976978
let { page: n } = e;
977979
i >= e.range[0] - t * 2 && i <= e.range[1] + t * 2 && !n.loaded ? (n.loaded = !0, this.Reveal.slideContent.load(n.slideElement)) : n.loaded && (n.loaded = !1, this.Reveal.slideContent.unload(n.slideElement)), i >= e.range[0] && i <= e.range[1] ? (this.activateTrigger(e), o = e.page) : e.active && this.deactivateTrigger(e);
978980
}), o && o.scrollTriggers.forEach((e) => {
979-
a >= e.range[0] && a <= e.range[1] ? this.activateTrigger(e) : e.active && this.deactivateTrigger(e);
980-
}), this.setProgressBarValue(n / (this.viewportElement.scrollHeight - e));
981-
}
982-
setProgressBarValue(e) {
983-
this.progressBar && (this.progressBarPlayhead.style.transform = `translateY(${e * this.progressBarScrollableHeight}px)`, this.getAllPages().filter((e) => e.progressBarSlide).forEach((e) => {
984-
e.progressBarSlide.classList.toggle("active", e.active === !0), e.scrollTriggers.forEach((t, n) => {
985-
e.scrollTriggerElements[n].classList.toggle("active", e.active === !0 && t.active === !0);
986-
});
987-
}), this.showProgressBar());
981+
a >= e.range[0] && a <= e.range[1] ? (this.activateTrigger(e), s = e) : e.active && this.deactivateTrigger(e);
982+
}), this.setProgressBarValue(n / (this.viewportElement.scrollHeight - e), o, s);
983+
}
984+
setProgressBarValue(e, t = null, n = null) {
985+
if (this.progressBar) {
986+
if (this.progressBarPlayhead.style.transform = `translateY(${e * this.progressBarScrollableHeight}px)`, this.activeProgressBarPage !== t) {
987+
var r, i;
988+
(r = this.activeProgressBarPage) == null || (r = r.progressBarSlide) == null || r.classList.remove("active"), t == null || (i = t.progressBarSlide) == null || i.classList.add("active"), this.activeProgressBarPage = t;
989+
}
990+
if (this.activeProgressBarTrigger !== n) {
991+
var a, o;
992+
(a = this.activeProgressBarTrigger) == null || (a = a.progressBarElement) == null || a.classList.remove("active"), n == null || (o = n.progressBarElement) == null || o.classList.add("active"), this.activeProgressBarTrigger = n;
993+
}
994+
this.showProgressBar();
995+
}
988996
}
989997
showProgressBar() {
990998
this.progressBar.classList.add("visible"), clearTimeout(this.hideProgressBarTimeout), this.Reveal.getConfig().scrollProgress === "auto" && !this.draggingProgressBar && (this.hideProgressBarTimeout = setTimeout(() => {
@@ -1042,7 +1050,9 @@ var ee = class {
10421050
return this.pages.flatMap((e) => [e, ...e.autoAnimatePages || []]);
10431051
}
10441052
onScroll() {
1045-
this.syncScrollPosition(), this.storeScrollPosition();
1053+
this.pendingScrollRaf || (this.pendingScrollRaf = requestAnimationFrame(() => {
1054+
this.pendingScrollRaf = 0, this.syncScrollPosition(), this.storeScrollPosition();
1055+
}));
10461056
}
10471057
get viewportElement() {
10481058
return this.Reveal.getViewportElement();
@@ -1898,15 +1908,15 @@ var pe = class {
18981908
}
18991909
}, I = 40, be = class {
19001910
constructor(e) {
1901-
this.Reveal = e, this.touchStartX = 0, this.touchStartY = 0, this.touchStartCount = 0, this.touchCaptured = !1, this.onPointerDown = this.onPointerDown.bind(this), this.onPointerMove = this.onPointerMove.bind(this), this.onPointerUp = this.onPointerUp.bind(this), this.onTouchStart = this.onTouchStart.bind(this), this.onTouchMove = this.onTouchMove.bind(this), this.onTouchEnd = this.onTouchEnd.bind(this);
1911+
this.Reveal = e, this.touchStartX = 0, this.touchStartY = 0, this.touchStartCount = 0, this.touchCaptured = !1, this.activePointers = /* @__PURE__ */ new Map(), this.onPointerDown = this.onPointerDown.bind(this), this.onPointerMove = this.onPointerMove.bind(this), this.onPointerUp = this.onPointerUp.bind(this), this.onPointerCancel = this.onPointerCancel.bind(this), this.onTouchStart = this.onTouchStart.bind(this), this.onTouchMove = this.onTouchMove.bind(this), this.onTouchEnd = this.onTouchEnd.bind(this);
19021912
}
19031913
bind() {
19041914
let e = this.Reveal.getRevealElement();
1905-
"onpointerdown" in window ? (e.addEventListener("pointerdown", this.onPointerDown, !1), e.addEventListener("pointermove", this.onPointerMove, !1), e.addEventListener("pointerup", this.onPointerUp, !1)) : window.navigator.msPointerEnabled ? (e.addEventListener("MSPointerDown", this.onPointerDown, !1), e.addEventListener("MSPointerMove", this.onPointerMove, !1), e.addEventListener("MSPointerUp", this.onPointerUp, !1)) : (e.addEventListener("touchstart", this.onTouchStart, !1), e.addEventListener("touchmove", this.onTouchMove, !1), e.addEventListener("touchend", this.onTouchEnd, !1));
1915+
"onpointerdown" in window ? (e.addEventListener("pointerdown", this.onPointerDown, !1), e.addEventListener("pointermove", this.onPointerMove, !1), e.addEventListener("pointerup", this.onPointerUp, !1), e.addEventListener("pointercancel", this.onPointerCancel, !1)) : (e.addEventListener("touchstart", this.onTouchStart, !1), e.addEventListener("touchmove", this.onTouchMove, !1), e.addEventListener("touchend", this.onTouchEnd, !1));
19061916
}
19071917
unbind() {
19081918
let e = this.Reveal.getRevealElement();
1909-
e.removeEventListener("pointerdown", this.onPointerDown, !1), e.removeEventListener("pointermove", this.onPointerMove, !1), e.removeEventListener("pointerup", this.onPointerUp, !1), e.removeEventListener("MSPointerDown", this.onPointerDown, !1), e.removeEventListener("MSPointerMove", this.onPointerMove, !1), e.removeEventListener("MSPointerUp", this.onPointerUp, !1), e.removeEventListener("touchstart", this.onTouchStart, !1), e.removeEventListener("touchmove", this.onTouchMove, !1), e.removeEventListener("touchend", this.onTouchEnd, !1);
1919+
e.removeEventListener("pointerdown", this.onPointerDown, !1), e.removeEventListener("pointermove", this.onPointerMove, !1), e.removeEventListener("pointerup", this.onPointerUp, !1), e.removeEventListener("pointercancel", this.onPointerCancel, !1), e.removeEventListener("touchstart", this.onTouchStart, !1), e.removeEventListener("touchmove", this.onTouchMove, !1), e.removeEventListener("touchend", this.onTouchEnd, !1);
19101920
}
19111921
isSwipePrevented(e) {
19121922
if (a(e, "video[controls], audio[controls]")) return !0;
@@ -1936,23 +1946,23 @@ var pe = class {
19361946
onTouchEnd(e) {
19371947
this.touchCaptured && !this.Reveal.slideContent.isAllowedToPlayAudio() && this.Reveal.startEmbeddedContent(this.Reveal.getCurrentSlide()), this.touchCaptured = !1;
19381948
}
1939-
onPointerDown(e) {
1940-
(e.pointerType === e.MSPOINTER_TYPE_TOUCH || e.pointerType === "touch") && (e.touches = [{
1949+
getActiveTouches() {
1950+
return Array.from(this.activePointers.values(), (e) => ({
19411951
clientX: e.clientX,
19421952
clientY: e.clientY
1943-
}], this.onTouchStart(e));
1953+
}));
1954+
}
1955+
onPointerDown(e) {
1956+
e.pointerType === "touch" && (this.activePointers.set(e.pointerId, e), e.touches = this.getActiveTouches(), this.onTouchStart(e));
19441957
}
19451958
onPointerMove(e) {
1946-
(e.pointerType === e.MSPOINTER_TYPE_TOUCH || e.pointerType === "touch") && (e.touches = [{
1947-
clientX: e.clientX,
1948-
clientY: e.clientY
1949-
}], this.onTouchMove(e));
1959+
e.pointerType === "touch" && (this.activePointers.set(e.pointerId, e), e.touches = this.getActiveTouches(), this.onTouchMove(e));
19501960
}
19511961
onPointerUp(e) {
1952-
(e.pointerType === e.MSPOINTER_TYPE_TOUCH || e.pointerType === "touch") && (e.touches = [{
1953-
clientX: e.clientX,
1954-
clientY: e.clientY
1955-
}], this.onTouchEnd(e));
1962+
e.pointerType === "touch" && (this.activePointers.delete(e.pointerId), e.touches = this.getActiveTouches(), this.onTouchEnd(e));
1963+
}
1964+
onPointerCancel(e) {
1965+
e.pointerType === "touch" && (this.activePointers.delete(e.pointerId), e.touches = this.getActiveTouches(), this.onTouchEnd(e));
19561966
}
19571967
}, L = "focus", R = "blur", xe = class {
19581968
constructor(e) {
@@ -2290,11 +2300,12 @@ function z(a, s) {
22902300
g && !f.embedded && document.documentElement.style.setProperty("--vh", window.innerHeight * .01 + "px");
22912301
let n = L.isActive() ? Qe(e, t) : Qe(), r = S;
22922302
Xe(f.width, f.height), D.slides.style.width = n.width + "px", D.slides.style.height = n.height + "px", S = Math.min(n.presentationWidth / n.width, n.presentationHeight / n.height), S = Math.max(S, f.minScale), S = Math.min(S, f.maxScale), S === 1 || L.isActive() ? (D.slides.style.zoom = "", D.slides.style.left = "", D.slides.style.top = "", D.slides.style.bottom = "", D.slides.style.right = "", qe({ layout: "" })) : (D.slides.style.zoom = "", D.slides.style.left = "50%", D.slides.style.top = "50%", D.slides.style.bottom = "auto", D.slides.style.right = "auto", qe({ layout: "translate(-50%, -50%) scale(" + S + ")" }));
2293-
let i = Array.from(D.wrapper.querySelectorAll(C));
2303+
let i = Array.from(D.wrapper.querySelectorAll(C)).filter((e) => e.style.display !== "none"), a = Array(i.length);
22942304
for (let e = 0, t = i.length; e < t; e++) {
22952305
let t = i[e];
2296-
t.style.display !== "none" && (f.center || t.classList.contains("center") ? t.classList.contains("stack") ? t.style.top = 0 : t.style.top = Math.max((n.height - t.scrollHeight) / 2, 0) + "px" : t.style.top = "");
2306+
f.center || t.classList.contains("center") ? t.classList.contains("stack") ? a[e] = 0 : a[e] = Math.max((n.height - t.scrollHeight) / 2, 0) + "px" : a[e] = "";
22972307
}
2308+
for (let e = 0, t = i.length; e < t; e++) i[e].style.top = a[e];
22982309
r !== S && Y({
22992310
type: "resize",
23002311
data: {

0 commit comments

Comments
 (0)