]>
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
);
53 var elementType
= "a";
56 var ma
= url
.match(/^qwebirc:\/\/(.*)$/);
58 var m
= ma
[1].match(/^([^\/]+)\/([^\/]+)\/?(.*)$/);
64 var cmd
= cmdfn(m
[1], window
);
74 disptext
= unescape(m
[2]);
83 if(url
.match(/^www\./))
84 url
= "http://" + url
;
87 var a
= new Element(elementType
);
89 a
.addClass("hyperlink-" + addClass
);
97 a
.appendChild(document
.createTextNode(disptext
));
99 element
.appendChild(a
);
101 a
.addEvent("click", function(e
) { new Event(e
).stop(); fn(disptext
); });
106 txtprocess(text
, /\b((https
?|ftp
|qwebirc
):\/\/|www
\.)[^ ]+/, function(text
) {
107 txtprocess(text
, /\B
#[^ ,]+/, appendText
, appendChan
);