From baeb87807f92a39eb9474f21dca22996f00ecb63 Mon Sep 17 00:00:00 2001 From: adamnorris Date: Tue, 22 Oct 2019 13:18:21 +0100 Subject: [PATCH 1/3] stop autoplay when carousel is focused --- js/player.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/player.js b/js/player.js index 1867497a..fc6fee9f 100644 --- a/js/player.js +++ b/js/player.js @@ -140,6 +140,7 @@ proto.activatePlayer = function() { } this.player.play(); this.element.addEventListener( 'mouseenter', this ); + this.element.addEventListener( 'focus', this ); }; // Player API, don't hate the ... thanks I know where the door is @@ -182,6 +183,17 @@ proto.onmouseleave = function() { this.element.removeEventListener( 'mouseleave', this ); }; +// ----- focus/blur ----- // +proto.onfocus = function() { + this.player.pause(); + this.element.addEventListener( 'blur', this ); +}; + +proto.onblur = function() { + this.player.unpause(); + this.element.removeEventListener( 'blur', this ); +}; + // ----- ----- // Flickity.Player = Player; From 195a81030a22a6e047187fa7155746cf39e3c205 Mon Sep 17 00:00:00 2001 From: adamnorris Date: Tue, 22 Oct 2019 14:00:15 +0100 Subject: [PATCH 2/3] prevent carousel playing when buttons are focused --- js/prev-next-button.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/prev-next-button.js b/js/prev-next-button.js index 058eef1d..1f52b3b9 100644 --- a/js/prev-next-button.js +++ b/js/prev-next-button.js @@ -72,6 +72,8 @@ PrevNextButton.prototype._create = function() { PrevNextButton.prototype.activate = function() { this.bindStartEvent( this.element ); this.element.addEventListener( 'click', this ); + this.element.addEventListener( 'focus', this ); + // console.log(this.parent.element); // add to DOM this.parent.element.appendChild( this.element ); }; @@ -127,6 +129,22 @@ PrevNextButton.prototype.onclick = function() { this.parent[ method ](); }; +PrevNextButton.prototype.onfocus = function() { + if ( !this.isEnabled ) { + return; + } + this.parent.stopPlayer(); + this.element.addEventListener( 'blur', this ); +}; + +PrevNextButton.prototype.onblur = function() { + if ( !this.isEnabled ) { + return; + } + this.parent.playPlayer(); + this.element.removeEventListener( 'blur', this ); +}; + // ----- ----- // PrevNextButton.prototype.enable = function() { From 1f005ce899d56c9eb2d3fb86de38143a3871bd70 Mon Sep 17 00:00:00 2001 From: adamnorris Date: Tue, 22 Oct 2019 14:02:38 +0100 Subject: [PATCH 3/3] stop player on prev next buttons --- js/prev-next-button.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/prev-next-button.js b/js/prev-next-button.js index 1f52b3b9..a3ea2ddd 100644 --- a/js/prev-next-button.js +++ b/js/prev-next-button.js @@ -73,7 +73,6 @@ PrevNextButton.prototype.activate = function() { this.bindStartEvent( this.element ); this.element.addEventListener( 'click', this ); this.element.addEventListener( 'focus', this ); - // console.log(this.parent.element); // add to DOM this.parent.element.appendChild( this.element ); };