-
Notifications
You must be signed in to change notification settings - Fork 430
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
anjnkmr
wants to merge
30
commits into
feimosi:dev
Choose a base branch
from
anjnkmr:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added Video Support #137
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
dc68d00
Added Video Support
a84b2bb
Added Video Support
a341970
Added Video Support
6b5ec5f
Added Video Support
e4b95f7
Added Video Support
662130e
Added Video Support
fd0bb45
Added Video Support
ef8639d
Removed Console Logs
1ef2c62
Removed Console Logs
24935f8
Removed Console Logs
7f5f62d
Removing Dist File
9827746
Removed Dist Files
3828e6d
Removed Dist Files
9a17e2b
Removed Dist Files
8f558e4
Removing Unmodified Files
4f05c46
Removing Unmodified Files
8d6b47d
Reverted changes
8f9faf1
Revereted Changes
0034778
Reverted Changes
c49d9f4
Reverted Changes
87ac750
Updating Linting Errors
39e4152
Removed unecessary empty space
12b0eeb
Updated Linting Warnings
af7da8b
Fixed the issues mentioned by @XhmikosR
250e5a3
Fixed the issues mentioned by @XhmikosR #2
acf93a1
Fixed the issues mentioned by @XhmikosR #3
f8d7c97
Fixed the issues mentioned by @XhmikosR #4
44e4819
Fixed the issues mentioned by @XhmikosR #5 (Merged)
ef25913
Update index.html
a4cb9b8
Update baguetteBox.js
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,8 +62,10 @@ | |
var touch = {}; | ||
// If set to true ignore touch events because animation was already fired | ||
var touchFlag = false; | ||
// Regex pattern to match image files | ||
var regex = /.+\.(gif|jpe?g|png|webp)/i; | ||
// Regex pattern to match image & video files | ||
var regex = /.+\.(gif|jpe?g|png|webp|mp4|webm)/i; | ||
// Pattern to match only videos | ||
var videoRegex = /.+\.(mp4|webm)/i; | ||
// Object of all used galleries | ||
var data = {}; | ||
// Array containing temporary images DOM elements | ||
|
@@ -467,21 +469,36 @@ | |
options.afterHide(); | ||
} | ||
}, 500); | ||
|
||
pauseAnyVideoPlaying(); | ||
|
||
documentLastFocus.focus(); | ||
} | ||
|
||
function pauseAnyVideoPlaying() { | ||
[].forEach.call(imagesElements, function(imageElement) { | ||
if (imageElement.getElementsByTagName('video').length > 0) { | ||
imageElement.getElementsByTagName('video')[0].pause(); | ||
} | ||
}); | ||
} | ||
|
||
function loadImage(index, callback) { | ||
var imageContainer = imagesElements[index]; | ||
var galleryItem = currentGallery[index]; | ||
var isVideo = false; | ||
if (typeof imageContainer !== 'undefined') { | ||
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') { | ||
return; | ||
} | ||
|
||
// If image is already loaded run callback and return | ||
if (imageContainer.getElementsByTagName('img')[0]) { | ||
// If image is already loaded run callback and return OR If video is already loaded run callback and return | ||
if ((imageContainer.getElementsByTagName('img')[0] && !isVideo) || (imageContainer.getElementsByTagName('video')[0] && isVideo)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it is needed |
||
if (callback) { | ||
callback(); | ||
} | ||
|
@@ -490,11 +507,11 @@ | |
|
||
// Get element reference, optional caption and source path | ||
var imageElement = galleryItem.imageElement; | ||
var thumbnailElement = imageElement.getElementsByTagName('img')[0]; | ||
var thumbnailElement = isVideo ? imageElement.getElementsByTagName('video')[0] : imageElement.getElementsByTagName('img')[0]; | ||
var imageCaption = typeof options.captions === 'function' ? | ||
options.captions.call(currentGallery, imageElement) : | ||
imageElement.getAttribute('data-caption') || imageElement.title; | ||
var imageSrc = getImageSrc(imageElement); | ||
var imageSrc = isVideo ? getVideoSrc(imageElement) : getImageSrc(imageElement); | ||
|
||
// Prepare figure element | ||
var figure = create('figure'); | ||
|
@@ -512,29 +529,79 @@ | |
} | ||
imageContainer.appendChild(figure); | ||
|
||
// Prepare gallery img element | ||
var image = create('img'); | ||
image.onload = function() { | ||
// Remove loader element | ||
var spinner = document.querySelector('#baguette-img-' + index + ' .baguetteBox-spinner'); | ||
figure.removeChild(spinner); | ||
if (!options.async && callback) { | ||
callback(); | ||
if (isVideo) { | ||
// Prepare gallery video element | ||
var video = create('video'); | ||
//video.onload = function() { | ||
video.addEventListener('loadeddata', function() { | ||
//Remove loader element | ||
var spinner = document.querySelector('#baguette-img-' + index + ' .baguetteBox-spinner'); | ||
figure.removeChild(spinner); | ||
if (!options.async && callback) { | ||
callback(); | ||
} | ||
}); | ||
var source = create('source'); | ||
source.setAttribute('src', imageSrc); | ||
video.appendChild(source); | ||
if (options.titleTag && imageCaption) { | ||
video.title = imageCaption; | ||
} | ||
}; | ||
image.setAttribute('src', imageSrc); | ||
image.alt = thumbnailElement ? thumbnailElement.alt || '' : ''; | ||
if (options.titleTag && imageCaption) { | ||
image.title = imageCaption; | ||
figure.appendChild(video); | ||
} else { | ||
// Prepare gallery img element | ||
var image = create('img'); | ||
image.onload = function() { | ||
// Remove loader element | ||
var spinner = document.querySelector('#baguette-img-' + index + ' .baguetteBox-spinner'); | ||
figure.removeChild(spinner); | ||
if (!options.async && callback) { | ||
callback(); | ||
} | ||
}; | ||
image.setAttribute('src', imageSrc); | ||
image.alt = thumbnailElement ? thumbnailElement.alt || '' : ''; | ||
if (options.titleTag && imageCaption) { | ||
image.title = imageCaption; | ||
} | ||
figure.appendChild(image); | ||
} | ||
figure.appendChild(image); | ||
|
||
// Run callback | ||
if (options.async && callback) { | ||
callback(); | ||
} | ||
} | ||
|
||
// Get video source location, mostly used for responsive images | ||
function getVideoSrc(image) { | ||
// Set default image path from href | ||
var result = image.getElementsByTagName('video')[0].getElementsByTagName('source')[0].src; | ||
// If dataset is supported find the most suitable image | ||
if (image.dataset) { | ||
var srcs = []; | ||
// Get all possible image versions depending on the resolution | ||
for (var item in image.dataset) { | ||
if (item.substring(0, 3) === 'at-' && !isNaN(item.substring(3))) { | ||
srcs[item.replace('at-', '')] = image.dataset[item]; | ||
} | ||
} | ||
// Sort resolutions ascending | ||
var keys = Object.keys(srcs).sort(function(a, b) { | ||
return parseInt(a, 10) < parseInt(b, 10) ? -1 : 1; | ||
}); | ||
// Get real screen resolution | ||
var width = window.innerWidth * window.devicePixelRatio; | ||
// Find the first image bigger than or equal to the current width | ||
var i = 0; | ||
while (i < keys.length - 1 && keys[i] < width) { | ||
i++; | ||
} | ||
result = srcs[keys[i]] || result; | ||
} | ||
return result; | ||
} | ||
|
||
// Get image source location, mostly used for responsive images | ||
function getImageSrc(image) { | ||
// Set default image path from href | ||
|
@@ -609,6 +676,7 @@ | |
} | ||
|
||
function updateOffset() { | ||
pauseAnyVideoPlaying(); | ||
var offset = -currentIndex * 100 + '%'; | ||
if (options.animation === 'fadeIn') { | ||
slider.style.opacity = 0; | ||
|
@@ -625,6 +693,9 @@ | |
slider.style.transform = slider.style.webkitTransform = 'translate3d(' + offset + ',0,0)' | ||
: slider.style.left = offset; | ||
} | ||
if (imagesElements[currentIndex].getElementsByTagName('video').length > 0) { | ||
imagesElements[currentIndex].getElementsByTagName('video')[0].play(); | ||
} | ||
} | ||
|
||
// CSS 3D Transforms test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be here.