]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/url.js
1 qwebirc
.ui
.urlificate = function(element
, text
, execfn
, cmdfn
, window
) {
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
, appendfn
);
25 var appendText = function(text
) {
26 qwebirc
.util
.NBSPCreate(text
, element
);
29 var appendChan = function(text
) {
30 var newtext
= text
.replace(punct_re
, "");
31 var punct
= text
.substring(newtext
.length
);
33 var a
= new Element("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
, appendfn
) {
46 var url
= text
.replace(punct_re
, "");
47 var punct
= text
.substring(url
.length
);
54 var ma
= url
.match(/^qwebirc:\/\/(.*)$/);
56 var m
= ma
[1].match(/^([^\/]+)\/(.+)$/);
62 var cmd
= cmdfn(m
[1], window
);
66 disptext
= unescape(m
[2]);
73 if(url
.match(/^www\./))
74 url
= "http://" + url
;
77 var a
= new Element("a");
82 a
.appendChild(document
.createTextNode(disptext
));
84 element
.appendChild(a
);
86 a
.addEvent("click", function(e
) { new Event(e
).stop(); fn(disptext
); });
91 txtprocess(text
, /\b((https
?|ftp
|qwebirc
):\/\/|www
\.)[^ ]+/, function(text
) {
92 txtprocess(text
, /\B
#[^ ,]+/, appendText
, appendChan
);