xip_client.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!--
  2. /*
  3. Copyright (c) 2004-2011, The Dojo Foundation
  4. All Rights Reserved.
  5. Licensed under the Academic Free License version 2.1 or above OR the
  6. modified BSD license. For more information on Dojo licensing, see:
  7. http://dojotoolkit.org/community/licensing.shtml
  8. */
  9. -->
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  11. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  12. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  13. <head>
  14. <title></title>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
  16. <!-- Security protection: uncomment the start and end script tags to enable. -->
  17. <!-- script type="text/javascript" -->
  18. // <!--
  19. function pollHash(){
  20. //Can't use location.hash because at least Firefox does a decodeURIComponent on it.
  21. var urlParts = window.location.href.split("#");
  22. if(urlParts.length == 2){
  23. var newHash = urlParts[1];
  24. if(newHash != xipCurrentHash){
  25. try{
  26. callMaster(xipStateId, newHash);
  27. }catch(e){
  28. //Make sure to not keep processing the error hash value.
  29. xipCurrentHash = newHash;
  30. throw e;
  31. }
  32. xipCurrentHash = newHash;
  33. }
  34. }
  35. }
  36. function unpackMessage(encodedMessage){
  37. var parts = encodedMessage.split(":");
  38. var command = parts[1];
  39. encodedMessage = parts[2] || "";
  40. var config = null;
  41. if(command == "init"){
  42. var configParts = encodedMessage.split("&");
  43. config = {};
  44. for(var i = 0; i < configParts.length; i++){
  45. var nameValue = configParts[i].split("=");
  46. config[decodeURIComponent(nameValue[0])] = decodeURIComponent(nameValue[1]);
  47. }
  48. }
  49. return {command: command, message: encodedMessage, config: config};
  50. }
  51. //************** Init **************************
  52. xipCurrentHash = "";
  53. //Decode the init params
  54. var fragId = window.location.href.split("#")[1];
  55. var config = unpackMessage(fragId).config;
  56. xipStateId = config.id;
  57. xipMasterFrame = parent.parent;
  58. //Set up an HTML5 messaging publisher if postMessage exists.
  59. //As of this writing, this is only useful to get Opera 9.25+ to work.
  60. if(typeof document.postMessage != "undefined"){
  61. callMaster = function(stateId, message){
  62. xipMasterFrame.document.postMessage(stateId + "#" + message);
  63. }
  64. }else{
  65. var parts = config.callback.split(".");
  66. xipCallbackObject = xipMasterFrame;
  67. for(var i = 0; i < parts.length - 1; i++){
  68. xipCallbackObject = xipCallbackObject[parts[i]];
  69. }
  70. xipCallback = parts[parts.length - 1];
  71. callMaster = function(stateId, message){
  72. xipCallbackObject[xipCallback](stateId + "#" + message);
  73. }
  74. }
  75. //Call the master frame to let it know it is OK to start sending.
  76. callMaster(xipStateId, "0:loaded");
  77. //Start counter to inspect hash value.
  78. setInterval(pollHash, 10);
  79. // -->
  80. <!-- </script> -->
  81. </head>
  82. <body>
  83. <h4>The Dojo Toolkit -- xip_client.html</h4>
  84. <p>This file is used for Dojo's XMLHttpRequest Iframe Proxy. This is the "client" file used
  85. internally by dojox.io.proxy.xip.</p>
  86. </body>
  87. </html>