1
2
3
4 import sys
5 from __pyjamas__ import JS, doc, wnd
6 if sys.platform not in ['mozilla', 'ie6', 'opera', 'oldmoz', 'safari']:
7 from __pyjamas__ import get_main_frame
8
9 global historyToken
10 historyToken = ''
11
12 historyListeners = []
13
14
15 """
16 Simple History management class for back/forward button support.
17
18 This class allows your AJAX application to use a history. Each time you
19 call newItem(), a new item is added to the history and the history
20 listeners are notified. If the user clicks the browser's forward or back
21 buttons, the appropriate item (a string passed to newItem) is fetched
22 from the history and the history listeners are notified.
23
24 The address bar of the browser contains the current token, using
25 the "#" seperator (for implementation reasons, not because we love
26 the # mark).
27
28 You may want to check whether the hash already contains a history
29 token when the page loads and use that to show appropriate content;
30 this allows users of the site to store direct links in their
31 bookmarks or send them in emails.
32
33 To make this work properly in all browsers, you must add a specially
34 named iframe to your html page, like this:
35
36 <iframe id='__pygwt_historyFrame' style='width:0;height:0;border:0' />
37 """
38
39
42
43
46
47
50
51
55
56
58 print "History - new item", ht
59 onHistoryChanged(ht)
60 return
61
62 JS("""
63 if(historyToken == "" || historyToken == null){
64 historyToken = "#";
65 }
66 $wnd.location.hash = encodeURI(historyToken).replace('#','%23');
67 """)
68
69
70
77
78
79
82
83
85 for listener in historyListeners:
86 listener.onHistoryChanged(ht)
87
88
91
92
94 print "history: TODO"
95 global historyToken
96 historyToken = ''
97 onHistoryChanged(historyToken)
98 return
99 JS("""
100 $wnd.__historyToken = '';
101
102 // Get the initial token from the url's hash component.
103 var hash = $wnd.location.hash;
104 if (hash.length > 0)
105 $wnd.__historyToken = decodeURI(hash.substring(1)).replace('%23','#');
106
107 // Create the timer that checks the browser's url hash every 1/4 s.
108 $wnd.__checkHistory = function() {
109 var token = '', hash = $wnd.location.hash;
110 if (hash.length > 0)
111 token = decodeURI(hash.substring(1)).replace('%23','#');
112
113 if (token != $wnd.__historyToken) {
114 $wnd.__historyToken = token;
115 // TODO - move init back into History
116 // this.onHistoryChanged(token);
117 var h = new __History_History();
118 h.onHistoryChanged(token);
119 }
120
121 $wnd.setTimeout('__checkHistory()', 250);
122 };
123
124 // Kick off the timer.
125 $wnd.__checkHistory();
126
127 return true;
128 """)
129
130
131 init()
132