Created
September 7, 2011 11:40
-
-
Save jokull/1200349 to your computer and use it in GitHub Desktop.
Public Instagram hashtag using Backbone.js and CoffeeScript
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
<html> | |
<head> | |
<script type="text/template" id="tpl-instagram-post"> | |
<a href="<%= link %>"><img src="<%= images.low_resolution.url %>"></a> | |
<p class="date"><%= created_time %></p> | |
<p class="user">@<%= user.username %></p> | |
<% if(caption){ %> | |
<p class="caption"><%= caption.text %></p> | |
<% } %> | |
</script> | |
/* jquery, underscore.js, backbone.js, instagram.coffee, script.coffee */ | |
</head> | |
<body> | |
<div id="instagram"></div> | |
</body> | |
</html> |
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
class window.InstagramPost extends Backbone.Model | |
class window.Instagram extends Backbone.Collection | |
model: InstagramPost | |
class window.InstagramView extends Backbone.View | |
el: "#instagram" | |
initialize: (options) -> | |
@collection.bind "add", @add | |
add: (model) => | |
model.view = new InstagramPostView model: model | |
($ @el).append model.view.render().el | |
class window.InstagramPostView extends Backbone.View | |
className: "post" | |
initialize: (options) -> | |
@model.bind "change", @render | |
@render() | |
render: => | |
tpl = _.template ($ "#tpl-instagram-post").html() | |
($ @el).html (tpl @model.toJSON()) | |
return @ | |
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
window.MyApp = | |
collections: {}, | |
models: {}, | |
views: {}, | |
instagram: { | |
client_id: client_id, # EDIT | |
count: count, # EDIT | |
hashtag: "hashtag" # EDIT | |
} | |
} | |
$-> | |
$.ajax | |
url: 'https://api.instagram.com/v1/tags/#{ MyApp.instagram.hashtag }/media/recent?count=#{ MyApp.instagram.count}&client_id=#{ MyApp.instagram.client_id }' | |
dataType: "jsonp" | |
success: (data, status) => | |
MyApp.collections.instagram = new Instagram | |
MyApp.views.instagram = new InstagramView collection: MyApp.collections.instagram | |
MyApp.collections.instagram.add data.data |
No because its jsonp
…Sent from my iPad
On Mar 11, 2012, at 6:34 AM, ***@***.*** wrote:
Hi Jokull,
Thanks for the sharing. Don't have cross domain issues with the AJAX call?
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1200349
Interesting. I got that issue and I used jsonp as well.
On Mar 11, 2012, at 8:32 PM, "Jökull Sólberg Auðunsson"
[email protected]
wrote:
… No because its jsonp
Sent from my iPad
On Mar 11, 2012, at 6:34 AM, ***@***.*** wrote:
> Hi Jokull,
>
> Thanks for the sharing. Don't have cross domain issues with the AJAX call?
> ---
>
> Reply to this email directly or view it on GitHub:
> https://gist.github.com/1200349
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1200349
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Jokull,
Thanks for the sharing. Don't you have cross domain issues with the AJAX call?