Skip to content

Instantly share code, notes, and snippets.

@asha23
Last active March 29, 2021 15:11
Show Gist options
  • Save asha23/ada4147140c90da235f8384af232e50b to your computer and use it in GitHub Desktop.
Save asha23/ada4147140c90da235f8384af232e50b to your computer and use it in GitHub Desktop.
<?php $video_id = 'the video id'; ?>
<div id="wistia_<?= $video_id; ?>" class="wistia_embed_api wistia_async_<?= $video_id; ?> popover=false wistia_embed_wrapper" data-video="<?= $video_id; ?>"></div>
// ========================
// Wistia injection scripts
// =========================
function doWistia(wistiaId, wistiaType) {
var baseUrl = "https://fast.wistia.com/oembed/?url=";
var accountUrl = encodeURIComponent("https://home.wistia.com/medias/");
var xhr = new XMLHttpRequest();
xhr.open('GET', baseUrl + accountUrl + wistiaId + "&format=json&callback=?");
xhr.send(null);
xhr.onreadystatechange = function() {
var DONE = 4;
var OK = 200;
if (xhr.readyState === DONE && xhr.status === OK) {
switch (wistiaType) {
case "popover":
wistiaEmbed = Wistia.embed(wistiaId, {
autoPlay: true,
controlsVisibleOnLoad: false,
popover: true,
popoverAnimateThumbnail: true,
videoFoam: true,
videoWrapper: 'wistia_embed_popover',
});
break;
case "inline":
wistiaEmbed = Wistia.embed(wistiaId, {
autoPlay: false,
controlsVisibleOnLoad: false,
videoFoam: true,
videoWrapper: 'wistia_embed_api',
});
break;
}
} else {
return;
}
};
};
function setupWistia(e) {
if (document.querySelector('.wistia_embed_popover')) {
wistiaId = document.querySelector('.wistia_embed_popover').getAttribute('data-wistia-id');
wistiaType = 'popover';
}
if (document.querySelector('.wistia_embed_api')) {
wistiaId = document.querySelector('.wistia_embed_api').getAttribute('data-video');
wistiaType = 'inline';
}
// inject wistia script (If needed)
if (typeof wistiaId !== 'undefined') {
var d = document;
script = d.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = 'https://fast.wistia.com/assets/external/E-v1.js';
d.getElementsByTagName('html')[0].appendChild(script);
script.onload = function() {
doWistia(wistiaId, wistiaType);
};
} else {
return;
}
};
window.addEventListener("load", pageFullyLoaded, false);
function pageFullyLoaded(e) {
setupWistia(e);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment