PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/library/platform/HistoryIE6.py

http://pyjamas.googlecode.com/
Python | 71 lines | 71 code | 0 blank | 0 comment | 0 complexity | cdae822abb6fa180650070de21ea3331 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?' + $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. Note that setting location.hash does _not_ add a history
  29. // frame on IE, so we don't have to do a 'location.replace()'.
  30. if (token != $wnd.__historyToken) {
  31. $wnd.__historyToken = token;
  32. $wnd.location.hash = encodeURIComponent(token);
  33. // TODO - move init back into History
  34. // this.onHistoryChanged(token);
  35. var h = new __History_History();
  36. h.onHistoryChanged(token);
  37. }
  38. };
  39. // This is the URL check timer. It detects when an unexpected change
  40. // occurs in the document's URL (e.g. when the user enters one manually
  41. // or selects a 'favorite', but only the #hash part changes). When this
  42. // occurs, we _must_ reload the page. This is because IE has a really
  43. // nasty bug that totally mangles its history stack and causes the location
  44. // bar in the UI to stop working under these circumstances.
  45. var urlChecker = function() {
  46. var hash = $wnd.location.hash;
  47. if (hash.length > 0) {
  48. var token = decodeURIComponent(hash.substring(1));
  49. if ($wnd.__historyToken && (token != $wnd.__historyToken))
  50. $wnd.location.reload();
  51. }
  52. $wnd.setTimeout(urlChecker, 250);
  53. };
  54. urlChecker();
  55. return true;
  56. """)
  57. class History:
  58. def newItem(self, historyToken):
  59. JS("""
  60. var iframe = $doc.getElementById('__pygwt_historyFrame');
  61. iframe.contentWindow.location.href = 'history.html?' + historyToken;
  62. """)