-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mashup #43
base: gh-pages
Are you sure you want to change the base?
mashup #43
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,108 @@ | |
<html> | ||
<head> | ||
<title>Mashup</title> | ||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> | ||
<style> | ||
input { | ||
margin: 10px; | ||
} | ||
|
||
li{ | ||
list-style: none; | ||
} | ||
|
||
.getimages { | ||
width: 100px; | ||
border : 1px solid black ; | ||
cursor: pointer; | ||
margin: 5px; | ||
} | ||
|
||
.queriedImages { | ||
} | ||
|
||
</style> | ||
</head> | ||
|
||
<body> | ||
<input type = "text" class = "inputText"></input> | ||
<button type = "submit"> Get images</button> | ||
<button type = "reset"> Reset images</button> | ||
<div class= "widget"></div> | ||
<div class= "queriedImages"></div> | ||
|
||
|
||
<script> | ||
function loadImages(queryTag) { | ||
$.ajax({ | ||
url: 'https://api.instagram.com/v1/tags/'+ queryTag +'/media/recent?client_id=ce95cb4e56c146c994457b48a839f6a8', | ||
dataType: 'jsonp', | ||
success: function(result) { | ||
for (var i = 0; i < result.data.length; i++) { | ||
var url = result.data[i].images.thumbnail.url; | ||
$('.queriedImages').append('<img class =\'EachImage\' src="' + url + '"/>'); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function searchArtist(query) { | ||
$.ajax({ | ||
url:"https://api.spotify.com/v1/search?q="+ query +"&type=artist", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. For query parameters, also take a look at |
||
// Accept: application/json, | ||
dataType: 'json', | ||
success: function(result) { | ||
console.log(result) | ||
var name = result.artists.items[0].name | ||
var id = result.artists.items[0].id | ||
getArtistSongs(id) | ||
} | ||
}); | ||
} | ||
|
||
function getArtistSongs(artistId) { | ||
console.log("got the artistId:", artistId) | ||
$.ajax({ | ||
url:"https://api.spotify.com/v1/artists/" + artistId + "/top-tracks?country=US", | ||
dataType: 'json', | ||
success: function(result) { | ||
console.log("result", result) | ||
|
||
var track = result.tracks[0].id; | ||
widget(track) | ||
// for (var i = 0; i < result.tracks.length; i++) { | ||
// var track = result.tracks[i].id; | ||
// // console.log("track", track.name, track.id) | ||
// widget(track) | ||
// } | ||
|
||
} | ||
}); | ||
} | ||
|
||
function widget(tracks) { | ||
// var Playlist = $('<iframe src="https://embed.spotify.com/?uri=spotify:trackset:'+ tracks + 'frameborder="0" allowtransparency="true"></iframe>') | ||
|
||
var Playlist = $('<iframe src="https://embed.spotify.com/?uri=' + tracks +'" width="250" height="330" frameborder="0" allowtransparency="true"></iframe>') | ||
var Playlist = $('<iframe class = \' widgetplay \' src="https://embed.spotify.com/?uri=spotify:track:' + tracks +'" frameborder="0" allowtransparency="true"></iframe>') | ||
|
||
$(".widget").append(Playlist) | ||
} | ||
|
||
$(document).ready(function() { | ||
|
||
$(":submit").click(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good practice to limit this to a specific form, so that you don't actually catch submits for any other forms that might make their way into the page—would lead to some weird bugs. |
||
var textValue = $(".inputText").val(); | ||
loadImages(textValue); | ||
searchArtist(textValue) | ||
}); | ||
|
||
$(":reset").click(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto—limit this to a specific element via an ID or class selector. |
||
$(".inputText").val(""); | ||
$(".EachImage").remove(); | ||
$(".widgetplay").remove(); | ||
}) | ||
}); | ||
</script> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, you may want to use
encodeURIComponent()
for cases like this so that it can handle things like spaces (though Instagram may not).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, will look into this.