]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/url.js
1 function urlificate(element
, text
, execfn
) {
2 var punct_re
= /(\.*|\,|;)$/;
4 var txtprocess = function(text
, regex
, appendfn
, matchfn
) {
6 var index
= text
.search(regex
);
11 var match
= text
.match(regex
);
13 var before
= text
.substring(0, index
);
14 var matched
= match
[0];
15 var after
= text
.substring(index
+ matched
.length
);
18 var more
= matchfn(matched
);
25 var appendText = function(text
) {
26 element
.appendChild(document
.createTextNode(text
));
29 var appendChan = function(text
) {
30 var newtext
= text
.replace(punct_re
, "");
31 var punct
= text
.substring(newtext
.length
);
33 var a
= document
.createElement("a");
35 a
.addEvent("click", function(e
) {
37 execfn("/JOIN " + newtext
);
39 a
.appendChild(document
.createTextNode(newtext
));
40 element
.appendChild(a
);
45 var appendURL = function(text
) {
46 var newtext
= text
.replace(punct_re
, "");
47 var punct
= text
.substring(newtext
.length
);
49 var a
= document
.createElement("a");
52 a
.appendChild(document
.createTextNode(newtext
));
53 element
.appendChild(a
);
58 txtprocess(text
, /\bhttp:\/\/[^ ]+/, function(text
) {
59 txtprocess(text
, /\B
#[^ ,]+/, appendText
, appendChan
);