PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/doc/example-jsunit/jsunit/app/jsUnitVersionCheck.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 59 lines | 50 code | 9 blank | 0 comment | 10 complexity | 2ab5c3ad4753f93edfd31638c9044acc MD5 | raw file
 1var versionRequest;
 2
 3function isOutOfDate(newVersionNumber) {
 4    return JSUNIT_VERSION < newVersionNumber;
 5}
 6
 7function sendRequestForLatestVersion(url) {
 8    versionRequest = createXmlHttpRequest();
 9    if (versionRequest) {
10        versionRequest.onreadystatechange = requestStateChanged;
11        versionRequest.open("GET", url, true);
12        versionRequest.send(null);
13    }
14}
15
16function createXmlHttpRequest() {
17    if (window.XMLHttpRequest)
18        return new XMLHttpRequest();
19    else if (window.ActiveXObject)
20        return new ActiveXObject("Microsoft.XMLHTTP");
21}
22
23function requestStateChanged() {
24    if (versionRequest && versionRequest.readyState == 4) {
25        if (versionRequest.status == 200) {
26            var latestVersion = versionRequest.responseText;
27            if (isOutOfDate(latestVersion))
28                versionNotLatest(latestVersion);
29            else
30                versionLatest();
31        } else
32            versionCheckError();
33    }
34}
35
36function checkForLatestVersion(url) {
37    setLatestVersionDivHTML("Checking for newer version...");
38    try {
39        sendRequestForLatestVersion(url);
40    } catch (e) {
41        setLatestVersionDivHTML("An error occurred while checking for a newer version: " + e.message);
42    }
43}
44
45function versionNotLatest(latestVersion) {
46    setLatestVersionDivHTML('<font color="red">A newer version of JsUnit, version ' + latestVersion + ', is available.</font>');
47}
48
49function versionLatest() {
50    setLatestVersionDivHTML("You are running the latest version of JsUnit.");
51}
52
53function setLatestVersionDivHTML(string) {
54    document.getElementById("versionCheckDiv").innerHTML = string;
55}
56
57function versionCheckError() {
58    setLatestVersionDivHTML("An error occurred while checking for a newer version.");
59}