]>
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("span");
35 a
.addClass("hyperlink-channel");
36 a
.addEvent("click", function(e
) {
38 execfn("/JOIN " + newtext
);
40 a
.appendChild(document
.createTextNode(newtext
));
41 element
.appendChild(a
);
46 var appendURL = function(text
, appendfn
) {
47 var url
= text
.replace(punct_re
, "");
48 var punct
= text
.substring(url
.length
);
54 var elementType
= "a";
57 var ma
= url
.match(/^qwebirc:\/\/(.*)$/);
59 var m
= ma
[1].match(/^([^\/]+)\/([^\/]+)\/?(.*)$/);
65 var cmd
= cmdfn(m
[1], window
);
75 disptext
= unescape(m
[2]);
84 if(url
.match(/^www\./))
85 url
= "http://" + url
;
88 var a
= new Element(elementType
);
90 a
.addClass("hyperlink-" + addClass
);
98 a
.appendChild(document
.createTextNode(disptext
));
100 element
.appendChild(a
);
102 a
.addEvent("click", function(e
) { new Event(e
).stop(); fn(disptext
); });
107 txtprocess(text
, /\b((https
?|ftp
|qwebirc
):\/\/|www
\.)[^ ]+/, function(text
) {
108 txtprocess(text
, /\B
#[^ ,]+/, appendText
, appendChan
);