|
|
@ -5,6 +5,11 @@
|
|
5
|
5
|
<meta charset="utf-8" />
|
|
6
|
6
|
|
|
7
|
7
|
<style type="text/css">
|
|
|
8
|
#messages img {
|
|
|
9
|
max-width: 500px;
|
|
|
10
|
max-height: 350px;
|
|
|
11
|
}
|
|
|
12
|
|
|
8
|
13
|
#input {
|
|
9
|
14
|
float: left;
|
|
10
|
15
|
width: 100%;
|
|
|
@ -32,10 +37,54 @@
|
|
32
|
37
|
}
|
|
33
|
38
|
}
|
|
34
|
39
|
|
|
|
40
|
var word_matchers = [{
|
|
|
41
|
re: /https?:\/\/.*youtube.com\/watch\?v=([a-zA-Z0-9-]+).*/,
|
|
|
42
|
fn: function(match) {
|
|
|
43
|
var el = document.createElement("iframe");
|
|
|
44
|
el.src = "http://www.youtube.com/embed/" + match[1];
|
|
|
45
|
el.width = 420;
|
|
|
46
|
el.height = 315;
|
|
|
47
|
el.setAttribute("frameborder", 0);
|
|
|
48
|
return el;
|
|
|
49
|
}
|
|
|
50
|
}, {
|
|
|
51
|
re: /https?:\/\/vimeo.com\/([0-9]+).*/,
|
|
|
52
|
fn: function(match) {
|
|
|
53
|
var el = document.createElement("iframe");
|
|
|
54
|
el.src = "http://player.vimeo.com/video/" + match[1];
|
|
|
55
|
el.width = 420;
|
|
|
56
|
el.height = 315;
|
|
|
57
|
el.setAttribute("frameborder", 0);
|
|
|
58
|
return el;
|
|
|
59
|
}
|
|
|
60
|
}, {
|
|
|
61
|
re: /https?:\/\/.*(png|gif|jpg|jpeg)$/i,
|
|
|
62
|
fn: function(match) {
|
|
|
63
|
var el = document.createElement("img");
|
|
|
64
|
el.src = match[0];
|
|
|
65
|
return el;
|
|
|
66
|
}
|
|
|
67
|
}, { re: /.*/, fn: function(match) { return new Text(match[0]); }}];
|
|
|
68
|
|
|
|
69
|
function expandWord(word) {
|
|
|
70
|
for (var i = 0; i < word_matchers.length; i++) {
|
|
|
71
|
var matcher = word_matchers[i];
|
|
|
72
|
var match = word.match(matcher.re);
|
|
|
73
|
if (match) {
|
|
|
74
|
return matcher.fn(match);
|
|
|
75
|
}
|
|
|
76
|
}
|
|
|
77
|
}
|
|
|
78
|
|
|
35
|
79
|
function displayMessage(msg) {
|
|
36
|
80
|
var msgEl = document.createElement("pre");
|
|
37
|
81
|
var msgDate = new Date(msg.timestamp);
|
|
38
|
|
msgEl.textContent = msgDate.toLocaleTimeString() + " - " + msg.author + ": " + msg.content;
|
|
|
82
|
msgEl.textContent = msgDate.toLocaleTimeString() + " - " + msg.author + ": ";
|
|
|
83
|
var words = msg.content.split(/\s/);
|
|
|
84
|
for (var i = 0; i < words.length; i++) {
|
|
|
85
|
msgEl.appendChild(new Text(" "));
|
|
|
86
|
msgEl.appendChild(expandWord(words[i]));
|
|
|
87
|
}
|
|
39
|
88
|
messagesEl.appendChild(msgEl);
|
|
40
|
89
|
if (window.scrollY >= window.scrollMaxY - 2 * inputEl.clientHeight) {
|
|
41
|
90
|
msgEl.scrollIntoView();
|