summaryrefslogtreecommitdiff
path: root/2024-06-18-guix-social/reveal.js/js/controllers/focus.js
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2024-06-24 13:49:08 -0400
committerDavid Thompson <dthompson2@worcester.edu>2024-06-24 13:52:17 -0400
commitd283f7e661e14d6ae1881fe803e5b4f1ed0689ff (patch)
tree84d3811c6dcb7d7f02aecadad7b2dfacce83bd4f /2024-06-18-guix-social/reveal.js/js/controllers/focus.js
parent3d9dcd3099fb252fa35697148fbbd541eb9eecc9 (diff)
Add 2024 Guix social talk.HEADmaster
Diffstat (limited to '2024-06-18-guix-social/reveal.js/js/controllers/focus.js')
-rw-r--r--2024-06-18-guix-social/reveal.js/js/controllers/focus.js103
1 files changed, 103 insertions, 0 deletions
diff --git a/2024-06-18-guix-social/reveal.js/js/controllers/focus.js b/2024-06-18-guix-social/reveal.js/js/controllers/focus.js
new file mode 100644
index 0000000..3e68c3f
--- /dev/null
+++ b/2024-06-18-guix-social/reveal.js/js/controllers/focus.js
@@ -0,0 +1,103 @@
+import { closest } from '../utils/util.js'
+
+/**
+ * Manages focus when a presentation is embedded. This
+ * helps us only capture keyboard from the presentation
+ * a user is currently interacting with in a page where
+ * multiple presentations are embedded.
+ */
+
+const STATE_FOCUS = 'focus';
+const STATE_BLUR = 'blur';
+
+export default class Focus {
+
+ constructor( Reveal ) {
+
+ this.Reveal = Reveal;
+
+ this.onRevealPointerDown = this.onRevealPointerDown.bind( this );
+ this.onDocumentPointerDown = this.onDocumentPointerDown.bind( this );
+
+ }
+
+ /**
+ * Called when the reveal.js config is updated.
+ */
+ configure( config, oldConfig ) {
+
+ if( config.embedded ) {
+ this.blur();
+ }
+ else {
+ this.focus();
+ this.unbind();
+ }
+
+ }
+
+ bind() {
+
+ if( this.Reveal.getConfig().embedded ) {
+ this.Reveal.getRevealElement().addEventListener( 'pointerdown', this.onRevealPointerDown, false );
+ }
+
+ }
+
+ unbind() {
+
+ this.Reveal.getRevealElement().removeEventListener( 'pointerdown', this.onRevealPointerDown, false );
+ document.removeEventListener( 'pointerdown', this.onDocumentPointerDown, false );
+
+ }
+
+ focus() {
+
+ if( this.state !== STATE_FOCUS ) {
+ this.Reveal.getRevealElement().classList.add( 'focused' );
+ document.addEventListener( 'pointerdown', this.onDocumentPointerDown, false );
+ }
+
+ this.state = STATE_FOCUS;
+
+ }
+
+ blur() {
+
+ if( this.state !== STATE_BLUR ) {
+ this.Reveal.getRevealElement().classList.remove( 'focused' );
+ document.removeEventListener( 'pointerdown', this.onDocumentPointerDown, false );
+ }
+
+ this.state = STATE_BLUR;
+
+ }
+
+ isFocused() {
+
+ return this.state === STATE_FOCUS;
+
+ }
+
+ destroy() {
+
+ this.Reveal.getRevealElement().classList.remove( 'focused' );
+
+ }
+
+ onRevealPointerDown( event ) {
+
+ this.focus();
+
+ }
+
+ onDocumentPointerDown( event ) {
+
+ let revealElement = closest( event.target, '.reveal' );
+ if( !revealElement || revealElement !== this.Reveal.getRevealElement() ) {
+ this.blur();
+ }
+
+ }
+
+} \ No newline at end of file