Last active
October 15, 2020 10:51
-
-
Save asha23/cc34c69d799aeb219b4096eccbba0161 to your computer and use it in GitHub Desktop.
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
function parentWidth(elem) { | |
return elem.parentElement.clientWidth; | |
} | |
var xhr = new XMLHttpRequest(); | |
var baseUrl = "https://fast.wistia.com/oembed/?url="; | |
var accountUrl = encodeURIComponent("https://home.wistia.com/medias/"); | |
var wistiaId = document.querySelector('.wistia_embed').getAttribute('data-wistia-id'); | |
console.log("aaa"); | |
var image_size = parentWidth(document.querySelector(".embed-responsive"));//value in px | |
console.log(image_size); | |
var thumb_args = 'image_play_button=true&image_play_button_color=7b7968e0&image_resize='+image_size; | |
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) { | |
if (xhr.status === OK) | |
var data = JSON.parse(xhr.responseText); | |
var thumb = data.thumbnail_url.split('?')[0]; | |
thumb = thumb + "?" + "image_resize=200"; | |
var wistcont = document.querySelector("#wistia_" +wistiaId); | |
var wistimg = document.createElement("img"); | |
wistimg.setAttribute("id",'wistia_preview'); | |
wistimg.setAttribute("src",thumb + "?" + thumb_args); | |
wistimg.setAttribute("alt","Couldn't load Wistia video"); | |
wistimg.classList.add("responsive-img"); | |
wistcont.appendChild(wistimg); | |
wistimg.addEventListener("click",function(){ | |
wistiaEmbed = Wistia.embed( wistiaId , { | |
autoPlay: true, | |
controlsVisibleOnLoad: false | |
}); | |
},false); | |
console.log(JSON.parse(xhr.responseText)); | |
} else { | |
console.log(xhr.status); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment