var emb_key = "YOUR_API_KEY";
$(document).ready(function() {
// Connect the styled button with the form input. The input is hidden. This is done in order to have a custom embed button.
$("#upload-button").click(function(e) {
$('#video_file').click();
})
// Once the video file is added, display the progress UI and submit the form for upload.
$("#video_file").change(function(e) {
$("#loader").css('display', "block");
$("#progress-percent").css('display', "block");
$("form[name='upload_form']").submit();
e.preventDefault();
})
// The sumbit function makes a post request. By default this replaces the page with the response, which is the JSON response after the post request. To stay on the same page the ajax request requires some more information.
$("form[name='upload_form'").submit(function(e) {
e.preventDefault();
var fd = new FormData($("form")[0]);
$.ajax({
url: $(this).attr('action'),
data: fd,
processData: false,
contentType: false,
crossDomain: true,
headers: {
'Access-Control-Allow-Origin': '*'
},
type: 'POST',
success: function(data, textStatus, xhr) {
// On receiving the response, update the UI with the embed code and URL of the video
successText(data);
//Query the status endpoint
var call = "https://upload.embed.ly/1/status?key=" + emb_key + "&video_id=" + data.video_id;
//Poll status endpoint until video is processed
pollForFinished(call, function(){renderIframe(data);});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("Upload Failed for video: " + errorThrown);
},
xhr: function() {
//Monitor and display the percentage uploaded
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = (evt.loaded /...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.