aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/io/proxy/xip_client.html
blob: c51a8396f92c324192b1beb3c32db346c72114b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!--
	/*
		Copyright (c) 2004-2008, The Dojo Foundation
		All Rights Reserved.
	
		Licensed under the Academic Free License version 2.1 or above OR the
		modified BSD license. For more information on Dojo licensing, see:
	
			http://dojotoolkit.org/community/licensing.shtml
	*/
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
	<!-- Security protection: uncomment the start and end script tags to enable. -->
	<!-- script type="text/javascript" -->
	// <!--
	
	function pollHash(){
		//Can't use location.hash because at least Firefox does a decodeURIComponent on it.
		var urlParts = window.location.href.split("#");
		if(urlParts.length == 2){
			var newHash = urlParts[1];
			if(newHash != xipCurrentHash){
				try{
					callMaster(xipStateId, newHash);
				}catch(e){
					//Make sure to not keep processing the error hash value.
					xipCurrentHash = newHash;
					throw e;
				}
				xipCurrentHash = newHash;
			}
		}
	}

	function unpackMessage(encodedMessage){
		var parts = encodedMessage.split(":");
		var command = parts[1];
		encodedMessage = parts[2] || "";

		var config = null;
		if(command == "init"){
			var configParts = encodedMessage.split("&");
			config = {};
			for(var i = 0; i < configParts.length; i++){
				var nameValue = configParts[i].split("=");
				config[decodeURIComponent(nameValue[0])] = decodeURIComponent(nameValue[1]);
			}
		}
		return {command: command, message: encodedMessage, config: config};
	}

	//************** Init **************************
	xipCurrentHash = "";
	
	//Decode the init params
	var fragId = window.location.href.split("#")[1];
	var config = unpackMessage(fragId).config;

	xipStateId = config.id;
	xipMasterFrame = parent.parent;

	//Set up an HTML5 messaging publisher if postMessage exists.
	//As of this writing, this is only useful to get Opera 9.25+ to work.
	if(typeof document.postMessage != "undefined"){
		callMaster = function(stateId, message){
			xipMasterFrame.document.postMessage(stateId + "#" + message);
		}
	}else{
		var parts = config.callback.split(".");
		xipCallbackObject = xipMasterFrame;
		for(var i = 0; i < parts.length - 1; i++){
			xipCallbackObject = xipCallbackObject[parts[i]];
		}
		xipCallback = parts[parts.length - 1];

		callMaster = function(stateId, message){
			xipCallbackObject[xipCallback](stateId + "#" + message);
		}
	}

	//Call the master frame to let it know it is OK to start sending.
	callMaster(xipStateId, "0:loaded");
	
	//Start counter to inspect hash value.
	setInterval(pollHash, 10);

	// -->
	<!-- </script> -->
</head>
<body>
	<h4>The Dojo Toolkit -- xip_client.html</h4>

	<p>This file is used for Dojo's XMLHttpRequest Iframe Proxy. This is the "client" file used
	internally by dojox.io.proxy.xip.</p>
</body>
</html>