]>
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
= /[[\)|\]]?(\.*|[\,;])$/;
5 var txtprocess = function(text
, regex
, appendfn
, matchfn
) {
7 var index
= text
.search(regex
);
12 var match
= text
.match(regex
);
14 var before
= text
.substring(0, index
);
15 var matched
= match
[0];
16 var after
= text
.substring(index
+ matched
.length
);
19 var more
= matchfn(matched
, appendfn
);
26 var appendText = function(text
) {
28 qwebirc
.util
.NBSPCreate(text
, element
);
31 var appendChan = function(text
) {
32 var newtext
= text
.replace(punct_re
, "");
33 addedText
.push(newtext
);
34 var punct
= text
.substring(newtext
.length
);
36 var a
= new Element("span");
38 a
.addClass("hyperlink-channel");
39 a
.addEvent("click", function(e
) {
41 execfn("/JOIN " + newtext
);
43 a
.appendChild(document
.createTextNode(newtext
));
44 element
.appendChild(a
);
49 var appendURL = function(text
, appendfn
) {
50 var url
= text
.replace(punct_re
, "");
51 var punct
= text
.substring(url
.length
);
57 var elementType
= "a";
60 var ma
= url
.match(/^qwebirc:\/\/(.*)$/);
62 var m
= ma
[1].match(/^([^\/]+)\/([^\/]+)\/?(.*)$/);
68 var cmd
= cmdfn(m
[1], window
);
78 disptext
= unescape(m
[2]);
87 if(url
.match(/^www\./))
88 url
= "http://" + url
;
91 var a
= new Element(elementType
);
93 a
.addClass("hyperlink-" + addClass
);
101 addedText
.push(disptext
);
102 a
.appendChild(document
.createTextNode(disptext
));
104 element
.appendChild(a
);
106 a
.addEvent("click", function(e
) { new Event(e
).stop(); fn(disptext
); });
111 txtprocess(text
, /\b((https
?|ftp
|qwebirc
):\/\/|www
\.)[^ ]+/, function(text
) {
112 txtprocess(text
, /\B
#[^ ,]+/, appendText
, appendChan
);
115 return addedText
.join("");