@@ -1,272 +0,0 @@
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 TumblrSync = Backbone.Collection.extend({
16- type: 'text',
17-
18- parse: function (res, xhr) {
19- this.total = Math.ceil(res.response.total_posts/this.count);
20- return res.response.posts;
21- },
22-
23- sync: function (model, method, options) {
24- var params = _.extend(options, {
25- "url": this.url,
26- "data": {
27- "type": this.type,
28- "limit": this.count,
29- "offset": this.page * this.count,
30- "api_key": "IM11cPEsi3jxTeSNwF8BB9Z08UItXcYKiEDLTLvl5RYn6MBcMD"
31- },
32- "dataType": "jsonp",
33- "jsonp": "jsonp"
34- });
35-
36- return $.ajax(params);
37- },
38-
39- next: function () {
40- if (this.page +1 === this.total) {
41- this.trigger('error', "That's it, you've read it all!");
42- } else {
43- this.page++;
44- this.fetch();
45- }
46- },
47-
48- previous: function () {
49- if (this.page -1 === -1) {
50- this.trigger('error', "No newer posts.");
51- } else {
52- this.page--;
53- this.fetch();
54- }
55- }
56- });
57-
58- var Photos = TumblrSync.extend({
59- url: "http://api.tumblr.com/v2/blog/xonecas.tumblr.com/posts/photo",
60- page: 0,
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- }
80- });
81-
82- var Tumblr = TumblrSync.extend({
83- url: "http://api.tumblr.com/v2/blog/xonecas.tumblr.com/posts/text",
84- page: 0,
85- count: 5
86- });
87-
88- var Twitter = Backbone.Collection.extend({
89- url: "http://api.twitter.com/1/statuses/user_timeline.json",
90- count: 11,
91-
92- parse: function (res) {
93- _.each(res, function (tweet) {
94- tweet.text = linkit(tweet.text);
95- });
96-
97- return res;
98- },
99-
100- sync: function (model, method, options) {
101- var params = _.extend(options, {
102- "url": this.url,
103- "data": {
104- "screen_name": "xonecas",
105- "count": this.count,
106- "trim_user": true,
107- "include_rts": true,
108- "exclude_replies": true
109- },
110- "dataType": "jsonp"
111- });
112-
113- return $.ajax(params);
114- }
115- });
116-
117- var Badges = Backbone.Collection.extend({
118- url: "http://coderwall.com/xonecas.json",
119-
120- parse: function (res, xhr) {
121- return res.data.badges;
122- },
123-
124- sync: function (model, method, options) {
125- var params = _.extend(options, {
126- "url": this.url,
127- "dataType": "jsonp"
128- });
129-
130- return $.ajax(params);
131- }
132- });
133-
134-
135- var Header = Backbone.View.extend({
136- className: 'topbar',
137- tagName: 'header',
138- template: Handlebars.templates['header-tmpl.html'],
139-
140- initialize: function () {
141- $(this.el).appendTo('body');
142- },
143-
144- render: function () {
145- $(this.el)
146- .html(this.template())
147- .dropdown();
148- },
149-
150- events: {
151- "click #prev-post": "previous",
152- "click #next-post": "next"
153- },
154-
155- previous: function (ev) {
156- ev.preventDefault();
157- this.collection.previous();
158- return false;
159- },
160-
161- next: function (ev) {
162- ev.preventDefault();
163- this.collection.next();
164- return false;
165- }
166- });
167-
168- var Footer = Backbone.View.extend({
169- className: 'container',
170- tagName: 'footer',
171- template: '#footer_tmpl',
172-
173- initialize: function () {
174- $(this.el).appendTo('body');
175- _.bindAll(this, "render");
176- this.twitter = new Twitter();
177- this.twitter.bind('reset', this.render);
178- this.twitter.fetch();
179-
180- this.badges = new Badges();
181- this.badges.bind('reset', this.render);
182- this.badges.fetch();
183- },
184-
185- render: function () {
186- var
187- template = Handlebars.compile($(this.template).html()),
188- context = {
189- twitter: this.twitter.toJSON(),
190- badges: this.badges.toJSON()
191- };
192-
193- $(this.el)
194- .html(template(context));
195- }
196- });
197-
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-
220- var Page = Backbone.View.extend({
221- id: 'main',
222- className: 'container',
223- tagName: 'section',
224- template: '#post_tmpl',
225- collection: new Tumblr(),
226-
227- initialize: function () {
228- this.header = new Header({
229- 'collection': this.collection
230- });
231- $('body').append(this.el);
232- this.media = new Media();
233- this.footer = new Footer();
234- _.bindAll(this, "render", "report");
235- this.collection.bind('reset', this.render);
236- this.collection.bind('error', this.report);
237- this.collection.bind('change', this.render);
238- this.collection.fetch();
239- this.header.render();
240- this.media.render();
241- this.footer.render();
242- },
243-
244- report: function (err) {
245- smoke.alert(err);
246- },
247-
248- render: function () {
249- var
250- html = "",
251- template = Handlebars.compile($(this.template).html());
252-
253- this.collection.each(function (model) {
254- html += template(model.toJSON());
255- });
256-
257- $(this.el)
258- .css('display', 'none')
259- .html(html)
260- .fadeIn(1000);
261-
262- if (window.scrollY > 310) {
263- window.scrollTo(0, 310);
264- }
265- hijs('code');
266- }
267- });
268-
269- $(function () {
270- window.page = new Page();
271- });
272-} ();