605f4a20346b12c344a7a08145e407577f4b16a7.svn-base 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <html>
  2. <head>
  3. <script language="JavaScript" type="text/javascript">
  4. // Dojo configuration
  5. djConfig = {
  6. //debugAtAllCosts: true, //Don't normally need this in applications.
  7. isDebug: true,
  8. dojoIframeHistoryUrl: "../../resources/iframe_history.html", //for xdomain
  9. preventBackButtonFix: false
  10. };
  11. </script>
  12. <script language="JavaScript" type="text/javascript" src="../../dojo.js"></script>
  13. <script language="JavaScript" type="text/javascript" src="browser/ApplicationState.js"></script>
  14. <script language="JavaScript" type="text/javascript">
  15. dojo.require("dojo.lang.common");
  16. dojo.require("dojo.undo.browser");
  17. dojo.require("dojo.io.*");
  18. //dojo.hostenv.writeIncludes(); //Don't normally need this in applications.
  19. //****************************************
  20. function goIoBind(id){
  21. doApplicationStateBind("browser/" + id + ".xml", "output", "dataOutput", id);
  22. }
  23. //****************************************
  24. /*
  25. This method illustrates using dojo.io.bind() that also saves an application
  26. state via dojo.undo.browser (dojo.io.bind() will automatically use dojo.undo.browser
  27. if the dojo.io.bind() request object contains a back for forward function).
  28. */
  29. function doApplicationStateBind(url, outputDivId, backForwardOutputDivId, bookmarkValue){
  30. dojo.io.bind({
  31. //Standard dojo.io.bind parameter
  32. url: url,
  33. //Standard dojo.io.bind parameter.
  34. //For this test, all of the bind requests are for text/xml documents.
  35. mimetype: "text/xml",
  36. //Standard dojo.io.bind parameter: if this is a value that evaluates
  37. //to true, then the page URL will change (by adding a fragment identifier
  38. //to the URL)
  39. changeUrl: bookmarkValue,
  40. //Data for use once we have data for an ApplicationState object
  41. outputDivId: outputDivId,
  42. backForwardOutputDivId: backForwardOutputDivId,
  43. //A holder for the application state object.
  44. //It will be created once we have a response from the bind request.
  45. appState: null,
  46. //Standard dojo.io.bind parameter. The ioRequest object is returned
  47. //to the load function as the fourth parameter. The ioRequest object
  48. //is the object we are creating and passing to this dojo.io.bind() call.
  49. load: function(type, evaldObj, xhrObject, ioRequest){
  50. var stateData = "XHR: " + evaldObj.getElementsByTagName("data")[0].childNodes[0].nodeValue;
  51. ioRequest.appState = new ApplicationState(stateData, ioRequest.outputDivId, ioRequest.backForwardOutputDivId);
  52. ioRequest.appState.showStateData();
  53. },
  54. back: function(){
  55. this.appState.back();
  56. },
  57. forward: function(){
  58. this.appState.forward();
  59. }
  60. });
  61. }
  62. //****************************************
  63. dojo.addOnLoad(function(){
  64. //See if there is a bookmark hash on the page URL.
  65. var bookmarkId = location.hash;
  66. if(bookmarkId){
  67. bookmarkId = bookmarkId.substring(1, bookmarkId.length);
  68. }
  69. //If we have a bookmark, load that as the initial state.
  70. if(bookmarkId && bookmarkId.indexOf("xhr") == 0){
  71. //Load the XHR data for the bookmarked URL
  72. dojo.io.bind({
  73. url: "browser/" + bookmarkId + ".xml",
  74. mimetype: "text/xml",
  75. dataId: bookmarkId,
  76. load: function(type, evaldObj, http, kwArgs){
  77. var stateData = "(Initial State) XHR: " + evaldObj.getElementsByTagName("data")[0].childNodes[0].nodeValue;
  78. var appState = new ApplicationState(stateData, "output", "dataOutput");
  79. appState.showStateData();
  80. //Since this is the initial state, don't add it to the dojo.undo.browser
  81. //history stack (notice that this dojo.io.bind() request does not define
  82. //any back or forward functions). Instead, register the result of this bind
  83. //as the initial state for the page.
  84. dojo.undo.browser.setInitialState(appState);
  85. }
  86. });
  87. }else{
  88. var appState = new ApplicationState("This is the initial state (page first loaded, no dojo.io.bind() calls yet)", "output", "dataOutput");
  89. appState.showStateData();
  90. dojo.undo.browser.setInitialState(appState);
  91. }
  92. });
  93. </script>
  94. </head>
  95. <body>
  96. <div style="padding-bottom: 20px; width: 100%; border-bottom: 1px solid gray">
  97. <h3>dojo.undo.browser test (dojo.io.bind() with bookmarking)</h3>
  98. See the Dojo Book entry for
  99. <a href="http://manual.dojotoolkit.org/WikiHome/DojoDotBook/DocFn1">Back Button and Bookmarking</a>.
  100. <p>This page tests the dojo.undo.browser back/forward integration with dojo.io.bind(),
  101. and dojo.undo.browser's bookmarking facility. For a back/forward test without bookmarking,
  102. see <a href="test_browser.html">test_browser.html</a>.</p>
  103. <p>The buttons that start with "XHR" use
  104. dojo.io.bind to do some XMLHTTPRequest calls for some test data, and they
  105. also define back/forward handlers, so dojo.io should use dojo.undo.browser
  106. add to history tracking.</p>
  107. <p>To test the bookmarking facility:</p>
  108. <ul>
  109. <li>Click on one of the buttons below.</li>
  110. <li>Save the resulting URL as a bookmark.</li>
  111. <li>Close the browser window, or navigate to a different page.</li>
  112. <li>Click on the bookmark to jump to that state in the page</li>
  113. </ul>
  114. <p>Other notes:</p>
  115. <ul>
  116. <li>Don't test this page using local disk for MSIE. MSIE will not
  117. create a history list for iframe_history.html if served from a file:
  118. URL. The XML served back from the XHR tests will also not be properly
  119. created if served from local disk. Serve the test pages from a web
  120. server to test in that browser.</li>
  121. <li>Safari 2.0.3+ (and probably 1.3.2+): Only the back button works OK
  122. (not the forward button), and only if changeUrl is NOT used (so it <b>will not</b>
  123. work for this test page, since it is using bookmarking -- changeUrl).
  124. When changeUrl is used, Safari jumps all the way
  125. back to whatever page was shown before the page that uses
  126. dojo.undo.browser support.</li>
  127. <li>Opera 8.5.3: Does not work.</li>
  128. <li>Konqueror: Unknown. The latest may have Safari's behavior.</li>
  129. </ul>
  130. </div>
  131. <div style="float:left; padding: 20px">
  132. <button onclick="goIoBind('xhr1')">XHR 1</button><br />
  133. <button onclick="goIoBind('xhr2')">XHR 2</button><br />
  134. <button onclick="goIoBind('xhr3')">XHR 3</button><br />
  135. <button onclick="goIoBind('xhr4')">XHR 4</button><br />
  136. </div>
  137. <div style="float: left; padding: 20px">
  138. <b>Data Output:</b><br />
  139. <div id="output"></div>
  140. <hr />
  141. <i>Back/Forward Info:</i><br />
  142. <div id="dataOutput"></div>
  143. </div>
  144. </body>
  145. </html>