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 #8 from Financial-Times/native-video-ads
Native video ads
- Loading branch information
Showing
15 changed files
with
287 additions
and
262 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
machine: | ||
node: | ||
version: 4.2.2 | ||
post: | ||
- npm install -g Financial-Times/origami-build-tools#node4 | ||
dependencies: | ||
override: | ||
- obt install | ||
cache_directories: | ||
- "node_modules" | ||
test: | ||
override: | ||
- obt test | ||
- obt verify |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* global console */ | ||
const oVideo = require('../../main'); | ||
oVideo.init({ | ||
advertising: true | ||
}); |
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,2 +1,2 @@ | ||
const oVideo = require('../../main'); | ||
oVideo.init({ placeholder: true }); | ||
oVideo.init({ placeholder: true, advertising: true }); |
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,5 @@ | ||
<div> | ||
<div class="video-container" data-o-component="o-video" | ||
<div class="o-video video-container" data-o-component="o-video" | ||
data-o-video-source="Brightcove" | ||
data-o-video-id="4165329773001"></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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div> | ||
<div class="video-container o-video--videojs video-js" data-o-component="o-video" | ||
data-o-video-source="Brightcove" | ||
data-o-video-player="videojs" | ||
data-o-video-id="4165329773001"></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,26 +1,61 @@ | ||
const factory = require('./src/models/video-factory'); | ||
const init = opts => { | ||
|
||
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 context = options.context instanceof HTMLElement ? options.context : document.querySelector(opts.context); | ||
const videoPromises = [].map.call(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(() => { }); | ||
|
||
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); | ||
}); | ||
return Promise.all(videoPromises); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
init, | ||
factory | ||
factory, | ||
_loadAdsLibrary: loadAdsLibrary | ||
}; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.