Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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