Skip to content
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

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Member

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).

Copy link
Author

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.

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. For query parameters, also take a look at $.ajax()'s data setting.

http://api.jquery.com/jquery.ajax/

// 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() {
Copy link
Member

Choose a reason for hiding this comment

The 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() {
Copy link
Member

Choose a reason for hiding this comment

The 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>