]> jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/jslib.js
11b7c70c598312c27dccb97c13084372fd5ec6fc
[irc/quakenet/qwebirc.git] / 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.")
7 };
8
9 function jsdecode(data) {
10 return eval('(' + data + ')');
11 }
12
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);
18 fn(o);
19 }
20 }
21 r.open("GET", url, true);
22 r.send(null);
23 }
24
25 function empty(y) {
26 for(var x in y) {
27 return false;
28 }
29 return true;
30 }
31
32 function ANI(p, d) {
33 if(d < 0)
34 return p[p.length + d];
35
36 return p[d];
37 }
38
39 var forEach = function(x, fn) {
40 for(var i=0;i<x.length;i++)
41 if(fn(x[i]))
42 return;
43 }