From 86b9884939586ebd98f4c17a41ca780f31d9ea9e Mon Sep 17 00:00:00 2001 From: Abdelrahman Deghedy Date: Fri, 15 Dec 2023 14:39:45 +0000 Subject: [PATCH] fix: 1476-Video sound keeps playing after closing the popup it's in (#1554) * Close Video after popup close * Merge branch 'master' into master * Replace var with const * Merge branch 'master' of https://github.com/AbdelrahmanDeghedy/rapid-router * Merge branch 'master' into master Co-Authored-By: Abdelrahman Co-Authored-By: Florian Aucomte <33633200+faucomte97@users.noreply.github.com> --- game/static/game/js/drawing.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/game/static/game/js/drawing.js b/game/static/game/js/drawing.js index 806551491..b14f6bb24 100644 --- a/game/static/game/js/drawing.js +++ b/game/static/game/js/drawing.js @@ -1013,6 +1013,14 @@ ocargo.Drawing.translate = function (coordinate) { return new ocargo.Coordinate(coordinate.x, GRID_HEIGHT - 1 - coordinate.y) } +// A Function used to stop the iframe video +function stopVideo() { + // https://gist.github.com/cferdinandi/9044694 + const video = document.getElementsByClassName("video"); + const iframeSrc = video[0].src; + video[0].src = iframeSrc; +} + /* This is the function that starts the pop-up. Buttons should be passed in separately to the function instead of concatenating @@ -1073,6 +1081,11 @@ ocargo.Drawing.startPopup = function ( const regexID = /id=\"*\w+_\w+\"/ + // Close the video on pressing the top right close button + $("#close-modal").click(function () { + stopVideo(); + }); + for (let i = 0; i < buttons.length; i++) { // get id with regex by stripping the html content let currentID = buttons[i].match(regexID)[0].slice(3).replaceAll('"', '') @@ -1088,6 +1101,11 @@ ocargo.Drawing.startPopup = function ( currentButton.attr("onclick", currentLink) } + // Close the video on the play button + currentButton.click(function () { + stopVideo(); + }); + // first level shouldn't have prev_button // and last level shouldn't have next_button if (currentButton.attr("onclick")) buttonDiv.append(currentButton)