-
Notifications
You must be signed in to change notification settings - Fork 0
/
watched.coffee
117 lines (102 loc) · 2.83 KB
/
watched.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# https://gist.github.com/1290439
$.fn.spin = (opts) ->
(($) ->
$.fn.spin = (opts, color) ->
presets =
tiny:
lines: 8
length: 2
width: 2
radius: 3
small:
lines: 8
length: 4
width: 3
radius: 5
large:
lines: 10
length: 8
width: 4
radius: 8
if Spinner
@each ->
$this = $(this)
data = $this.data()
if data.spinner
data.spinner.stop()
delete data.spinner
if opts isnt false
if typeof opts is "string"
if opts of presets
opts = presets[opts]
else
opts = {}
opts.color = color if color
data.spinner = new Spinner($.extend(
color: $this.css("color")
, opts)).spin(this)
else
throw "Spinner class not available."
) jQuery
get_user = ($formfield) ->
uri = "users/#{ $formfield.val() }"
$formfield.blur()
routie uri
render_table = (repos, name, table="table") ->
$table = $(table)
$tbody = $table.children "tbody:first"
template = """
{{#array}}
<tr>
<td><a href="{{html_url}}" title="{{full_name}}">{{name}}</a></td>
<td>{{description}}</td>
<td><img src="{{owner.avatar_url}}"> <a href="#users/{{owner.login}}">{{owner.login}}</a></td>
<td>{{watchers}}</td>
<td>{{language}}</td>
</tr>
{{/array}}
"""
html = Mustache.to_html template, { array: repos }
if repos
amount = repos.length
else
amount = 0
$("header p").html Mustache.to_html '<a href="https://github.com/{{name}}">{{name}}</a> ({{amount}})', { name: name, amount: amount}
$tbody.hide()
$tbody.html(html)
$tbody.fadeIn 1200
$table.stupidtable()
$("#spinner").spin false
get_repos = (user) ->
$("#spinner").spin "large"
firstUrl = "https://api.github.com/users/#{ user }/starred?page=1&per_page=100&callback=?"
allRepos = []
get_repo = (page) ->
$.ajax page,
jsonpCallback: 'jsonCallback',
contentType: "application/json",
dataType: 'jsonp',
cache: true,
success : (data, status, xhr) ->
if data.meta.status isnt 200
$("#spinner").spin false
$("tbody:first").fadeOut 'slow'
$("tbody:first").empty()
$("header p").html "User not found."
return
allRepos = allRepos.concat data.data
if data.meta['Link']
next = entry[0] for entry in data.meta['Link'] when entry[1]['rel'] == 'next'
if next
get_repo next
else
render_table allRepos, user
get_repo firstUrl
$(document).ready ->
routie('users/:name',
(name) ->
get_repos(name)
document.title = name + " (Watched Repositories)"
)
$("form:first").submit ->
get_user $("input:first")