This repository was archived by the owner on Mar 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
mashup #43
Open
clenclen
wants to merge
1
commit into
advanced-js:gh-pages
Choose a base branch
from
clenclen:gh-pages
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
mashup #43
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.