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

fix: 1476-Video sound keeps playing after closing the popup it's in #1554

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Changes from 2 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
18 changes: 18 additions & 0 deletions game/static/game/js/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
var 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
Expand Down Expand Up @@ -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('"', '')
Expand All @@ -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)
Expand Down