Created
October 22, 2018 22:55
-
-
Save pedroribeirodev/6327dc43374defb170c2c19aaf0cfda2 to your computer and use it in GitHub Desktop.
Codigo Youtube JS
This file contains hidden or 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 (e) { | |
$("form").on("submit", function() { | |
e.preventDefault(); | |
var request = gapi.client.youtube.search.list({ | |
part: "snippet", | |
type: "video", | |
q: encodeURIComponent($("#search").val()).replace(/%20/g, "+"), | |
maxResults: 3, | |
order: "viewCount", | |
publishedAfter: "2015-01-01T00:00:00Z" | |
}); | |
request.execute(function(response) { | |
var results = response.result; | |
$("#results").html(""); | |
$.each(results.items, function(index, item) { | |
$.get("?search=", function(data) { | |
var string = "<div class='item'>"+ | |
"<h2>" + item.snippet.title + "</h2>" + | |
"<iframe class='video w100' width='640' height='360' src='https://www.youtube.com/embed/" + item.id.videoId + "' frameborder='0' allowfullscreen></iframe>" | |
"</div>"; | |
$("#results").append(string); | |
}); | |
}); | |
resetVideoHeight(); | |
}); | |
return false; | |
}); | |
$(window).on("resize", resetVideoHeight); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment