PageRenderTime 85ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Apache-2.0
  1. def 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. // Get the initial token from the url's hash component.
  8. var hash = $wnd.location.hash;
  9. if (hash.length > 0)
  10. $wnd.__historyToken = decodeURIComponent(hash.substring(1));
  11. else
  12. $wnd.__historyToken = '';
  13. // Initialize the history iframe. If '__historyToken' already exists, then
  14. // we're probably backing into the app, so _don't_ set the iframe's location.
  15. var tokenElement = null;
  16. if (historyFrame.contentWindow) {
  17. var doc = historyFrame.contentWindow.document;
  18. tokenElement = doc ? doc.getElementById('__historyToken') : null;
  19. }
  20. if (tokenElement)
  21. $wnd.__historyToken = tokenElement.value;
  22. else
  23. historyFrame.src = 'history.html?' + encodeURIComponent($wnd.__historyToken);
  24. // Expose the '__onHistoryChanged' function, which will be called by
  25. // the history frame when it loads.
  26. $wnd.__onHistoryChanged = function(token) {
  27. // Change the URL and notify the application that its history frame
  28. // is changing.
  29. if (token != $wnd.__historyToken) {
  30. $wnd.__historyToken = token;
  31. // TODO(jgw): fix the bookmark update, if possible. The following code
  32. // screws up the browser by (a) making it pretend that it's loading the
  33. // page indefinitely, and (b) causing all text to disappear (!)
  34. // var base = $wnd.location.href;
  35. // var hashIdx = base.indexOf('#');
  36. // if (hashIdx != -1)
  37. // base = base.substring(0, hashIdx);
  38. // $wnd.location.replace(base + '#' + token);
  39. // TODO - move init back into History
  40. // this.onHistoryChanged(token);
  41. var h = new __History_History();
  42. h.onHistoryChanged(token);
  43. }
  44. };
  45. return true;
  46. """)
  47. class History:
  48. def newItem(self, historyToken):
  49. JS("""
  50. var iframe = $doc.getElementById('__pygwt_historyFrame');
  51. iframe.contentWindow.location.href = 'history.html?' + historyToken;
  52. """)