2013-11-09 04:11:22 -05:00
|
|
|
function setupVideo(thumb, url) {
|
|
|
|
var video = null;
|
|
|
|
var videoContainer, videoHide;
|
|
|
|
var expanded = false;
|
|
|
|
var hovering = false;
|
2013-11-10 22:09:12 -05:00
|
|
|
var loop = true;
|
|
|
|
var loopControls = [document.createElement("span"), document.createElement("span")];
|
|
|
|
var fileInfo = thumb.parentNode.querySelector(".fileinfo");
|
2013-11-14 02:17:09 -05:00
|
|
|
var mouseDown = false;
|
2013-11-09 04:11:22 -05:00
|
|
|
|
|
|
|
function unexpand() {
|
|
|
|
if (expanded) {
|
|
|
|
expanded = false;
|
|
|
|
if (video.pause) video.pause();
|
|
|
|
videoContainer.style.display = "none";
|
|
|
|
thumb.style.display = "inline";
|
2013-11-16 13:30:04 -05:00
|
|
|
video.style.maxWidth = "inherit";
|
|
|
|
video.style.maxHeight = "inherit";
|
2013-11-09 04:11:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function unhover() {
|
|
|
|
if (hovering) {
|
|
|
|
hovering = false;
|
|
|
|
if (video.pause) video.pause();
|
2013-11-16 13:30:04 -05:00
|
|
|
videoContainer.style.display = "none";
|
|
|
|
video.style.maxWidth = "inherit";
|
|
|
|
video.style.maxHeight = "inherit";
|
2013-11-09 04:11:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVideo() {
|
|
|
|
if (video == null) {
|
|
|
|
video = document.createElement("video");
|
|
|
|
video.src = url;
|
2013-11-10 22:09:12 -05:00
|
|
|
video.loop = loop;
|
2013-11-09 04:11:22 -05:00
|
|
|
video.innerText = "Your browser does not support HTML5 video.";
|
|
|
|
|
|
|
|
videoHide = document.createElement("img");
|
|
|
|
videoHide.src = configRoot + "cc/collapse.gif";
|
|
|
|
videoHide.alt = "[ - ]";
|
2013-11-11 06:11:52 -05:00
|
|
|
videoHide.title = "Collapse video";
|
2013-11-11 07:03:48 -05:00
|
|
|
videoHide.style.marginLeft = "-15px";
|
|
|
|
videoHide.style.cssFloat = "left";
|
2013-11-16 01:33:48 -05:00
|
|
|
videoHide.addEventListener("click", unexpand, false);
|
2013-11-09 04:11:22 -05:00
|
|
|
|
|
|
|
videoContainer = document.createElement("div");
|
2013-11-11 07:03:48 -05:00
|
|
|
videoContainer.style.paddingLeft = "15px";
|
2013-11-16 13:30:04 -05:00
|
|
|
videoContainer.style.display = "none";
|
2013-11-09 04:11:22 -05:00
|
|
|
videoContainer.appendChild(videoHide);
|
|
|
|
videoContainer.appendChild(video);
|
|
|
|
thumb.parentNode.insertBefore(videoContainer, thumb.nextSibling);
|
2013-11-11 06:11:52 -05:00
|
|
|
|
2013-11-14 02:17:09 -05:00
|
|
|
// Dragging to the left collapses the video
|
|
|
|
video.addEventListener("mousedown", function(e) {
|
|
|
|
if (e.button == 0) mouseDown = true;
|
|
|
|
}, false);
|
|
|
|
video.addEventListener("mouseup", function(e) {
|
|
|
|
if (e.button == 0) mouseDown = false;
|
|
|
|
}, false);
|
|
|
|
video.addEventListener("mouseenter", function(e) {
|
|
|
|
mouseDown = false;
|
|
|
|
}, false);
|
|
|
|
video.addEventListener("mouseout", function(e) {
|
|
|
|
if (mouseDown && e.clientX - video.getBoundingClientRect().left <= 0) {
|
|
|
|
unexpand();
|
|
|
|
}
|
|
|
|
mouseDown = false;
|
|
|
|
}, false);
|
2013-11-09 04:11:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-10 07:57:45 -05:00
|
|
|
thumb.addEventListener("click", function(e) {
|
2013-11-09 04:11:22 -05:00
|
|
|
if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
|
|
|
getVideo();
|
|
|
|
expanded = true;
|
|
|
|
hovering = false;
|
|
|
|
|
|
|
|
video.style.position = "static";
|
2013-11-16 13:30:04 -05:00
|
|
|
video.style.pointerEvents = "inherit";
|
2013-11-09 04:11:22 -05:00
|
|
|
video.style.display = "inline";
|
|
|
|
videoHide.style.display = "inline";
|
|
|
|
videoContainer.style.display = "block";
|
2013-11-12 07:47:53 -05:00
|
|
|
videoContainer.style.position = "static";
|
2013-11-09 04:11:22 -05:00
|
|
|
thumb.style.display = "none";
|
|
|
|
|
2014-03-04 19:45:53 -05:00
|
|
|
video.muted = (setting("videovolume") == 0);
|
|
|
|
video.volume = setting("videovolume");
|
2013-11-09 04:11:22 -05:00
|
|
|
video.controls = true;
|
2013-11-16 02:24:27 -05:00
|
|
|
if (video.readyState == 0) {
|
2013-11-16 13:30:04 -05:00
|
|
|
video.addEventListener("loadedmetadata", expand2, false);
|
2013-11-16 02:24:27 -05:00
|
|
|
} else {
|
2013-11-16 13:30:04 -05:00
|
|
|
setTimeout(expand2, 0);
|
2013-11-16 02:24:27 -05:00
|
|
|
}
|
2013-11-09 04:11:22 -05:00
|
|
|
video.play();
|
2013-11-10 07:57:45 -05:00
|
|
|
e.preventDefault();
|
2013-11-09 04:11:22 -05:00
|
|
|
}
|
2013-11-10 07:57:45 -05:00
|
|
|
}, false);
|
2013-11-09 04:11:22 -05:00
|
|
|
|
2013-11-16 13:30:04 -05:00
|
|
|
function expand2() {
|
|
|
|
video.style.maxWidth = "100%";
|
|
|
|
video.style.maxHeight = window.innerHeight + "px";
|
|
|
|
var bottom = video.getBoundingClientRect().bottom;
|
|
|
|
if (bottom > window.innerHeight) {
|
|
|
|
window.scrollBy(0, bottom - window.innerHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-10 07:57:45 -05:00
|
|
|
thumb.addEventListener("mouseover", function(e) {
|
2013-11-09 04:11:22 -05:00
|
|
|
if (setting("videohover")) {
|
|
|
|
getVideo();
|
|
|
|
expanded = false;
|
|
|
|
hovering = true;
|
|
|
|
|
2013-11-16 01:33:48 -05:00
|
|
|
var docRight = document.documentElement.getBoundingClientRect().right;
|
2013-11-09 19:35:35 -05:00
|
|
|
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
|
|
|
var maxWidth = docRight - thumbRight - 20;
|
|
|
|
if (maxWidth < 250) maxWidth = 250;
|
|
|
|
|
2013-11-09 04:11:22 -05:00
|
|
|
video.style.position = "fixed";
|
|
|
|
video.style.right = "0px";
|
|
|
|
video.style.top = "0px";
|
2013-11-16 01:33:48 -05:00
|
|
|
var docRight = document.documentElement.getBoundingClientRect().right;
|
2013-11-09 19:35:35 -05:00
|
|
|
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
|
|
|
video.style.maxWidth = maxWidth + "px";
|
2013-11-09 04:11:22 -05:00
|
|
|
video.style.maxHeight = "100%";
|
2013-11-09 19:35:35 -05:00
|
|
|
video.style.pointerEvents = "none";
|
2013-11-09 04:11:22 -05:00
|
|
|
|
|
|
|
video.style.display = "inline";
|
|
|
|
videoHide.style.display = "none";
|
|
|
|
videoContainer.style.display = "inline";
|
2013-11-12 07:47:53 -05:00
|
|
|
videoContainer.style.position = "fixed";
|
2013-11-09 04:11:22 -05:00
|
|
|
|
2014-03-04 19:45:53 -05:00
|
|
|
video.muted = (setting("videovolume") == 0);
|
|
|
|
video.volume = setting("videovolume");
|
2013-11-09 04:11:22 -05:00
|
|
|
video.controls = false;
|
|
|
|
video.play();
|
|
|
|
}
|
2013-11-10 07:57:45 -05:00
|
|
|
}, false);
|
2013-11-09 04:11:22 -05:00
|
|
|
|
2013-11-10 07:57:45 -05:00
|
|
|
thumb.addEventListener("mouseout", unhover, false);
|
2013-11-10 22:09:12 -05:00
|
|
|
|
|
|
|
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);
|
2013-11-11 07:03:48 -05:00
|
|
|
loopControls[i].style.whiteSpace = "nowrap";
|
2013-11-10 22:09:12 -05:00
|
|
|
fileInfo.appendChild(document.createTextNode(" "));
|
|
|
|
fileInfo.appendChild(loopControls[i]);
|
|
|
|
}
|
2013-11-09 04:11:22 -05:00
|
|
|
}
|
|
|
|
|
2014-02-22 13:05:07 -05:00
|
|
|
function setupVideosIn(element) {
|
|
|
|
var thumbs = element.querySelectorAll("a.file");
|
2013-11-09 04:11:22 -05:00
|
|
|
for (var i = 0; i < thumbs.length; i++) {
|
|
|
|
if (/\.webm$/.test(thumbs[i].pathname)) {
|
|
|
|
setupVideo(thumbs[i], thumbs[i].href);
|
|
|
|
} else {
|
|
|
|
var m = thumbs[i].search.match(/\bv=([^&]*)/);
|
|
|
|
if (m != null) {
|
|
|
|
var url = decodeURIComponent(m[1]);
|
|
|
|
if (/\.webm$/.test(url)) setupVideo(thumbs[i], url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-22 13:05:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (window.addEventListener) window.addEventListener("load", function(e) {
|
|
|
|
document.body.insertBefore(settingsMenu, document.body.firstChild);
|
|
|
|
setupVideosIn(document);
|
|
|
|
if (window.MutationObserver) {
|
|
|
|
var observer = new MutationObserver(function(mutations) {
|
|
|
|
for (var i = 0; i < mutations.length; i++) {
|
|
|
|
var additions = mutations[i].addedNodes;
|
|
|
|
if (additions == null) continue;
|
|
|
|
for (var j = 0; j < additions.length; j++) {
|
|
|
|
var node = additions[j];
|
|
|
|
if (node.nodeType == 1) {
|
|
|
|
setupVideosIn(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
observer.observe(document.body, {childList: true, subtree: true});
|
|
|
|
}
|
2013-11-10 04:56:45 -05:00
|
|
|
}, false);
|
2014-02-22 13:05:07 -05:00
|
|
|
|