-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/video-js' into develop
- Loading branch information
Showing
8 changed files
with
7,945 additions
and
5 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { appendThumbnails } from './thumbnail' | ||
import { appendPlayer, removePlayer } from './video' | ||
|
||
document.addEventListener("turbolinks:load", function() { | ||
console.log("turbolinks:load modal"); | ||
var parentViewId = 'modal-content'; | ||
var playerId = 'my-player'; | ||
var videoUrl = "https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8"; | ||
var videoType = "application/x-mpegURL"; | ||
var posterUrl = ""; | ||
|
||
var thumbnailLinkToOpenModals = document.querySelectorAll('a#open-thumbnail-modal'); | ||
thumbnailLinkToOpenModals.forEach(function(link) { | ||
link.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
var dataThumbnails = this.getAttribute("data-thumbnails"); | ||
var thumbnails = JSON.parse(dataThumbnails); | ||
appendThumbnails(thumbnails, parentViewId); | ||
var modal = document.querySelector('.modal'); // assuming you have only 1 | ||
var html = document.querySelector('html'); | ||
modal.classList.add('is-active'); | ||
html.classList.add('is-clipped'); | ||
var closeCompoments = modal.querySelectorAll('.modal-background, .modal-close.is-large'); | ||
closeCompoments.forEach(function(compoment) { | ||
compoment.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
var modalContent = document.getElementById(parentViewId); | ||
while (modalContent.firstChild) { | ||
modalContent.removeChild(modalContent.lastChild); | ||
} | ||
modal.classList.remove('is-active'); | ||
html.classList.remove('is-clipped'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
var playLinkToOpenModals = document.querySelectorAll('a#open-play-modal'); | ||
playLinkToOpenModals.forEach(function(link) { | ||
link.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
console.log("data-video" + this.getAttribute("data-video")); | ||
console.log("data-poster" + this.getAttribute("data-poster")); | ||
console.log("document.querySelector a#open-modal"); | ||
videoUrl = this.getAttribute("data-video"); | ||
posterUrl = this.getAttribute("data-poster"); | ||
appendPlayer(parentViewId, playerId, videoUrl, videoType, posterUrl); | ||
var modal = document.querySelector('.modal'); // assuming you have only 1 | ||
var html = document.querySelector('html'); | ||
modal.classList.add('is-active'); | ||
html.classList.add('is-clipped'); | ||
var closeCompoments = modal.querySelectorAll('.modal-background, .modal-close.is-large'); | ||
closeCompoments.forEach(function(compoment) { | ||
compoment.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
removePlayer(playerId); | ||
modal.classList.remove('is-active'); | ||
html.classList.remove('is-clipped'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function appendThumbnails(thumbnails, parentViewId) { | ||
thumbnails.forEach(function(asset) { | ||
if(asset.format == 'image'){ | ||
var url = asset.url; | ||
var img = document.createElement('img'); | ||
img.setAttribute('src', url); | ||
var modalContent = document.getElementById(parentViewId); | ||
modalContent.append(img); | ||
} | ||
}); | ||
} | ||
|
||
export { appendThumbnails } |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import videojs from 'video.js'; | ||
|
||
function removePlayer(playerId){ | ||
var oldPlayer = document.getElementById(playerId); | ||
if(oldPlayer){ | ||
videojs(oldPlayer).dispose(); | ||
} | ||
} | ||
|
||
function appendPlayer(parentViewId, playerId, videoUrl, videoType, posterUrl) { | ||
removePlayer(playerId); | ||
var modalContent = document.getElementById(parentViewId); | ||
if(modalContent){ | ||
var v = buildVideoElement(videoUrl, videoType, posterUrl); | ||
modalContent.append(v); | ||
var player = videojs(v); | ||
} | ||
} | ||
|
||
function buildVideoElement(videoUrl, videoType, posterUrl){ | ||
var obj, source; | ||
obj = document.createElement('video'); | ||
obj.setAttribute('id', 'my-player'); | ||
obj.setAttribute('class', 'video-js vjs-theme-sea'); | ||
obj.setAttribute('width', '640'); | ||
obj.setAttribute('data-height', '264'); | ||
obj.setAttribute('controls', ' '); | ||
obj.setAttribute('poster', posterUrl); | ||
obj.setAttribute('preload', 'auto'); | ||
obj.setAttribute('data-setup', '{}'); | ||
source = document.createElement('source'); | ||
source.setAttribute('type', videoType); | ||
source.setAttribute('src', videoUrl); | ||
obj.append(source); | ||
return obj; | ||
} | ||
|
||
export { removePlayer, appendPlayer, buildVideoElement } |
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
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
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
Oops, something went wrong.