Widget:Flipflop: Skillnad mellan sidversioner
Hoppa till navigering
Hoppa till sök
Harri (diskussion | bidrag) typos, autoplay and text for buttons |
Harri (diskussion | bidrag) Ingen redigeringssammanfattning |
||
| Rad 1: | Rad 1: | ||
<style> | <style> | ||
.flipflopButton { | |||
color: #36b; | |||
font-weight: bold; | |||
cursor: pointer; | |||
} | |||
.flipflopButton[disabled], .flipflopButton:disabled { | |||
color: grey; | |||
cursor: default; | |||
} | |||
article.flipflop-book-instance { | article.flipflop-book-instance { | ||
display: flex; | display: flex; | ||
| Rad 62: | Rad 72: | ||
<p>Your browser does not support the video tag.</p> | <p>Your browser does not support the video tag.</p> | ||
</video> | </video> | ||
<div id="playback-speed" style="text-align: center;margin-top: 15px;"> | |||
<b>Uppspelningshastighet: </b> | |||
<button class="flipflopButton speed-button" value=0.25>x0.25</button> | |||
<button class="flipflopButton speed-button" value=0.50>x0.5</button> | |||
<button class="flipflopButton speed-button" value=0.75>x0.75</button> | |||
<button class="flipflopButton speed-button" value=1.00>x1</button> | |||
</div> | |||
</div> | </div> | ||
</div> | </div> | ||
| Rad 462: | Rad 479: | ||
leftBtn.textContent = "← Föregående" | leftBtn.textContent = "← Föregående" | ||
leftBtn.style.cssText = "height:100%;" | leftBtn.style.cssText = "height:100%;" | ||
leftBtn.className = "flipflopButton" | |||
const rightBtn = document.createElement("button") | const rightBtn = document.createElement("button") | ||
rightBtn.textContent = "Följande →" | rightBtn.textContent = "Följande →" | ||
rightBtn.style.cssText = "height:100%;" | rightBtn.style.cssText = "height:100%;" | ||
rightBtn.className = "flipflopButton" | |||
const imgDiv = document.createElement("div") | |||
imgDiv.style.cssText = "width:200px; text-align:center;" | |||
const leftImg = document.createElement("img") | const leftImg = document.createElement("img") | ||
leftImg.src = page.currentPageEl.imageLeft | leftImg.src = page.currentPageEl.imageLeft | ||
leftImg.style.cssText = "height:150px; width:auto;" | leftImg.style.cssText = "height:150px; width:auto;" | ||
const | const textDiv = document.createElement("div") | ||
textDiv.style.cssText = "width:200px; text-align:center;" | |||
textDiv.textContent = page.currentPageEl.textLeft | |||
const playBtn = document.createElement("button") | const playBtn = document.createElement("button") | ||
playBtn.textContent = "▶ Spela video" | playBtn.textContent = "▶ Spela video" | ||
playBtn.style.cssText = "height:100%; width:auto; max-height:150px;" | playBtn.style.cssText = "height:100%; width:auto; max-height:150px;" | ||
playBtn.className = "playBtn" | playBtn.className = "flipflopButton playBtn" | ||
playBtn.onclick = function () { | playBtn.onclick = function () { | ||
// Reset old states of playbackRate buttons | |||
resetSpeedButtons(); | |||
setVideo(video, page.bookIndex) | setVideo(video, page.bookIndex) | ||
modal.style.display = "block"; | modal.style.display = "block"; | ||
| Rad 482: | Rad 506: | ||
article.appendChild(leftBtn) | article.appendChild(leftBtn) | ||
article.appendChild( | imgDiv.appendChild(leftImg) | ||
article.appendChild( | article.appendChild(imgDiv) | ||
article.appendChild(textDiv) | |||
article.appendChild(playBtn) | article.appendChild(playBtn) | ||
article.appendChild(rightBtn) | article.appendChild(rightBtn) | ||
| Rad 534: | Rad 559: | ||
// Get the <span> element that closes the modal | // Get the <span> element that closes the modal | ||
var span = document.getElementsByClassName("close")[0]; | var span = document.getElementsByClassName("close")[0]; | ||
// Get all buttons that change playbackRate | |||
var speedBtns = document.querySelectorAll('.speed-button'); | |||
// When user click speed buttons call function to change playbackRate | |||
speedBtns.forEach(button => button.addEventListener("click", changeSpeed(button))); | |||
function changeSpeed(button) { | |||
return function() { | |||
// Reset old states of playbackRate buttons | |||
resetSpeedButtons(); | |||
video.playbackRate = button.value; | |||
// Make button look like its pressed | |||
button.disabled = true; | |||
} | |||
} | |||
function resetSpeedButtons() { | |||
speedBtns.forEach(button => button.disabled = false); | |||
} | |||
// When the user clicks on <span> (x), close the modal | // When the user clicks on <span> (x), close the modal | ||
| Rad 549: | Rad 594: | ||
bodyContent.style.zIndex = 0; | bodyContent.style.zIndex = 0; | ||
} | } | ||
} | } | ||
</script> | </script> | ||