]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/url.js
Alt hotkeys should stop the event.
[irc/quakenet/qwebirc.git] / js / ui / url.js
CommitLineData
83f9b8b2
CP
1var url_re = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/;
2
3function urlificate(element, text) {
4 function appendText(text) {
5 element.appendChild(document.createTextNode(text));
6 }
7 function appendA(text) {
8 var a = document.createElement("a");
9 a.href = text;
10 a.target = "new";
11 a.appendChild(document.createTextNode(text));
12
13 element.appendChild(a);
14 }
15
16 for(;;) {
17 var index = text.search(url_re);
18 if(index == -1) {
19 appendText(text);
20 break;
21 }
22 var match = text.match(url_re);
23
24 before = text.substring(0, index);
25 matched = match[0];
26 after = text.substring(index + matched.length);
27 text = after;
28 appendText(before);
29 appendA(matched, before);
30 }
31}