This repository was archived by the owner on Apr 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapplication.js
More file actions
118 lines (96 loc) · 3.17 KB
/
Copy pathapplication.js
File metadata and controls
118 lines (96 loc) · 3.17 KB
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
118
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require showdown
function get_gist_comments(gist_id, element){
converter = new Showdown.converter();
$.getJSON(
'https://gist.github.com/api/v1/json/' + gist_id + '?callback=?', function(response){
$.each(response['gists'][0]['comments'], function(key, val) {
element.append(
'<div>' +
'<img class="gravatar" src="http://gravatar.com/avatar/' + val.gravatar_id + '.png?r=PG&s=20"/> ' +
val.user + converter.makeHtml(val.body) +
'</div>'
);
});
}
);
}
$(document).ready(function(){
$('.comments').each(function(){
get_gist_comments($(this).data('gist_id'), $(this));
});
$('a.extend').click(function(){
$(this).parent().css('height', 'auto');
$(this).remove();
});
$('ul#entries.voting li.unvoted div.files').css('height', 'auto');
$('ul#entries.voting li.unvoted a.extend').hide();
$('li.unvoted .new_vote input[type="submit"]').hide();
$('.new_vote input').change(function(){
$(this).parent().submit();
window.location = '#'
})
var unvoted = $('li.unvoted')
unvoted.hide();
if(unvoted.length > 0) {
$('.message').after('<a class="button vote">Vote</a>');
}
$('a.vote').click(function(){
var lis = $('ul#entries li.unvoted');
lis.sort(function() { return 0.5 - Math.random() })
var index = 0;
var li = lis[index];
if(lis.length >= 1){
form = lis.find('form')
form.
append('<span class="skip">or <a href="#">skip this entry</a></span>').
append('<span class="entries_left"/>')
if(lis.length <= 1){
$('span.skip').hide();
$('span.entries_left').text('You\'re at the last entry')
} else {
$('span.entries_left').text(lis.length + ' entries left to rate');
}
}
$('ul.voting').addClass('voting_box')
$('ul.voting').after('<div class="overlay"/>')
$('div.overlay').click(function(){
window.location.reload();
})
$('ul#entries li.voted, ul#entries li.unvoted').hide();
$(li).show();
$('ul#entries span.skip a').click(function(){
$(li).hide()
index ++
if(index >= lis.length){ index = 0; }
li = lis[index]
$(li).show()
})
$('.new_vote').bind('ajax:success', function() {
lis.splice(index, 1);
if(lis.length <= 1){
$('span.skip').hide();
$('span.entries_left').text('You\'re at the last entry')
} else {
$('span.entries_left').text(lis.length + ' entries left to rate');
}
index ++
if(index >= lis.length){ index = 0; }
next_li = lis[index]
if($(next_li).length > 0) {
$(li).hide()
$(next_li).show()
li = next_li
} else {
window.location.reload()
}
});
});
});