Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial

  • Loading branch information...
commit c6ff748964548a259dd6aba3a6696601ee7def66 0 parents
@jokull authored
0  README.md
No changes.
48 example.html
@@ -0,0 +1,48 @@
+<!doctype html>
+<html>
+ <head>
+ <script type="text/template" id="tpl-tumblr-post">
+
+ <% if(typeof title !== 'undefined' && title){ %>
+ <h2 class="title">
+ <a href="<%= post_url %>"><%= title %></a>
+ </h2>
+ <% } %>
+
+ <% if(typeof photos !== 'undefined' && photos.length){ %>
+ <% for (var i=0; i < photos.length; i++) { %>
+ <a href="<%= post_url %>"><img src="<%= photos[i].alt_sizes[0].url %>" alt="<%= photos.caption %>"></a>
+ <% } %>
+ <% } %>
+
+ <% if(typeof body !== 'undefined' && body){ %>
+ <%= body %>
+ <% } %>
+
+ </script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
+ <script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
+ <script src="http://backbonejs.org/backbone-min.js"></script>
+ <script src="tumblr.js"></script>
+ <script>
+ tumblr = {};
+ $(document).ready(function(){
+ tumblr.collection = new Tumblr({
+ hostname: 'kexhostel.tumblr.com',
+ params: {
+ api_key: 'yk0jaTbiVSXap7qTQtzYY36VbOQklHZ1fleeTOK9t5FZqHhrgC'
+ // ,tag: 'events'
+ }
+ });
+ tumblr.view = new TumblrView({
+ el: '#tumblr',
+ collection: tumblr.collection
+ });
+ tumblr.collection.page();
+ });
+ </script>
+ </head>
+ <body>
+ <div id="tumblr"></div>
+ </body>
+</html>
19 templates/post.html
@@ -0,0 +1,19 @@
+<script type="text/template" id="tpl-tumblr-post">
+
+ <% if(typeof title !== 'undefined' && title){ %>
+ <h2 class="title">
+ <a href="<%= post_url %>"><%= title %></a>
+ </h2>
+ <% } %>
+
+ <% if(typeof photos !== 'undefined' && photos.length){ %>
+ <% for (var i=0; i < photos.length; i++) { %>
+ <a href="<%= post_url %>"><img src="<%= photos[i].alt_sizes[0].url %>" alt="<%= photos.caption %>"></a>
+ <% } %>
+ <% } %>
+
+ <% if(typeof body !== 'undefined' && body){ %>
+ <%= body %>
+ <% } %>
+
+</script>
74 tumblr.coffee
@@ -0,0 +1,74 @@
+root = exports ? this
+
+class root.NextPage extends Backbone.View
+
+ el: ".pagination .next"
+
+ events:
+ "click": "click"
+
+ initialize: (options) ->
+ @collection.bind "last", @hide
+
+ hide: =>
+ ($ @el).hide()
+
+ click: (e) =>
+ e.preventDefault()
+ @collection.page()
+
+
+class root.TumblrPost extends Backbone.Model
+
+
+class root.Tumblr extends Backbone.Collection
+
+ model: TumblrPost
+ endpoint: 'http://api.tumblr.com/v2/blog/'
+ params: {limit: 1} # Default only one
+
+ initialize: (options) ->
+ @endpoint = @endpoint + options.hostname
+ @params = _.extend @params, (options.params or {})
+
+ page: =>
+ params = _.extend @params, {offset: @length}
+ $.ajax
+ url: @endpoint + '/posts/json?' + ($.param params)
+ dataType: "jsonp"
+ jsonp: "jsonp"
+ success: (data, status) =>
+ @add data.response.posts
+ @trigger "paged"
+ @trigger "last" if data.response.total_posts == @length
+
+
+class root.TumblrPostView extends Backbone.View
+
+ className: "tumblr-post"
+
+ initialize: (options) ->
+ @model.bind "change", @render if @model
+
+ render: =>
+ tpl = _.template ($ "#tpl-tumblr-post").html()
+ console.log @model.toJSON()
+ ($ @el).html (tpl @model.toJSON())
+ return @
+
+
+class root.TumblrView extends Backbone.View
+
+ initialize: (options) ->
+ @collection.bind "reset", @all
+ @collection.bind "add", @add
+
+ all: () =>
+ ($ @el).html("")
+ @collection.each @add
+
+ add: (model) =>
+ model.view = new TumblrPostView model: model
+ ($ @el).append model.view.render().el
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.