xonecas.io
1361
Xc

xonecas.com / commit 50f523c

added media gallery

Sean Caetano Martin2011-11-02 50f523cae1235f3b268ffe2e5b77e15bdcc7dfd4 parent 77f56a0

6 files changed

public/index.html+6−3
@@ -10,7 +10,7 @@
1010
1111 <script src="vendor/modernizr.js"></script>
1212 <!-- require magic! -->
13- <script data-main="js/router.js" src="vendor/require.js"></script>
13+ <script data-main="js/init.js" src="vendor/require.js"></script>
1414
1515 <link href='http://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
1616 <link rel="stylesheet" type="text/css" href="styles/style.css?v=1">
@@ -27,12 +27,15 @@
2727 </section>
2828
2929 <script id="photos_tmpl" type="text/template">
30+ <h2>Media gallery <small>Tumblr</small>
3031 <ul class="media-grid">
32+ {{#each this}}
3133 <li>
32- <a href="">
33-
34+ <a href="{{url}}">
35+ <img src="{{thumb}}" alt="{{caption}}" title="{{caption}}">
3436 </a>
3537 </li>
38+ {{/each}}
3639 </ul>
3740 </script>
3841
public/js/init-event.js+0−12
@@ -1,12 +0,0 @@
1-require.config({
2- baseUrl: '/'
3-});
4-
5-require([
6- 'vendor/underscore',
7- 'vendor/jquery'
8-], function () {
9- _.each([1,2,3,4,5,6], function (num) {
10- $('body').append('<p>'+num+'</p>');
11- });
12-});
public/js/router.js+0−9
@@ -1,9 +0,0 @@
1-var loc = location.pathname.split('/')[1];
2-
3-require.config({
4- baseUrl: '/'
5-});
6-
7-loc === "" && require(['js/init']);
8-
9-loc === "event" && require(['js/init-event']);
public/js/script.js+50−8
@@ -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
public/styles/base.less+4−0
@@ -38,3 +38,7 @@ code .comment { color: grey }
3838 max-width: 100%;
3939 float: left;
4040 }
41+
42+#media {
43+ margin-bottom: 140px;
44+}
public/styles/style.css+1−0
@@ -364,3 +364,4 @@ code .number{color:red;}
364364 code .comment{color:grey;}
365365 .badge{width:90px;height:90px;position:relative;left:20px;float:left;margin:0 40px 20px 0;}
366366 .post_body img{display:block;margin-bottom:20px;max-width:100%;float:left;}
367+#media{margin-bottom:140px;}