Skip to content

Commit 70c441a

Browse files
authored
Video player - Add support for local video / HTML player (#513)
* Add support for local video playback * Updated CSS as HTML player is block level, unlike iframe from Youtube or Vimeo * Updated local docs * Compiled artefacts * Version bump to v14.3.1 * Updated package lock following clean install * Compiled artefacts
1 parent 04117ea commit 70c441a

File tree

10 files changed

+248
-142
lines changed

10 files changed

+248
-142
lines changed

dist/honeycomb.app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/honeycomb.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/honeycomb.css.cheatsheet.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,9 +1471,10 @@ <h1>Honeycomb web toolkit class name cheatsheet</h1>
14711471
</ul>
14721472
<li>.js-video-container</li>
14731473

1474-
1474+
<ul>
1475+
<li>.js-video-container--html-player</li>
14751476

1476-
1477+
</ul>
14771478
<li>.label</li>
14781479

14791480
<ul>
@@ -2887,9 +2888,10 @@ <h1>Honeycomb web toolkit class name cheatsheet</h1>
28872888
</ul>
28882889
<li>.video-container</li>
28892890

2890-
2891+
<ul>
2892+
<li>.video-container--html-player</li>
28912893

2892-
2894+
</ul>
28932895
<li>.visually-hidden</li>
28942896

28952897

dist/honeycomb.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ var colours = ['204, 0, 0',
562562
// Yellow
563563
'118, 118, 118' // Grey
564564
];
565-
566565
var init = function init() {
567566
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
568567
var charts = document.querySelectorAll('.js-chart');
@@ -6995,7 +6994,6 @@ var init = function init() {
69956994
}
69966995
}
69976996
};
6998-
69996997
var _default = exports["default"] = {
70006998
init: init
70016999
};
@@ -8186,7 +8184,6 @@ var notification = function notification(options) {
81868184
// Could be either 'font' or 'image'.
81878185
src: false // Reference to the icon.
81888186
},
8189-
81908187
content: '',
81918188
duration: false,
81928189
container: window.jQuery('body')
@@ -9154,7 +9151,7 @@ var loadPlayerAPIs = function loadPlayerAPIs() {
91549151
if (videoId) {
91559152
// If video is already loaded, skip.
91569153
// We look for the iframe for the specific video, because in React we may be reusing an old VideoPlayer component.
9157-
if (videoContainer.querySelector("iframe[id^=\"".concat(videoId, "\"]"))) {
9154+
if (videoContainer.querySelector("iframe[id^=\"".concat(videoId, "\"], video"))) {
91589155
continue;
91599156
}
91609157
if (isVimeoId(videoId)) {
@@ -9210,6 +9207,16 @@ var isVimeoId = function isVimeoId(id) {
92109207
}
92119208
return !!id.match(/^[0-9]*$/);
92129209
};
9210+
var isLocalVideoId = function isLocalVideoId(id) {
9211+
var extensions = ['mp4', 'webm'];
9212+
var isLocalVideo = false;
9213+
extensions.forEach(function (ext) {
9214+
if (id.match(".".concat(ext)) !== null) {
9215+
isLocalVideo = true;
9216+
}
9217+
});
9218+
return isLocalVideo;
9219+
};
92139220

92149221
// calculate second values for 10%, 20% etc. for event tracking
92159222
var calculatePercentages = function calculatePercentages(duration) {
@@ -9300,6 +9307,31 @@ var attachVimeoPlayerEventListeners = function attachVimeoPlayerEventListeners(p
93009307
handlePlayEvent(videoId, data.duration);
93019308
});
93029309
};
9310+
var addHtmlVideoPlayer = function addHtmlVideoPlayer(src, options, element) {
9311+
// Clear the contents of the target element.
9312+
while (element.firstChild) {
9313+
element.removeChild(element.firstChild);
9314+
}
9315+
var videoPlayer = document.createElement('video');
9316+
videoPlayer.setAttribute('src', src);
9317+
9318+
// Autoplay.
9319+
if (options.autoplay) {
9320+
videoPlayer.muted = true;
9321+
videoPlayer.autoplay = true;
9322+
}
9323+
9324+
// Controls.
9325+
if (options.controls) {
9326+
videoPlayer.controls = true;
9327+
}
9328+
9329+
// Loop.
9330+
if (options.loop) {
9331+
videoPlayer.loop = true;
9332+
}
9333+
element.appendChild(videoPlayer);
9334+
};
93039335

93049336
// Search the document for video containers,
93059337
// and load any video players that need loading.
@@ -9318,7 +9350,6 @@ var addInlineVideos = function addInlineVideos() {
93189350
if (videoContainer.querySelector("iframe[id^=\"".concat(videoId, "\"]"))) {
93199351
return 1; // continue
93209352
}
9321-
93229353
var duration;
93239354
var currentTime;
93249355
var percentages;
@@ -9420,6 +9451,9 @@ var addInlineVideos = function addInlineVideos() {
94209451
// add event listeners
94219452
attachVimeoPlayerEventListeners(player, videoId, goalTracked);
94229453
}
9454+
} else if (isLocalVideoId(videoId)) {
9455+
videoContainer.classList.add('video-container--html-player');
9456+
addHtmlVideoPlayer(videoId, _options, videoDiv.parentElement);
94239457
} else {
94249458
// load youtube player
94259459
if (window.YT && typeof window.YT.Player === 'function') {

dist/honeycomb.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/js-library/video-embed.htm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ <h1 class="section-heading--style-guide">Video embedding</h1>
1414
<p>Embed YouTube videos on the page, either inline or as background elements.</p>
1515
<p>Note: If you want to play the video in a <a href="/style-guide/js-library/lightbox.htm" class="js-scroll-to">lightbox</a>, use the <a href="/style-guide/js-library/lightbox.htm" class="js-scroll-to">lightbox</a> functionality.</p>
1616

17-
18-
<h2 class="section-heading--style-guide">Example inline embed</h2>
19-
<div class="js-video-container video-container" data-video-id="Zz8bdsPn01Q" data-video-controls="1"></div>
17+
<div class="grid">
18+
<h2 class="section-heading--style-guide">Example inline embed</h2>
19+
<div class="grid__col grid__col--span-6-of-12 padded--tight">
20+
<h3>Native/HTML video player</h3>
21+
<div class="js-video-container video-container" data-video-id="https://www.red-gate.com/assets/products/test-data-manager/images/ui-demo.mp4" data-video-controls="true" data-video-auto-play="true" data-video-loop="true"></div>
22+
</div>
23+
<div class="grid__col grid__col--span-6-of-12 padded--tight">
24+
<h3>Youtube video</h3>
25+
<div class="js-video-container video-container" data-video-id="Zz8bdsPn01Q" data-video-controls="1"></div>
26+
</div>
27+
</div>
2028

2129
<h2 class="section-heading--style-guide">Example background video</h2>
2230
<p>{Killed the autoplay example}</p>

0 commit comments

Comments
 (0)