forked from GithubBackups/vichan
expand-video.js: format
This commit is contained in:
parent
d9a333a69f
commit
85b03c0fb0
@ -2,26 +2,32 @@
|
|||||||
/* Note: This code expects the global variable configRoot to be set. */
|
/* Note: This code expects the global variable configRoot to be set. */
|
||||||
|
|
||||||
if (typeof _ == 'undefined') {
|
if (typeof _ == 'undefined') {
|
||||||
var _ = function(a) { return a; };
|
var _ = function(a) {
|
||||||
|
return a;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupVideo(thumb, url) {
|
function setupVideo(thumb, url) {
|
||||||
if (thumb.videoAlreadySetUp) return;
|
if (thumb.videoAlreadySetUp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
thumb.videoAlreadySetUp = true;
|
thumb.videoAlreadySetUp = true;
|
||||||
|
|
||||||
var video = null;
|
let video = null;
|
||||||
var videoContainer, videoHide;
|
let videoContainer, videoHide;
|
||||||
var expanded = false;
|
let expanded = false;
|
||||||
var hovering = false;
|
let hovering = false;
|
||||||
var loop = true;
|
let loop = true;
|
||||||
var loopControls = [document.createElement("span"), document.createElement("span")];
|
let loopControls = [document.createElement("span"), document.createElement("span")];
|
||||||
var fileInfo = thumb.parentNode.querySelector(".fileinfo");
|
let fileInfo = thumb.parentNode.querySelector(".fileinfo");
|
||||||
var mouseDown = false;
|
let mouseDown = false;
|
||||||
|
|
||||||
function unexpand() {
|
function unexpand() {
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
expanded = false;
|
expanded = false;
|
||||||
if (video.pause) video.pause();
|
if (video.pause) {
|
||||||
|
video.pause();
|
||||||
|
}
|
||||||
videoContainer.style.display = "none";
|
videoContainer.style.display = "none";
|
||||||
thumb.style.display = "inline";
|
thumb.style.display = "inline";
|
||||||
video.style.maxWidth = "inherit";
|
video.style.maxWidth = "inherit";
|
||||||
@ -32,7 +38,9 @@ function setupVideo(thumb, url) {
|
|||||||
function unhover() {
|
function unhover() {
|
||||||
if (hovering) {
|
if (hovering) {
|
||||||
hovering = false;
|
hovering = false;
|
||||||
if (video.pause) video.pause();
|
if (video.pause) {
|
||||||
|
video.pause();
|
||||||
|
}
|
||||||
videoContainer.style.display = "none";
|
videoContainer.style.display = "none";
|
||||||
video.style.maxWidth = "inherit";
|
video.style.maxWidth = "inherit";
|
||||||
video.style.maxHeight = "inherit";
|
video.style.maxHeight = "inherit";
|
||||||
@ -129,16 +137,18 @@ function setupVideo(thumb, url) {
|
|||||||
expanded = false;
|
expanded = false;
|
||||||
hovering = true;
|
hovering = true;
|
||||||
|
|
||||||
var docRight = document.documentElement.getBoundingClientRect().right;
|
let docRight = document.documentElement.getBoundingClientRect().right;
|
||||||
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
let thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
||||||
var maxWidth = docRight - thumbRight - 20;
|
let maxWidth = docRight - thumbRight - 20;
|
||||||
if (maxWidth < 250) maxWidth = 250;
|
if (maxWidth < 250) {
|
||||||
|
maxWidth = 250;
|
||||||
|
}
|
||||||
|
|
||||||
video.style.position = "fixed";
|
video.style.position = "fixed";
|
||||||
video.style.right = "0px";
|
video.style.right = "0px";
|
||||||
video.style.top = "0px";
|
video.style.top = "0px";
|
||||||
var docRight = document.documentElement.getBoundingClientRect().right;
|
docRight = document.documentElement.getBoundingClientRect().right;
|
||||||
var thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
thumbRight = thumb.querySelector("img, video").getBoundingClientRect().right;
|
||||||
video.style.maxWidth = maxWidth + "px";
|
video.style.maxWidth = maxWidth + "px";
|
||||||
video.style.maxHeight = "100%";
|
video.style.maxHeight = "100%";
|
||||||
video.style.pointerEvents = "none";
|
video.style.pointerEvents = "none";
|
||||||
@ -161,10 +171,18 @@ function setupVideo(thumb, url) {
|
|||||||
thumb.addEventListener("wheel", function(e) {
|
thumb.addEventListener("wheel", function(e) {
|
||||||
if (setting("videohover")) {
|
if (setting("videohover")) {
|
||||||
var volume = setting("videovolume");
|
var volume = setting("videovolume");
|
||||||
if (e.deltaY > 0) volume -= 0.1;
|
if (e.deltaY > 0) {
|
||||||
if (e.deltaY < 0) volume += 0.1;
|
volume -= 0.1;
|
||||||
if (volume < 0) volume = 0;
|
}
|
||||||
if (volume > 1) volume = 1;
|
if (e.deltaY < 0) {
|
||||||
|
volume += 0.1;
|
||||||
|
}
|
||||||
|
if (volume < 0) {
|
||||||
|
volume = 0;
|
||||||
|
}
|
||||||
|
if (volume > 1) {
|
||||||
|
volume = 1;
|
||||||
|
}
|
||||||
if (video != null) {
|
if (video != null) {
|
||||||
video.muted = (volume == 0);
|
video.muted = (volume == 0);
|
||||||
video.volume = volume;
|
video.volume = volume;
|
||||||
@ -202,15 +220,17 @@ function setupVideo(thumb, url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupVideosIn(element) {
|
function setupVideosIn(element) {
|
||||||
var thumbs = element.querySelectorAll("a.file");
|
let thumbs = element.querySelectorAll("a.file");
|
||||||
for (var i = 0; i < thumbs.length; i++) {
|
for (let i = 0; i < thumbs.length; i++) {
|
||||||
if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) {
|
if (/\.webm$|\.mp4$/.test(thumbs[i].pathname)) {
|
||||||
setupVideo(thumbs[i], thumbs[i].href);
|
setupVideo(thumbs[i], thumbs[i].href);
|
||||||
} else {
|
} else {
|
||||||
var m = thumbs[i].search.match(/\bv=([^&]*)/);
|
let m = thumbs[i].search.match(/\bv=([^&]*)/);
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
var url = decodeURIComponent(m[1]);
|
let url = decodeURIComponent(m[1]);
|
||||||
if (/\.webm$|\.mp4$/.test(url)) setupVideo(thumbs[i], url);
|
if (/\.webm$|\.mp4$/.test(url)) {
|
||||||
|
setupVideo(thumbs[i], url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,20 +238,23 @@ function setupVideosIn(element) {
|
|||||||
|
|
||||||
onready(function(){
|
onready(function(){
|
||||||
// Insert menu from settings.js
|
// Insert menu from settings.js
|
||||||
if (typeof settingsMenu != "undefined" && typeof Options == "undefined")
|
if (typeof settingsMenu != "undefined" && typeof Options == "undefined") {
|
||||||
document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]);
|
document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// Setup Javascript events for videos in document now
|
// Setup Javascript events for videos in document now
|
||||||
setupVideosIn(document);
|
setupVideosIn(document);
|
||||||
|
|
||||||
// Setup Javascript events for videos added by updater
|
// Setup Javascript events for videos added by updater
|
||||||
if (window.MutationObserver) {
|
if (window.MutationObserver) {
|
||||||
var observer = new MutationObserver(function(mutations) {
|
let observer = new MutationObserver(function(mutations) {
|
||||||
for (var i = 0; i < mutations.length; i++) {
|
for (let i = 0; i < mutations.length; i++) {
|
||||||
var additions = mutations[i].addedNodes;
|
let additions = mutations[i].addedNodes;
|
||||||
if (additions == null) continue;
|
if (additions == null) {
|
||||||
for (var j = 0; j < additions.length; j++) {
|
continue;
|
||||||
var node = additions[j];
|
}
|
||||||
|
for (let j = 0; j < additions.length; j++) {
|
||||||
|
let node = additions[j];
|
||||||
if (node.nodeType == 1) {
|
if (node.nodeType == 1) {
|
||||||
setupVideosIn(node);
|
setupVideosIn(node);
|
||||||
}
|
}
|
||||||
@ -241,4 +264,3 @@ onready(function(){
|
|||||||
observer.observe(document.body, {childList: true, subtree: true});
|
observer.observe(document.body, {childList: true, subtree: true});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user