Subversion Repositories Applications.papyrus

Rev

Rev 1422 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
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
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.undo.browser");
14
dojo.require("dojo.io.common");
15
try {
16
	if ((!djConfig["preventBackButtonFix"]) && (!dojo.hostenv.post_load_)) {
17
		document.write("<iframe style='border: 0px; width: 1px; height: 1px; position: absolute; bottom: 0px; right: 0px; visibility: visible;' name='djhistory' id='djhistory' src='" + (djConfig["dojoIframeHistoryUrl"] || dojo.hostenv.getBaseScriptUri() + "iframe_history.html") + "'></iframe>");
18
	}
19
}
20
catch (e) {
21
}
22
if (dojo.render.html.opera) {
23
	dojo.debug("Opera is not supported with dojo.undo.browser, so back/forward detection will not work.");
24
}
25
dojo.undo.browser = {initialHref:(!dj_undef("window")) ? window.location.href : "", initialHash:(!dj_undef("window")) ? window.location.hash : "", moveForward:false, historyStack:[], forwardStack:[], historyIframe:null, bookmarkAnchor:null, locationTimer:null, setInitialState:function (args) {
26
	this.initialState = this._createState(this.initialHref, args, this.initialHash);
27
}, addToHistory:function (args) {
28
	this.forwardStack = [];
29
	var hash = null;
30
	var url = null;
31
	if (!this.historyIframe) {
32
		if (djConfig["useXDomain"] && !djConfig["dojoIframeHistoryUrl"]) {
33
			dojo.debug("dojo.undo.browser: When using cross-domain Dojo builds," + " please save iframe_history.html to your domain and set djConfig.dojoIframeHistoryUrl" + " to the path on your domain to iframe_history.html");
34
		}
35
		this.historyIframe = window.frames["djhistory"];
36
	}
37
	if (!this.bookmarkAnchor) {
38
		this.bookmarkAnchor = document.createElement("a");
39
		dojo.body().appendChild(this.bookmarkAnchor);
40
		this.bookmarkAnchor.style.display = "none";
41
	}
42
	if (args["changeUrl"]) {
43
		hash = "#" + ((args["changeUrl"] !== true) ? args["changeUrl"] : (new Date()).getTime());
44
		if (this.historyStack.length == 0 && this.initialState.urlHash == hash) {
45
			this.initialState = this._createState(url, args, hash);
46
			return;
47
		} else {
48
			if (this.historyStack.length > 0 && this.historyStack[this.historyStack.length - 1].urlHash == hash) {
49
				this.historyStack[this.historyStack.length - 1] = this._createState(url, args, hash);
50
				return;
51
			}
52
		}
53
		this.changingUrl = true;
54
		setTimeout("window.location.href = '" + hash + "'; dojo.undo.browser.changingUrl = false;", 1);
55
		this.bookmarkAnchor.href = hash;
56
		if (dojo.render.html.ie) {
57
			url = this._loadIframeHistory();
58
			var oldCB = args["back"] || args["backButton"] || args["handle"];
59
			var tcb = function (handleName) {
60
				if (window.location.hash != "") {
61
					setTimeout("window.location.href = '" + hash + "';", 1);
62
				}
63
				oldCB.apply(this, [handleName]);
64
			};
65
			if (args["back"]) {
66
				args.back = tcb;
67
			} else {
68
				if (args["backButton"]) {
69
					args.backButton = tcb;
70
				} else {
71
					if (args["handle"]) {
72
						args.handle = tcb;
73
					}
74
				}
75
			}
76
			var oldFW = args["forward"] || args["forwardButton"] || args["handle"];
77
			var tfw = function (handleName) {
78
				if (window.location.hash != "") {
79
					window.location.href = hash;
80
				}
81
				if (oldFW) {
82
					oldFW.apply(this, [handleName]);
83
				}
84
			};
85
			if (args["forward"]) {
86
				args.forward = tfw;
87
			} else {
88
				if (args["forwardButton"]) {
89
					args.forwardButton = tfw;
90
				} else {
91
					if (args["handle"]) {
92
						args.handle = tfw;
93
					}
94
				}
95
			}
96
		} else {
97
			if (dojo.render.html.moz) {
98
				if (!this.locationTimer) {
99
					this.locationTimer = setInterval("dojo.undo.browser.checkLocation();", 200);
100
				}
101
			}
102
		}
103
	} else {
104
		url = this._loadIframeHistory();
105
	}
106
	this.historyStack.push(this._createState(url, args, hash));
107
}, checkLocation:function () {
108
	if (!this.changingUrl) {
109
		var hsl = this.historyStack.length;
110
		if ((window.location.hash == this.initialHash || window.location.href == this.initialHref) && (hsl == 1)) {
111
			this.handleBackButton();
112
			return;
113
		}
114
		if (this.forwardStack.length > 0) {
115
			if (this.forwardStack[this.forwardStack.length - 1].urlHash == window.location.hash) {
116
				this.handleForwardButton();
117
				return;
118
			}
119
		}
120
		if ((hsl >= 2) && (this.historyStack[hsl - 2])) {
121
			if (this.historyStack[hsl - 2].urlHash == window.location.hash) {
122
				this.handleBackButton();
123
				return;
124
			}
125
		}
126
	}
127
}, iframeLoaded:function (evt, ifrLoc) {
128
	if (!dojo.render.html.opera) {
129
		var query = this._getUrlQuery(ifrLoc.href);
130
		if (query == null) {
131
			if (this.historyStack.length == 1) {
132
				this.handleBackButton();
133
			}
134
			return;
135
		}
136
		if (this.moveForward) {
137
			this.moveForward = false;
138
			return;
139
		}
140
		if (this.historyStack.length >= 2 && query == this._getUrlQuery(this.historyStack[this.historyStack.length - 2].url)) {
141
			this.handleBackButton();
142
		} else {
143
			if (this.forwardStack.length > 0 && query == this._getUrlQuery(this.forwardStack[this.forwardStack.length - 1].url)) {
144
				this.handleForwardButton();
145
			}
146
		}
147
	}
148
}, handleBackButton:function () {
149
	var current = this.historyStack.pop();
150
	if (!current) {
151
		return;
152
	}
153
	var last = this.historyStack[this.historyStack.length - 1];
154
	if (!last && this.historyStack.length == 0) {
155
		last = this.initialState;
156
	}
157
	if (last) {
158
		if (last.kwArgs["back"]) {
159
			last.kwArgs["back"]();
160
		} else {
161
			if (last.kwArgs["backButton"]) {
162
				last.kwArgs["backButton"]();
163
			} else {
164
				if (last.kwArgs["handle"]) {
165
					last.kwArgs.handle("back");
166
				}
167
			}
168
		}
169
	}
170
	this.forwardStack.push(current);
171
}, handleForwardButton:function () {
172
	var last = this.forwardStack.pop();
173
	if (!last) {
174
		return;
175
	}
176
	if (last.kwArgs["forward"]) {
177
		last.kwArgs.forward();
178
	} else {
179
		if (last.kwArgs["forwardButton"]) {
180
			last.kwArgs.forwardButton();
181
		} else {
182
			if (last.kwArgs["handle"]) {
183
				last.kwArgs.handle("forward");
184
			}
185
		}
186
	}
187
	this.historyStack.push(last);
188
}, _createState:function (url, args, hash) {
189
	return {"url":url, "kwArgs":args, "urlHash":hash};
190
}, _getUrlQuery:function (url) {
191
	var segments = url.split("?");
192
	if (segments.length < 2) {
193
		return null;
194
	} else {
195
		return segments[1];
196
	}
197
}, _loadIframeHistory:function () {
198
	var url = (djConfig["dojoIframeHistoryUrl"] || dojo.hostenv.getBaseScriptUri() + "iframe_history.html") + "?" + (new Date()).getTime();
199
	this.moveForward = true;
200
	dojo.io.setIFrameSrc(this.historyIframe, url, false);
201
	return url;
202
}};
203