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

Added Video Support #137

Open
wants to merge 30 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/baguetteBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@

function pauseAnyVideoPlaying(){
[].forEach.call(imagesElements, function(imageElement) {
if(imageElement.getElementsByTagName('video').length > 0){
if (imageElement.getElementsByTagName('video').length > 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before brackets.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, do you want me to remove the spaces before brackets

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you should always use it as per the rest of the codebase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, fixing

imageElement.getElementsByTagName('video')[0].pause();
}
});
Expand All @@ -487,13 +487,13 @@
var imageContainer = imagesElements[index];
var galleryItem = currentGallery[index];
var isVideo = false;
if(imageContainer !== undefined) {
if typeof imageContainer !== 'undefined' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong now; you are missing the parentheses.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing

isVideo = videoRegex.test(galleryItem.imageElement.href);
}

// Return if the index exceeds prepared images in the overlay
// or if the current gallery has been changed / closed
if (imageContainer === undefined || galleryItem === undefined) {
if (typeof imageContainer === 'undefined'|| typeof galleryItem === 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space before ||

return;
}

Expand All @@ -516,17 +516,16 @@
// Get element reference, optional caption and source path
var imageElement = galleryItem.imageElement;
var thumbnailElement = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could change this whole thing into a one liner

var thumbnailElement = isvideo ? imageElement.getElementsByTagName('video')[0] : imageElement.getElementsByTagName('img')[0];

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you fixing

if(isVideo) {
if (isVideo) {
thumbnailElement = imageElement.getElementsByTagName('video')[0];
}
else {
} else {
thumbnailElement = imageElement.getElementsByTagName('img')[0];
}
var imageCaption = typeof options.captions === 'function' ?
options.captions.call(currentGallery, imageElement) :
imageElement.getAttribute('data-caption') || imageElement.title;
var imageSrc = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(isVideo) {
if (isVideo) {
imageSrc = getVideoSrc(imageElement);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use else in the same line as the brackets.

else {
Expand All @@ -549,7 +548,7 @@
}
imageContainer.appendChild(figure);

if(isVideo){
if (isVideo){
// Prepare gallery video element
var video = create('video');
//video.onload = function(){
Expand Down Expand Up @@ -715,7 +714,7 @@
slider.style.transform = slider.style.webkitTransform = 'translate3d(' + offset + ',0,0)'
: slider.style.left = offset;
}
if(imagesElements[currentIndex].getElementsByTagName('video').length > 0) {
if (imagesElements[currentIndex].getElementsByTagName('video').length > 0) {
imagesElements[currentIndex].getElementsByTagName('video')[0].play();
}
}
Expand Down