Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Sketchometry.activity/js/cache.js
blob: a01a04eb6749dabe9d8ae6858e7ef0a8ee2865f2 (plain)
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
/*
    Copyright 2011 / 2012

        Alfred Wassermann
        Michael Gerhaeuser,
        Carsten Miller,
        Matthias Ehmann,
        Heiko Vogel,

    This file is part of the JSXGraph GUI project.
    This code isn't licensed yet.
*/

(function () {
    if ($.browser.msie) {
        // Internet Explorer doesn't really support this stuff. At least not IE <= 9
        return;
    }

    var appCache = window.applicationCache;

    if (typeof appCache == 'undefined') {
        // in case app cache is not supported by the browser we don't need to tell the user.
        // besides: GUI.Lang.std is not initialized by now, all the alert box would tell us is "undefined".
        //GUI.alert(GUI.Lang.std.appcache_error);
    }

    appCache.on = appCache.addEventListener;

    var report = function (ev) {

        console.log('appCacheEvent: ' + ev.type + ' -- ' + new Date().toISOString());

        if (!('progress' === ev.type || 'downloading' === ev.type || 'checking' === ev.type
            || 'noupdate' === ev.type || 'cached' === ev.type)) {

            if ('updateready' == ev.type) {
                if (!GUI.release) {
                    GUI.alert('new version available, updating');
                }
                window.location.reload();
            }

            if ('error' === ev.type && !GUI.release) {
                if (navigator.onLine)
                    GUI.alert('appcache error!');
                else
                    console.log('appcache error!');
            }
        }
    };

    appCache.on('checking', report, false);
    appCache.on('error', report, false);
    appCache.on('noupdate', report, false);
    appCache.on('downloading', report, false);
    appCache.on('progress', report, false);
    appCache.on('updateready', report, false);
    appCache.on('cached', report, false);

}());