-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislib_examples.js
40 lines (36 loc) · 1.03 KB
/
islib_examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/** author: lo sauer,'11
Examples using the islib
MIT license applies
*/
var x = [];
x[100] = 1;
x.length
is.NoElements(x) == 1 ? "x has one non-empty Element" : '';
if( navigator.is.Chrome ) { //or: if(is.Chrome)
console.log("I am neither Mac nor PC, for I am Chrome!");
}
//status test
is.XHRStatus = {status : 204} && is.XHRStatus
//returns:
//>>> true
is.XHRStatus = {status : 300} && is.XHRStatus
//returns:
//>>> false
var url = "http://lsauer.com";
var content = XHR(url);
function XHR(url){
var xhr = is.newXhrObj;//new XMLHttpRequest()
xhr.open('GET', url, false); //false...ynchronous mode, i.e. non- AJAX
try{
xhr.send(null);
if( is.XHRStatus = xhr && is.XHRStatus ) { //or: if(is.XHRStatusOK(xhr))...
var e = Error("Could not load:" + uri + "|status:" + xhr.status);
e.status = xhr.status;
e.responseText = xhr.responseText;
return is.Debug ? is.Exit = e : null;
}
}catch(e){
return is.Error(e, null); //or return is.Debug ? is.Errror(e) : null;
}
return xhr.responseText; // String
}