Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pedroribeirodev/6327dc43374defb170c2c19aaf0cfda2 to your computer and use it in GitHub Desktop.
Save pedroribeirodev/6327dc43374defb170c2c19aaf0cfda2 to your computer and use it in GitHub Desktop.
Codigo Youtube JS
$(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