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

/library/platform/HistorySafari.py

http://pyjamas.googlecode.com/
Python | 62 lines | 62 code | 0 blank | 0 comment | 0 complexity | 7705162071241f085e1d24affadbc1e6 MD5 | raw file
 1def init():
 2    JS("""
 3    // Check for existence of the history frame.
 4    var historyFrame = $doc.getElementById('__pygwt_historyFrame');
 5    if (!historyFrame)
 6        return false;
 7
 8    // Get the initial token from the url's hash component.
 9    var hash = $wnd.location.hash;
10    if (hash.length > 0)
11        $wnd.__historyToken = decodeURIComponent(hash.substring(1));
12    else
13        $wnd.__historyToken = '';
14
15    // Initialize the history iframe.  If '__historyToken' already exists, then
16    // we're probably backing into the app, so _don't_ set the iframe's location.
17    var tokenElement = null;
18    if (historyFrame.contentWindow) {
19        var doc = historyFrame.contentWindow.document;
20        tokenElement = doc ? doc.getElementById('__historyToken') : null;
21    }
22
23    if (tokenElement)
24        $wnd.__historyToken = tokenElement.value;
25    else
26        historyFrame.src = 'history.html?' + encodeURIComponent($wnd.__historyToken);
27
28    // Expose the '__onHistoryChanged' function, which will be called by
29    // the history frame when it loads.
30    $wnd.__onHistoryChanged = function(token) {
31        // Change the URL and notify the application that its history frame
32        // is changing.
33        if (token != $wnd.__historyToken) {
34            $wnd.__historyToken = token;
35
36            // TODO(jgw): fix the bookmark update, if possible.  The following code
37            // screws up the browser by (a) making it pretend that it's loading the
38            // page indefinitely, and (b) causing all text to disappear (!)
39            //        var base = $wnd.location.href;
40            //        var hashIdx = base.indexOf('#');
41            //        if (hashIdx != -1)
42            //          base = base.substring(0, hashIdx);
43            //        $wnd.location.replace(base + '#' + token);
44
45            // TODO - move init back into History
46            // this.onHistoryChanged(token);
47            var h = new __History_History();
48            h.onHistoryChanged(token);
49        }
50    };
51
52    return true;
53    """)
54
55        
56class History:
57
58    def newItem(self, historyToken):
59        JS("""
60        var iframe = $doc.getElementById('__pygwt_historyFrame');
61        iframe.contentWindow.location.href = 'history.html?' + historyToken;
62        """)