loop controls on main page
This commit is contained in:
parent
bcdedcb28a
commit
9c335764c4
@ -3,6 +3,9 @@ function setupVideo(thumb, url) {
|
|||||||
var videoContainer, videoHide;
|
var videoContainer, videoHide;
|
||||||
var expanded = false;
|
var expanded = false;
|
||||||
var hovering = false;
|
var hovering = false;
|
||||||
|
var loop = true;
|
||||||
|
var loopControls = [document.createElement("span"), document.createElement("span")];
|
||||||
|
var fileInfo = thumb.parentNode.querySelector(".fileinfo");
|
||||||
|
|
||||||
function unexpand() {
|
function unexpand() {
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
@ -25,7 +28,7 @@ function setupVideo(thumb, url) {
|
|||||||
if (video == null) {
|
if (video == null) {
|
||||||
video = document.createElement("video");
|
video = document.createElement("video");
|
||||||
video.src = url;
|
video.src = url;
|
||||||
video.loop = true;
|
video.loop = loop;
|
||||||
video.innerText = "Your browser does not support HTML5 video.";
|
video.innerText = "Your browser does not support HTML5 video.";
|
||||||
video.addEventListener("click", function(e) {
|
video.addEventListener("click", function(e) {
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
@ -104,6 +107,30 @@ function setupVideo(thumb, url) {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
thumb.addEventListener("mouseout", unhover, false);
|
thumb.addEventListener("mouseout", unhover, false);
|
||||||
|
|
||||||
|
function setupLoopControl(i) {
|
||||||
|
loopControls[i].addEventListener("click", function(e) {
|
||||||
|
loop = (i != 0);
|
||||||
|
thumb.href = thumb.href.replace(/([\?&])loop=\d+/, "$1loop=" + i);
|
||||||
|
if (video != null) {
|
||||||
|
video.loop = loop;
|
||||||
|
if (loop && video.currentTime >= video.duration) {
|
||||||
|
video.currentTime = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loopControls[i].style.fontWeight = "bold";
|
||||||
|
loopControls[1-i].style.fontWeight = "inherit";
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
loopControls[0].textContent = "[play once]";
|
||||||
|
loopControls[1].textContent = "[loop]";
|
||||||
|
loopControls[1].style.fontWeight = "bold";
|
||||||
|
for (var i = 0; i < 2; i++) {
|
||||||
|
setupLoopControl(i);
|
||||||
|
fileInfo.appendChild(document.createTextNode(" "));
|
||||||
|
fileInfo.appendChild(loopControls[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.addEventListener) window.addEventListener("load", function(e) {
|
if (window.addEventListener) window.addEventListener("load", function(e) {
|
||||||
|
@ -7,10 +7,9 @@ if (window.addEventListener) window.addEventListener("load", function(e) {
|
|||||||
function setupLoopLink(i) {
|
function setupLoopLink(i) {
|
||||||
loopLinks[i].addEventListener("click", function(e) {
|
loopLinks[i].addEventListener("click", function(e) {
|
||||||
video.loop = (i != 0);
|
video.loop = (i != 0);
|
||||||
if (i == 1 && video.currentTime >= video.duration) {
|
if (i != 0 && video.currentTime >= video.duration) {
|
||||||
video.currentTime = 0;
|
video.currentTime = 0;
|
||||||
}
|
}
|
||||||
video.play();
|
|
||||||
loopLinks[i].style.fontWeight = "bold";
|
loopLinks[i].style.fontWeight = "bold";
|
||||||
loopLinks[1-i].style.fontWeight = "inherit";
|
loopLinks[1-i].style.fontWeight = "inherit";
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user