This repository has been archived by the owner on Nov 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Financial-Times/v1
Refactors o-video to follow the spec and to remove all unused code
- Loading branch information
Showing
25 changed files
with
878 additions
and
1,307 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* global console */ | ||
const oVideo = require('../../main'); | ||
oVideo.init({ | ||
advertising: true | ||
import './../../main.js'; | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
document.dispatchEvent(new CustomEvent('o.DOMContentLoaded')); | ||
}); |
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,7 @@ | ||
<div> | ||
<div class="o-video video-container" data-o-component="o-video" | ||
data-o-video-source="Brightcove" | ||
data-o-video-id="4165329773001" | ||
data-o-video-advertising="true" | ||
data-o-video-placeholder="true"></div> | ||
</div> |
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,5 +1,6 @@ | ||
<div> | ||
<div class="o-video video-container" data-o-component="o-video" | ||
data-o-video-source="Brightcove" | ||
data-o-video-id="4165329773001"></div> | ||
data-o-video-id="4165329773001" | ||
data-o-video-advertising="true"></div> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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,61 +1,10 @@ | ||
const factory = require('./src/models/video-factory'); | ||
import Video from './src/video.js'; | ||
|
||
function loadAdsLibrary() { | ||
return new Promise((resolve, reject) => { | ||
const googleSdkScript = document.createElement('script'); | ||
googleSdkScript.setAttribute('type', 'text/javascript'); | ||
googleSdkScript.setAttribute('src', `//imasdk.googleapis.com/js/sdkloader/ima3.js`); | ||
googleSdkScript.setAttribute('async', true); | ||
googleSdkScript.setAttribute('defer', true); | ||
document.getElementsByTagName("head")[0].appendChild(googleSdkScript); | ||
|
||
googleSdkScript.addEventListener('load', () => { | ||
resolve(); | ||
}); | ||
|
||
googleSdkScript.addEventListener('error', () => { | ||
reject(); | ||
}); | ||
}); | ||
} | ||
|
||
function loadVideos(options) { | ||
const videoPromises = [].map.call(options.context.querySelectorAll(options.selector + ':not([data-o-video-js])[data-o-component~="o-video"]'), videoEl => { | ||
return factory(videoEl, options) | ||
.init() | ||
// don't fail all if a video errors | ||
.catch(() => { }); | ||
}); | ||
|
||
return Promise.all(videoPromises); | ||
} | ||
|
||
function init(opts) { | ||
const options = opts || {}; | ||
const defaultOpts = { | ||
context: document.body, | ||
selector: '*' | ||
}; | ||
|
||
for (let defaultOpt in defaultOpts) { | ||
if (defaultOpts.hasOwnProperty(defaultOpt) && !options.hasOwnProperty(defaultOpt)) { | ||
options[defaultOpt] = defaultOpts[defaultOpt]; | ||
} | ||
} | ||
|
||
const librariesLoaded = options.advertising ? loadAdsLibrary() : Promise.resolve(); | ||
options.context = options.context instanceof HTMLElement ? options.context : document.querySelector(opts.context); | ||
|
||
return librariesLoaded.then(() => { | ||
return loadVideos(options); | ||
}, () => { | ||
options.ads = false; | ||
return loadVideos(options); | ||
}); | ||
const constructAll = () => { | ||
Video.init(); | ||
document.removeEventListener('o.DOMContentLoaded', constructAll); | ||
}; | ||
|
||
module.exports = { | ||
init, | ||
factory, | ||
_loadAdsLibrary: loadAdsLibrary | ||
}; | ||
document.addEventListener('o.DOMContentLoaded', constructAll); | ||
|
||
export default Video; |
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.