-
Notifications
You must be signed in to change notification settings - Fork 3
/
browserscope.js
84 lines (72 loc) · 1.88 KB
/
browserscope.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(function( $ ) {
var baseUrl = "http://www.browserscope.org/user";
var BrowserScope = window.BrowserScope = function( testKey, sandboxId ) {
this.testKey = testKey;
this.sandboxId = sandboxId;
};
BrowserScope.browsers = {
top: 0,
families: 1,
minor: 2,
all: 3
};
$.extend( BrowserScope.prototype, {
browsersDefault: BrowserScope.browsers.families,
_resultsUrl: function( format, browsers ) {
return baseUrl + "/tests/table/" + this.testKey +
"?o=" + format + "&v=" + (browsers || this.browsersDefault);
},
_beaconUrl: function( varName, callbackName ) {
var url = baseUrl + "/beacon/" + this.testKey +
"?test_results_var=" + varName;
if ( callbackName ) {
url += "&callback=" + callbackName;
}
if ( this.sandboxId ) {
url += "&sandboxId=" + this.sandboxId;
}
return url;
},
renderResults: function( browsers ) {
browsers = browsers || this.browsersDefault;
$.getScript( this._resultsUrl( "js", browsers ) );
},
getResults: function( browsers, fn ) {
if ( !fn ) {
fn = browsers;
browsers = undefined;
}
$.ajax({
url: this._resultsUrl( "json", browsers ),
dataType: "jsonp",
success: function( data ) {
var results = {};
$.each( data.results, function( browser, browserDetails ) {
results[ browser ] = {};
$.each( browserDetails.results, function( testName, testDetails ) {
results[ browser ][ testName ] = testDetails.result;
});
});
fn( results );
}
});
},
storeResults: function( results, fn ) {
var fnName,
name = "_bTestResults" + $.now();
window[ name ] = results;
if ( fn ) {
fnName = "_bCallback" + $.now();
window[ fnName ] = function() {
fn();
// IE throws an error when trying to delete
window[ fnName ] = undefined;
try {
delete window[ fnName ];
} catch( error ) {}
};
}
$.getScript( this._beaconUrl( name, fnName ) );
}
});
}( jQuery ) );