forked from cchan/lexhack-live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed.js
123 lines (112 loc) · 2.85 KB
/
feed.js
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
119
120
121
122
123
$(document).ready(function() {
var roomParam = location.search.split('room=')[1];
if(roomParam) {
$("#room-input").val(roomParam);
}
updateSkills();
updateAnnouncements();
$("#summon-mentor").on("click", function() {
$.ajax({
url:"http://api.lexhack.org:3000/request",
type: "POST",
dataType: "json",
data: {
room: $("#room-input").val(),
skill: $("#skill-select").val()
},
success: function(json) {
console.log("success!");
console.log(json);
if(!json["status"]) {
$("#mentors-requested").append($("<li></li>")
.append($("<span></span>")
.text(json.name + " - " + $("#skill-select").val() + " "))
.append($("<a></a>")
.attr("href", "#")
.attr("class", "clear-link")
.attr("id", json._id)
.attr("onclick", "clearMentor('"+json._id+"');")
.text("clear")));
}
},
error: function(xhr, status, error) {
console.log("ERROR");
console.log(status);
},
complete: function(xhr, status) {
}
});
});
setInterval(updateAnnouncements, 30000);
});
var clearMentor = function(id) {
console.log("ok fam");
$.ajax({
url:"http://api.lexhack.org:3000/clear-mentor",
type: "POST",
dataType: "json",
data: {
id: id,
},
success: function(json) {
console.log("success!");
console.log($('a[id='+id+']'));
$('a[id='+id+']').parent().remove();
},
error: function(xhr, status, error) {
console.log("ERROR");
console.log(status);
},
complete: function(xhr, status) {
}
});
}
var updateAnnouncements = function() {
$.ajax({
url: "http://api.lexhack.org:3000/announcements",
type:"GET",
dataType: "json",
success: function(json) {
$("#announcements-list").text("");
$.each(json, function(index, value) {
var d = new Date(value.date);
$("#announcements-list")
.append($("<h4></h4")
.html(replaceURLWithHTMLLinks(value.body)))
.append($("<p></p>")
.text(d.toLocaleTimeString()));
})
},
error: function(xhr, status, error) {
console.log("ERROR");
console.log(status);
},
complete: function(xhr, status) {
}
})
};
var replaceURLWithHTMLLinks = function(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
return text.replace(exp,"<a href='$1'>$1</a>");
}
var updateSkills = function() {
$.ajax({
url: "http://api.lexhack.org:3000/available",
type: "GET",
dataType : "json",
success: function(json) {
$.each(json.languages, function(index, value) {
$('#skill-select')
.append($("<option></option>")
.attr("value",value)
.text(value));
});
},
error: function(xhr, status, error) {
console.log("ERROR");
console.log(status);
},
complete: function(xhr, status) {
}
});
}