Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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