xonecas.io
1361
Xc

xonecas.com / commit ed4e800

added tweets and coderwal badges, links to tother projects

sean2011-10-07 ed4e80082e852cf7014c99899cd7f595de300834 parent 57c891d

6 files changed

.gitignore+1−0
@@ -0,0 +1 @@
1+*.swp
index.html+87−18
@@ -14,36 +14,104 @@
1414 <script src="vendor/modernizr.js?v=0.0.3"></script>
1515 </head>
1616 <body>
17- <!--
18- Templates go in this magic div that no one sees
19- -->
20- <script id="post_tmpl" type="text/template">
21- <h1>{{title}}</h1>
22- <div class="post_body">
23- {{{body}}}
24- </div>
25- <aside>
26- <a href="{{post_url}}" title="{{post_url}}">permalink</a>,
27- on {{date}} ({{timestamp}}).
28- </aside>
29- </script>
17+ <a href="http://github.com/you"><img style="position: absolute; top: 40px; right: 0; border: 0; z-index: 1000;" src="https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a>
3018
3119 <script id="header_tmpl" type="text/template">
3220 <div class="topbar-inner">
3321 <div class="container">
3422 <h3><a href="/">xonecas</a></h3>
3523 <ul class="nav">
36- <li><a id="prev-post" href="#">Previous</a></li>
37- <li><a id="next-post" href="#">Next</a></li>
24+ <li><a id="prev-post" href="#">Previous page</a></li>
25+ <li><a id="next-post" href="#">Next page</a></li>
26+ </ul>
27+
28+ <ul class="nav secondary-nav">
29+ <li class="menu">
30+ <a href="#" class="menu">Projects and experiments</a>
31+ <ul class="menu-dropdown">
32+ <li>
33+ <a href="/2d-particle-experiements/" target="_new">
34+ 2D Particle Experiments
35+ </a>
36+ </li>
37+ <li>
38+ <a href="/creativejs-threejs-part1/" target="_new">
39+ Three.js tutorial from Creativejs.com
40+ </a>
41+ </li>
42+ <li>
43+ <a href="/fractal-tree/" target="_new">
44+ Fractal Tree
45+ </a>
46+ </li>
47+ <li class="divider"></li>
48+ <li>
49+ <a href="https://github.com/xonecas/chrome-hijs"
50+ target="_new">
51+ Hijs for Chrome
52+ </a>
53+ </li>
54+ <li>
55+ <a href="https://github.com/xonecas/dotter"
56+ target="_new">
57+ Dotter
58+ </a>
59+ </li>
60+ <li>
61+ <a href="https://github.com/xonecas/disqus-node"
62+ target="_new">
63+ Disqus api for Node.js
64+ </a>
65+ </li>
66+ </ul>
67+ </li>
3868 </ul>
3969 </div>
4070 </div>
4171 </script>
4272
43- <script id="error_tmpl" type="text/template">
44- An error has occured: {{error}}. <small>Leaving in 5 secs</small>
73+ <script id="post_tmpl" type="text/template">
74+ <article>
75+ <h1>{{title}}</h1>
76+ <div class="post_body">
77+ {{{body}}}
78+ </div>
79+ <aside>
80+ <a href="{{post_url}}" title="{{post_url}}">permalink <small>tumblr</small></a>,
81+ on {{date}} ({{timestamp}}).
82+ </aside>
83+ </article>
4584 </script>
4685
86+ <script id="footer_tmpl" type="text/template">
87+ <div class="row">
88+ <div id="twitter" class="span6 offset1">
89+ <h2>
90+ <a href="//twitter.com/xonecas">@xonecas</a>
91+ <small>Twitter</small>
92+ </h2>
93+ {{#each twitter}}
94+ <blockquote>
95+ <p>{{{text}}}</p>
96+ <small>On {{created_at}}</small>
97+ </blockquote>
98+ {{/each}}
99+ </div>
100+ <div id="coderwall" class="span6 offset1">
101+ <h2>
102+ <a href="//coderwall.com/xonecas">Badges</a>
103+ <small>Coderwall</small>
104+ </h2>
105+ {{#each badges}}
106+ <div class="row">
107+ <img src="{{badge}}" alt="{{name}}" class="badge">
108+ <h3>{{name}}</h3>
109+ <p>{{description}}</p>
110+ </div>
111+ {{/each}}
112+ </div>
113+ </div>
114+ </script>
47115
48116 <!--
49117 Dependencies
@@ -55,8 +123,9 @@
55123 <script src="vendor/backbone.js?v=0.0.3"></script>
56124 <script src="vendor/hijs.js?v=0.0.3"></script>
57125 <script src="vendor/smoke.js?v=0.0.3"></script>
126+ <script src="bootstrap/js/bootstrap-dropdown.js"></script>
58127
59128 <!-- app -->
60- <script src="js/script.js?v=0.0.3"></script>
129+ <script src="js/script.js?v=0.0.4"></script>
61130 </body>
62131 </html>
js/old_script.js+144−0
@@ -0,0 +1,144 @@
1+$(function () {
2+ Tumblr = Backbone.Collection.extend({
3+ url: "http://api.tumblr.com/v2/blog/xonecas.tumblr.com/posts/text",
4+ page: 0,
5+ count: 6,
6+ idx: 0,
7+
8+ initialize: function () {
9+ _.bindAll(this, "setCurrent");
10+ this.bind('reset', this.setCurrent);
11+ },
12+
13+ parse: function (res, xhr) {
14+ this.total = res.response.total_posts;
15+ return res.response.posts;
16+ },
17+
18+ sync: function (model, method, options) {
19+ var params = _.extend(options, {
20+ "url": this.url,
21+ "data": {
22+ "limit": this.count,
23+ "offset": this.page * this.count,
24+ "api_key": "IM11cPEsi3jxTeSNwF8BB9Z08UItXcYKiEDLTLvl5RYn6MBcMD"
25+ },
26+ "dataType": "jsonp",
27+ "jsonp": "jsonp"
28+ });
29+
30+ return $.ajax(params);
31+ },
32+
33+ setCurrent: function () {
34+ this.current = this.at(this.idx);
35+ },
36+
37+ next: function () {
38+ this.idx++;
39+ if (this.idx + (this.count * this.page) === this.total) {
40+ this.trigger('error', 'At oldest post.');
41+ this.idx--;
42+ return;
43+ }
44+
45+ var model = this.at(this.idx);
46+
47+ if (model) {
48+ this.current = model;
49+ this.trigger('change');
50+ } else {
51+ this.page++;
52+ this.idx = 0;
53+ this.fetch();
54+ }
55+ },
56+
57+ previous: function () {
58+ this.idx--;
59+ var model = this.at(this.idx);
60+
61+ if (model) {
62+ this.current = model;
63+ this.trigger('change');
64+ } else {
65+ if (this.page > 0) {
66+ this.page--;
67+ this.idx = this.count -1;
68+ this.fetch();
69+ } else {
70+ this.idx++;
71+ this.trigger('error', 'At most recent post.');
72+ }
73+ }
74+
75+ }
76+ });
77+
78+ Page = Backbone.View.extend({
79+ id: 'main',
80+ className: 'container',
81+ tagName: 'section',
82+ template: Handlebars.compile($('#post_tmpl').html()),
83+ collection: new Tumblr(),
84+
85+ initialize: function () {
86+ this.header = new Header({
87+ 'collection': this.collection
88+ });
89+ this.header.render();
90+ _.bindAll(this, "render", "report");
91+ this.collection.bind('reset', this.render);
92+ this.collection.bind('error', this.report);
93+ this.collection.bind('change', this.render);
94+ this.collection.fetch();
95+
96+ $('body').append(this.el);
97+ },
98+
99+ report: function (err) {
100+ smoke.alert(err);
101+ },
102+
103+ render: function () {
104+ var model = this.collection.current;
105+ $(this.el)
106+ .css('display', 'none')
107+ .html(this.template(model.toJSON()))
108+ .fadeIn(1000);
109+ hijs('code');
110+ }
111+ });
112+
113+ Header = Backbone.View.extend({
114+ className: 'topbar',
115+ tagName: 'div',
116+ template: $('#header_tmpl').html(),
117+
118+ render: function () {
119+ $(this.el)
120+ .html(this.template)
121+ .appendTo('body');
122+ },
123+
124+ events: {
125+ "click #prev-post": "previous",
126+ "click #next-post": "next"
127+ },
128+
129+ previous: function (ev) {
130+ ev.preventDefault();
131+ this.collection.previous();
132+ return false;
133+ },
134+
135+ next: function (ev) {
136+ ev.preventDefault();
137+ this.collection.next();
138+ return false;
139+ }
140+ });
141+
142+ // main
143+ window.page = new Page();
144+});
js/script.js+145−72
@@ -1,17 +1,28 @@
1-$(function () {
2- Tumblr = Backbone.Collection.extend({
1+var xonecas = !function () {
2+
3+ function linkit (text) {
4+ text = text.replace(
5+ /(ftp|http|https|file):\/\/[\S]+(\b|$)/gim,
6+ '<a href="$&" target="_new">$&</a>');
7+ text = text.replace(/@\w+\s/gi, function (match) {
8+ match = match.substring(0, match.length -1);
9+ return '<a href="//twitter.com/'+match.substring(1)+'">'+match+'</a> ';
10+ });
11+
12+ return text;
13+ }
14+
15+ var Tumblr = Backbone.Collection.extend({
316 url: "http://api.tumblr.com/v2/blog/xonecas.tumblr.com/posts/text",
417 page: 0,
5- count: 6,
18+ count: 5,
619 idx: 0,
720
821 initialize: function () {
9- _.bindAll(this, "setCurrent");
10- this.bind('reset', this.setCurrent);
1122 },
1223
1324 parse: function (res, xhr) {
14- this.total = res.response.total_posts;
25+ this.total = Math.ceil(res.response.total_posts/this.count);
1526 return res.response.posts;
1627 },
1728
@@ -30,95 +41,82 @@ $(function () {
3041 return $.ajax(params);
3142 },
3243
33- setCurrent: function () {
34- this.current = this.at(this.idx);
35- },
36-
3744 next: function () {
38- this.idx++;
39- if (this.idx + (this.count * this.page) === this.total) {
40- this.trigger('error', 'At oldest post.');
41- this.idx--;
42- return;
43- }
44-
45- var model = this.at(this.idx);
46-
47- if (model) {
48- this.current = model;
49- this.trigger('change');
45+ if (this.page +1 === this.total) {
46+ this.trigger('error', "That's it, you've read it all!");
5047 } else {
5148 this.page++;
52- this.idx = 0;
5349 this.fetch();
5450 }
5551 },
5652
5753 previous: function () {
58- this.idx--;
59- var model = this.at(this.idx);
60-
61- if (model) {
62- this.current = model;
63- this.trigger('change');
54+ if (this.page -1 === -1) {
55+ this.trigger('error', "No newer posts.");
6456 } else {
65- if (this.page > 0) {
66- this.page--;
67- this.idx = this.count -1;
68- this.fetch();
69- } else {
70- this.idx++;
71- this.trigger('error', 'At most recent post.');
72- }
57+ this.page--;
58+ this.fetch();
7359 }
74-
7560 }
7661 });
7762
78- HomePage = Backbone.View.extend({
79- id: 'main',
80- className: 'container',
81- tagName: 'section',
82- template: Handlebars.compile($('#post_tmpl').html()),
83- collection: new Tumblr(),
63+ var Twitter = Backbone.Collection.extend({
64+ url: "http://api.twitter.com/1/statuses/user_timeline.json",
65+ count: 5,
8466
85- initialize: function () {
86- this.header = new Header({
87- 'collection': this.collection
67+ parse: function (res) {
68+ _.each(res, function (tweet) {
69+ tweet.text = linkit(tweet.text);
8870 });
89- this.header.render();
90- _.bindAll(this, "render", "report");
91- this.collection.bind('reset', this.render);
92- this.collection.bind('error', this.report);
93- this.collection.bind('change', this.render);
94- this.collection.fetch();
95-
96- $('body').append(this.el);
71+
72+ return res;
9773 },
9874
99- report: function (err) {
100- smoke.alert(err);
75+ sync: function (model, method, options) {
76+ var params = _.extend(options, {
77+ "url": this.url,
78+ "data": {
79+ "screen_name": "xonecas",
80+ "count": this.count,
81+ "trim_user": true,
82+ "include_rts": true,
83+ "exclude_replies": true
84+ },
85+ "dataType": "jsonp"
86+ });
87+
88+ return $.ajax(params);
89+ }
90+ });
91+
92+ Badges = Backbone.Collection.extend({
93+ url: "http://coderwall.com/xonecas.json",
94+
95+ parse: function (res, xhr) {
96+ return res.data.badges;
10197 },
98+
99+ sync: function (model, method, options) {
100+ var params = _.extend(options, {
101+ "url": this.url,
102+ "dataType": "jsonp"
103+ });
102104
103- render: function () {
104- var model = this.collection.current;
105- $(this.el)
106- .css('display', 'none')
107- .html(this.template(model.toJSON()))
108- .fadeIn(1000);
109- hijs('code');
105+ return $.ajax(params);
110106 }
111107 });
112108
113- Header = Backbone.View.extend({
109+
110+ var Header = Backbone.View.extend({
114111 className: 'topbar',
115- tagName: 'div',
116- template: $('#header_tmpl').html(),
112+ tagName: 'header',
113+ template: '#header_tmpl',
117114
118115 render: function () {
119116 $(this.el)
120- .html(this.template)
121- .appendTo('body');
117+ .html($(this.template).html())
118+ .appendTo('body')
119+ .dropdown();
122120 },
123121
124122 events: {
@@ -139,6 +137,81 @@ $(function () {
139137 }
140138 });
141139
142- // main
143- window.app = new HomePage();
144-});
140+ var Footer = Backbone.View.extend({
141+ className: 'container',
142+ tagName: 'footer',
143+ template: '#footer_tmpl',
144+
145+ initialize: function () {
146+ _.bindAll(this, "render");
147+ this.twitter = new Twitter();
148+ this.twitter.bind('reset', this.render);
149+ this.twitter.fetch();
150+
151+ this.badges = new Badges();
152+ this.badges.bind('reset', this.render);
153+ this.badges.fetch();
154+ },
155+
156+ render: function () {
157+ var
158+ template = Handlebars.compile($(this.template).html()),
159+ context = {
160+ twitter: this.twitter.toJSON(),
161+ badges: this.badges.toJSON()
162+ };
163+
164+ $(this.el)
165+ .html(template(context))
166+ .appendTo('body');
167+ }
168+ });
169+
170+ var Page = Backbone.View.extend({
171+ id: 'main',
172+ className: 'container',
173+ tagName: 'section',
174+ template: '#post_tmpl',
175+ collection: new Tumblr(),
176+
177+ initialize: function () {
178+ this.header = new Header({
179+ 'collection': this.collection
180+ });
181+ this.footer = new Footer();
182+ _.bindAll(this, "render", "report");
183+ this.collection.bind('reset', this.render);
184+ this.collection.bind('error', this.report);
185+ this.collection.bind('change', this.render);
186+ this.collection.fetch();
187+
188+ this.header.render();
189+ $('body').append(this.el);
190+ this.footer.render();
191+ },
192+
193+ report: function (err) {
194+ smoke.alert(err);
195+ },
196+
197+ render: function () {
198+ var
199+ html = "",
200+ template = Handlebars.compile($(this.template).html());
201+
202+ this.collection.each(function (model) {
203+ html += template(model.toJSON());
204+ });
205+
206+ $(this.el)
207+ .css('display', 'none')
208+ .html(html)
209+ .fadeIn(1000);
210+ hijs('code');
211+ }
212+ });
213+
214+ $(function () {
215+ window.page = new Page();
216+ });
217+} ();
server.js+7−0
@@ -15,6 +15,13 @@ var connect = require('connect'),
1515
1616 var routes = function (app) {
1717
18+ app.get('/reader', function (req, res, next) {
19+ res.writeHead(302, {
20+ 'content-type' : 'text/plain',
21+ 'location' : 'localhost:8081'
22+ });
23+ res.end('Redirect to reader');
24+ });
1825
1926 /* ------------------------------------------------------------------
2027 Keep this route last.
styles/base.less+14−1
@@ -1,8 +1,13 @@
11 @import "styles/smoke.css";
22
33 body {
4- margin-top: 50px;
4+ margin-top: 100px;
55 }
6+
7+article {
8+ margin: 0 0 140px 0;
9+}
10+
611 pre code {
712 background-color: #f5f5f5;
813 }
@@ -12,3 +17,11 @@ code .class, code .special { color: blue }
1217 code .number { color: red }
1318 code .comment { color: grey }
1419
20+.badge {
21+ width: 90px;
22+ height: 90px;
23+ position: relative;
24+ left: 20px;
25+ float: left;
26+ margin: 0 40px 20px 0;
27+}