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