@@ -58,8 +58,25 @@ var xonecas = !function () {
5858 var Photos = TumblrSync.extend({
5959 url: "http://api.tumblr.com/v2/blog/xonecas.tumblr.com/posts/photo",
6060 page: 0,
61- count: 10,
62- type: 'photo'
61+ count: 20,
62+ type: 'photo',
63+
64+ parse: function (res) {
65+ var media = [];
66+
67+ _.each(res.response.posts, function (post) {
68+ _.each(post.photos, function (photo) {
69+ var cap = photo.caption === "" ? post.caption: photo.caption;
70+ media.push({
71+ caption: cap.replace(/<.*?>/g, ''),
72+ url: photo.original_size.url,
73+ thumb: photo.alt_sizes[4].url
74+ });
75+ });
76+ });
77+
78+ return media;
79+ }
6380 });
6481
6582 var Tumblr = TumblrSync.extend({
@@ -120,10 +137,13 @@ var xonecas = !function () {
120137 tagName: 'header',
121138 template: Handlebars.templates['header-tmpl.html'],
122139
140+ initialize: function () {
141+ $(this.el).appendTo('body');
142+ },
143+
123144 render: function () {
124145 $(this.el)
125146 .html(this.template())
126- .appendTo('body')
127147 .dropdown();
128148 },
129149
@@ -151,6 +171,7 @@ var xonecas = !function () {
151171 template: '#footer_tmpl',
152172
153173 initialize: function () {
174+ $(this.el).appendTo('body');
154175 _.bindAll(this, "render");
155176 this.twitter = new Twitter();
156177 this.twitter.bind('reset', this.render);
@@ -170,11 +191,32 @@ var xonecas = !function () {
170191 };
171192
172193 $(this.el)
173- .html(template(context))
174- .appendTo('body');
194+ .html(template(context));
175195 }
176196 });
177197
198+ var Media = Backbone.View.extend({
199+ id: "media",
200+ className: 'container',
201+ tagName: 'section',
202+ template: '#photos_tmpl',
203+ collection: new Photos(),
204+
205+ initialize: function () {
206+ $(this.el).appendTo('body');
207+ this.template = Handlebars.compile($(this.template).html());
208+
209+ _.bindAll(this, "render");
210+ this.collection.bind('reset', this.render);
211+ this.collection.fetch();
212+ },
213+
214+ render: function () {
215+ $(this.el)
216+ .html(this.template(this.collection.toJSON()));
217+ }
218+ });
219+
178220 var Page = Backbone.View.extend({
179221 id: 'main',
180222 className: 'container',
@@ -186,8 +228,8 @@ var xonecas = !function () {
186228 this.header = new Header({
187229 'collection': this.collection
188230 });
189- this.photos = new Photos();
190- this.photos.fetch();
231+ $('body').append(this.el);
232+ this.media = new Media();
191233 this.footer = new Footer();
192234 _.bindAll(this, "render", "report");
193235 this.collection.bind('reset', this.render);
@@ -195,7 +237,7 @@ var xonecas = !function () {
195237 this.collection.bind('change', this.render);
196238 this.collection.fetch();
197239 this.header.render();
198- $('body').append(this.el);
240+ this.media.render();
199241 this.footer.render();
200242 },
201243