Skip to content

Commit e7470ef

Browse files
committed
Normalize all the line endings
1 parent cab4b50 commit e7470ef

File tree

1 file changed

+192
-192
lines changed

1 file changed

+192
-192
lines changed

vimmers/main2.js

Lines changed: 192 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,192 @@
1-
// vim:set ts=8 sts=2 sw=2 tw=0 et:
2-
(function(global){
3-
4-
var VIMMERS_DATA_URL = "http://vim-jp.herokuapp.com/vimmers?callback=?";
5-
var DEFAULT_LIMITS = 50;
6-
7-
var allVimmers = [];
8-
9-
function main() {
10-
var ractive;
11-
12-
ractive = new Ractive({
13-
debug: true,
14-
el: '#vimmers-body',
15-
template: '#vimmers-template',
16-
data: {
17-
persons: [],
18-
all: false
19-
}
20-
});
21-
ractive.on({
22-
shuffle: onShuffle,
23-
showAll: onShowAll
24-
});
25-
loadJSON(VIMMERS_DATA_URL).then(onFirstLoad.bind(ractive));
26-
}
27-
28-
function loadJSON(url) {
29-
return new Promise(function(resolve, reject) {
30-
$.getJSON(url, function(data) {
31-
resolve(data);
32-
});
33-
});
34-
}
35-
36-
function loadGithubIcon(id) {
37-
return loadJSON('https://api.github.com/users/' + id + '?callback=?');
38-
}
39-
40-
function toVimmerData(raw, delay) {
41-
var v;
42-
43-
v = {
44-
name: raw.name,
45-
shortName: raw.short_name,
46-
desc: raw.description,
47-
face_icon_url: raw.logo,
48-
links: []
49-
};
50-
51-
if (raw.twitter) {
52-
if (!v.face_icon_url && raw.twitter_icon) {
53-
v.face_icon_url = raw.twitter_icon;
54-
}
55-
v.links.push({
56-
url: 'https://twitter.com/' + raw.twitter,
57-
type: 'Twitter',
58-
icon_url: '/assets/images/icon-twitter.png'
59-
});
60-
}
61-
62-
if (raw.github) {
63-
if (!v.face_icon_url) {
64-
v.face_icon_url = '/assets/images/icon-loading.gif';
65-
delay(loadGithubIcon(raw.github).then(function(res) {
66-
try {
67-
if (res.data.avatar_url) {
68-
v.face_icon_url = res.data.avatar_url;
69-
} else {
70-
// FIXME: set rate limited error image.
71-
v.face_icon_url = null;
72-
console.warn('may reached rate limit of Github API for '
73-
+ raw.name);
74-
}
75-
} catch (e) {
76-
console.error(e.stack);
77-
}
78-
}));
79-
}
80-
v.links.push({
81-
url: 'https://github.com/' + raw.github,
82-
type: 'Github',
83-
icon_url: '/assets/images/icon-github.png'
84-
});
85-
}
86-
87-
if (raw.facebook) {
88-
v.links.push({
89-
url: 'https://www.facebook.com/' + raw.facebook,
90-
type: 'Facebook',
91-
icon_url: '/assets/images/icon-facebook.png'
92-
});
93-
}
94-
95-
if (raw.googleplus) {
96-
v.links.push({
97-
url: 'https://plus.google.com/' + raw.googleplus,
98-
type: 'Google+',
99-
icon_url: '/assets/images/icon-googleplus.png'
100-
});
101-
}
102-
103-
if (raw.website) {
104-
v.links.push({
105-
url: raw.website,
106-
type: 'WebSite',
107-
icon_url: '/assets/images/icon-website.png'
108-
});
109-
}
110-
111-
if (raw.vimorg) {
112-
v.links.push({
113-
url: 'http://www.vim.org/account/profile.php?user_id=' + raw.vimorg,
114-
type: 'Vim',
115-
icon_url: '/assets/images/icon-vim.png'
116-
});
117-
}
118-
119-
return v;
120-
}
121-
122-
function showVimmers(ractive, all) {
123-
var order, persons;
124-
125-
order = getShuffledNumbers(allVimmers.length);
126-
if (!all) {
127-
order = order.splice(0, DEFAULT_LIMITS);
128-
}
129-
persons = _.map(order, function(index) {
130-
return allVimmers[index];
131-
});
132-
133-
ractive.set({
134-
persons: persons,
135-
all: all
136-
});
137-
}
138-
139-
function getShuffledNumbers(max) {
140-
var rows = _.range(max);
141-
var i, n, tmp;
142-
143-
// Start from 1, to keep Mr.Bram at first.
144-
for (i = 1; i < max - 1; ++i) {
145-
n = Math.floor((max - i) * Math.random()) + i;
146-
if (n != i) {
147-
tmp = rows[i];
148-
rows[i] = rows[n];
149-
rows[n] = tmp;
150-
}
151-
}
152-
return rows;
153-
}
154-
155-
function onFirstLoad(data) {
156-
var ractive, delays;
157-
158-
ractive = this;
159-
try {
160-
delays = [];
161-
allVimmers = _.map(data, function(raw) {
162-
return toVimmerData(raw, function(promise) {
163-
delays.push(promise);
164-
});
165-
});
166-
showVimmers(ractive, false);
167-
Promise.all(delays).then(function() {
168-
ractive.update();
169-
});
170-
171-
$('#vimmers-container').masonry({
172-
isAnimated: true,
173-
isResizable: true
174-
});
175-
} catch (e) {
176-
console.error(e.stack);
177-
}
178-
}
179-
180-
function onShuffle(e) {
181-
showVimmers(this, this.get('all'));
182-
$('#vimmers-container').masonry('reload');
183-
}
184-
185-
function onShowAll(e) {
186-
showVimmers(this, true);
187-
$('#vimmers-container').masonry('reload');
188-
}
189-
190-
global.addEventListener('load', main);
191-
192-
})(this);
1+
// vim:set ts=8 sts=2 sw=2 tw=0 et:
2+
(function(global){
3+
4+
var VIMMERS_DATA_URL = "http://vim-jp.herokuapp.com/vimmers?callback=?";
5+
var DEFAULT_LIMITS = 50;
6+
7+
var allVimmers = [];
8+
9+
function main() {
10+
var ractive;
11+
12+
ractive = new Ractive({
13+
debug: true,
14+
el: '#vimmers-body',
15+
template: '#vimmers-template',
16+
data: {
17+
persons: [],
18+
all: false
19+
}
20+
});
21+
ractive.on({
22+
shuffle: onShuffle,
23+
showAll: onShowAll
24+
});
25+
loadJSON(VIMMERS_DATA_URL).then(onFirstLoad.bind(ractive));
26+
}
27+
28+
function loadJSON(url) {
29+
return new Promise(function(resolve, reject) {
30+
$.getJSON(url, function(data) {
31+
resolve(data);
32+
});
33+
});
34+
}
35+
36+
function loadGithubIcon(id) {
37+
return loadJSON('https://api.github.com/users/' + id + '?callback=?');
38+
}
39+
40+
function toVimmerData(raw, delay) {
41+
var v;
42+
43+
v = {
44+
name: raw.name,
45+
shortName: raw.short_name,
46+
desc: raw.description,
47+
face_icon_url: raw.logo,
48+
links: []
49+
};
50+
51+
if (raw.twitter) {
52+
if (!v.face_icon_url && raw.twitter_icon) {
53+
v.face_icon_url = raw.twitter_icon;
54+
}
55+
v.links.push({
56+
url: 'https://twitter.com/' + raw.twitter,
57+
type: 'Twitter',
58+
icon_url: '/assets/images/icon-twitter.png'
59+
});
60+
}
61+
62+
if (raw.github) {
63+
if (!v.face_icon_url) {
64+
v.face_icon_url = '/assets/images/icon-loading.gif';
65+
delay(loadGithubIcon(raw.github).then(function(res) {
66+
try {
67+
if (res.data.avatar_url) {
68+
v.face_icon_url = res.data.avatar_url;
69+
} else {
70+
// FIXME: set rate limited error image.
71+
v.face_icon_url = null;
72+
console.warn('may reached rate limit of Github API for '
73+
+ raw.name);
74+
}
75+
} catch (e) {
76+
console.error(e.stack);
77+
}
78+
}));
79+
}
80+
v.links.push({
81+
url: 'https://github.com/' + raw.github,
82+
type: 'Github',
83+
icon_url: '/assets/images/icon-github.png'
84+
});
85+
}
86+
87+
if (raw.facebook) {
88+
v.links.push({
89+
url: 'https://www.facebook.com/' + raw.facebook,
90+
type: 'Facebook',
91+
icon_url: '/assets/images/icon-facebook.png'
92+
});
93+
}
94+
95+
if (raw.googleplus) {
96+
v.links.push({
97+
url: 'https://plus.google.com/' + raw.googleplus,
98+
type: 'Google+',
99+
icon_url: '/assets/images/icon-googleplus.png'
100+
});
101+
}
102+
103+
if (raw.website) {
104+
v.links.push({
105+
url: raw.website,
106+
type: 'WebSite',
107+
icon_url: '/assets/images/icon-website.png'
108+
});
109+
}
110+
111+
if (raw.vimorg) {
112+
v.links.push({
113+
url: 'http://www.vim.org/account/profile.php?user_id=' + raw.vimorg,
114+
type: 'Vim',
115+
icon_url: '/assets/images/icon-vim.png'
116+
});
117+
}
118+
119+
return v;
120+
}
121+
122+
function showVimmers(ractive, all) {
123+
var order, persons;
124+
125+
order = getShuffledNumbers(allVimmers.length);
126+
if (!all) {
127+
order = order.splice(0, DEFAULT_LIMITS);
128+
}
129+
persons = _.map(order, function(index) {
130+
return allVimmers[index];
131+
});
132+
133+
ractive.set({
134+
persons: persons,
135+
all: all
136+
});
137+
}
138+
139+
function getShuffledNumbers(max) {
140+
var rows = _.range(max);
141+
var i, n, tmp;
142+
143+
// Start from 1, to keep Mr.Bram at first.
144+
for (i = 1; i < max - 1; ++i) {
145+
n = Math.floor((max - i) * Math.random()) + i;
146+
if (n != i) {
147+
tmp = rows[i];
148+
rows[i] = rows[n];
149+
rows[n] = tmp;
150+
}
151+
}
152+
return rows;
153+
}
154+
155+
function onFirstLoad(data) {
156+
var ractive, delays;
157+
158+
ractive = this;
159+
try {
160+
delays = [];
161+
allVimmers = _.map(data, function(raw) {
162+
return toVimmerData(raw, function(promise) {
163+
delays.push(promise);
164+
});
165+
});
166+
showVimmers(ractive, false);
167+
Promise.all(delays).then(function() {
168+
ractive.update();
169+
});
170+
171+
$('#vimmers-container').masonry({
172+
isAnimated: true,
173+
isResizable: true
174+
});
175+
} catch (e) {
176+
console.error(e.stack);
177+
}
178+
}
179+
180+
function onShuffle(e) {
181+
showVimmers(this, this.get('all'));
182+
$('#vimmers-container').masonry('reload');
183+
}
184+
185+
function onShowAll(e) {
186+
showVimmers(this, true);
187+
$('#vimmers-container').masonry('reload');
188+
}
189+
190+
global.addEventListener('load', main);
191+
192+
})(this);

0 commit comments

Comments
 (0)