]>
jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/jslib.js
1 if( typeof XMLHttpRequest
== "undefined" ) XMLHttpRequest = function() {
2 try{ return new ActiveXObject("Msxml2.XMLHTTP.6.0") }catch(e
){}
3 try{ return new ActiveXObject("Msxml2.XMLHTTP.3.0") }catch(e
){}
4 try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e
){}
5 try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e
){}
6 throw new Error("This browser does not support XMLHttpRequest or XMLHTTP.")
9 function jsdecode(data
) {
10 return eval('(' + data
+ ')');
13 function XHR(url
, fn
) {
14 var r
= new XMLHttpRequest();
15 r
.onreadystatechange = function() {
16 if(r
.readyState
== 4 && r
.status
== 200) {
17 var o
= jsdecode(r
.responseText
);
21 r
.open("GET", url
, true);
34 return p
[p
.length
+ d
];
39 var forEach = function(x
, fn
) {
40 for(var i
=0;i
<x
.length
;i
++)
45 /* how horribly inefficient */
46 String
.prototype.replaceAll = function(f
, t
) {
47 var i
= this.indexOf(f
);
57 /* how horribly inefficient (again) */
58 String
.prototype.splitMax = function(by
, max
) {
59 var items
= this.split(by
);
60 var newitems
= items
.slice(0, max
-1);
62 if(items
.length
>= max
)
63 newitems
.push(items
.slice(max
-1).join(by
));
68 alert("a".splitMax(" ", 2));
69 alert("a b".splitMax(" ", 2));
70 alert("a b c".splitMax(" ", 2));
71 alert("a b".splitMax(" ", 3));
72 alert("a b c".splitMax(" ", 3));
73 alert("a".splitMax(" ", 4));
74 alert("a b".splitMax(" ", 4));
75 alert("a b c".splitMax(" ", 4));
76 alert("a".splitMax(" ", 1));
77 alert("a b".splitMax(" ", 1));
78 alert("a b c".splitMax(" ", 1));