forked from koding/koding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.js
More file actions
executable file
·73 lines (66 loc) · 2.1 KB
/
Copy pathentry.js
File metadata and controls
executable file
·73 lines (66 loc) · 2.1 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
var $ = require('jquery-browserify');
var dnode = require('dnode');
$(document).ready(function () {
// Fetch the user's name before the main chat code fires
$('form#name').submit(function (ev) {
ev.preventDefault();
var name = $('input[name="name"]').val();
$('#messages').show();
$('#prompt').hide();
chat(name);
});
});
function chat (name) {
// Connect to the chat server now that we've got a name
dnode(function () {
this.name = name;
this.joined = function (who) {
addLine($('<div>')
.addClass('join')
.text(who + ' has joined')
);
};
this.parted = function (who) {
addLine($('<div>')
.addClass('part')
.text(who + ' has left')
);
};
this.said = function (who,msg) {
addLine($('<div>').append(
$('<span>')
.addClass(who == name ? 'me' : 'who')
.text('<' + who + '>')
,
$('<span>').addClass('msg').text(msg)
));
};
}).connect(function (remote) {
$('form#post').submit(function (ev) {
ev.preventDefault();
remote.say(this.elements.msg.value);
this.elements.msg.value = '';
});
// fetch a list of all the connected users
remote.names(function (names) {
addLine($('<div>')
.addClass('users')
.text('Users: ' + (
names.map(function (name) {
return '[ ' + name
.replace(/\\/g,'\\\\')
.replace(/\[/g,'\\[')
.replace(/\]/g,'\\]')
+ ' ]'
}).join(' ')
|| '(no users)'
))
);
});
});
}
function addLine(elem) {
var div = $('#messages');
div.append(elem);
div.animate({ scrollTop: div.attr('scrollHeight') }, 200);
}