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

captions background opacity #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 24 additions & 0 deletions views/player/js/captionsDisplay.jade
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ script.
}
}

function setCaptionBgOpacityIfExists() {
const storedBgOpacity = localStorage.getItem("storedBgOpacity");

if(storedBgOpacity) {
subtitlesBgOpacity = storedBgOpacity;
$('.plyr__caption').css("background", `rgba(0, 0, 0, ${storedBgOpacity}`);
}
}

function adjustFontSize(direction) {

const currentLineHeight = $('.plyr__caption').css('line-height');
Expand Down Expand Up @@ -65,3 +74,18 @@ script.

subtitlesLineHeight = newLineHeightWithPx;
}

function adjustCaptionsBackground (direction) {
let bgColors, bgAlpha;
const currentBgOpacity = $('.plyr__caption').css('background');
bgColors = currentBgOpacity.split(',');
bgAlpha = bgColors[3] ? bgColors[3].split(')')[0] : bgColors[3] = 1;

const newBgOpacity = parseFloat(bgAlpha) + (direction === 'increase' ? 0.15 : -0.15);

// Saving the new background opacity into localStorage.
localStorage.setItem("storedBgOpacity", newBgOpacity);
subtitlesBgOpacity = newBgOpacity;

$('.plyr__caption').css("background", `rgba(0, 0, 0, ${newBgOpacity}`);
}
13 changes: 12 additions & 1 deletion views/player/player.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ block content
button.btn#decreaseSize Subtitle Text Size -
button.btn#increaseLineHeight Subtitle Spacing +
button.btn#decreaseLineHeight Subtitle Spacing -
button.btn#darkBg Subtitle Background Opacity +
button.btn#lightBg Subtitle Background Opacity -
button.btn#showHideControls Hide Text
.downloadLinks
a.btn.startAnotherTranscription(href='/') Start Another Transcription
Expand Down Expand Up @@ -81,7 +83,7 @@ block content
l = console.log;

let player;
let subtitlesFontSize, subtitlesLineHeight;
let subtitlesFontSize, subtitlesLineHeight, subtitlesBgOpacity;

const language = '#{processingData.language}';
const languagesToLoop = !{JSON.stringify(languagesToLoop)};
Expand Down Expand Up @@ -135,6 +137,14 @@ block content
adjustLineHeight('decrease');
});

$('#lightBg').click(function (event) {
adjustCaptionsBackground('decrease');
});

$('#darkBg').click(function (event) {
adjustCaptionsBackground('increase');
});

console.log("ready!");
var controls =
[
Expand Down Expand Up @@ -171,6 +181,7 @@ block content
// without this timeout it doesn't work properly
setTimeout(function(){
setStoredLineHeightAndFontSizeIfExists();
setCaptionBgOpacityIfExists();
}, 200)

});
Expand Down