1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <title>API: history history.js (YUI Library)
</title>
5 <link rel=
"stylesheet" type=
"text/css" href=
"assets/api.css">
9 <div id=
"doc3" class=
"yui-t2">
12 <h1>Yahoo! UI Library
</h1>
13 <h3>Browser History Manager
<span class=
"subtitle">2.2.0</span></h3>
15 <a href=
"./index.html">Yahoo! UI Library
</a>
16 > <a href=
"./module_history.html">history
</a>
18 > history.js (source view)
27 <div class=
"highlight" ><pre><span class=
"c">/**
</span>
28 <span class=
"c"> *
</span>
29 <span class=
"c"> * The Browser History Manager provides the ability to use the
</span>
30 <span class=
"c"> * back/forward navigation buttons in a DHTML application. It also allows
</span>
31 <span class=
"c"> * a DHTML application to be bookmarked in a specific state.
</span>
32 <span class=
"c"> *
</span>
33 <span class=
"c"> * @module history
</span>
34 <span class=
"c"> * @requires yahoo,event
</span>
35 <span class=
"c"> * @namespace YAHOO.util
</span>
36 <span class=
"c"> * @title Browser History Manager
</span>
37 <span class=
"c"> * @experimental
</span>
38 <span class=
"c"> */
</span>
40 <span class=
"c">/**
</span>
41 <span class=
"c"> * The History class provides the ability to use the back/forward navigation
</span>
42 <span class=
"c"> * buttons in a DHTML application. It also allows a DHTML application to
</span>
43 <span class=
"c"> * be bookmarked in a specific state.
</span>
44 <span class=
"c"> *
</span>
45 <span class=
"c"> * @class History
</span>
46 <span class=
"c"> * @constructor
</span>
47 <span class=
"c"> */
</span>
48 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">History
</span> <span class=
"o">=
</span> <span class=
"o">(
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
50 <span class=
"c">/**
</span>
51 <span class=
"c"> * String identifying which browser we are in.
</span>
52 <span class=
"c"> * Different code is run depending on which browser you are using.
</span>
53 <span class=
"c"> *
</span>
54 <span class=
"c"> * @property _browser
</span>
55 <span class=
"c"> * @type string
</span>
56 <span class=
"c"> * @default
"unknown
"</span>
57 <span class=
"c"> * @private
</span>
58 <span class=
"c"> */
</span>
59 <span class=
"k">var
</span> <span class=
"nx">_browser
</span> <span class=
"o">=
</span> <span class=
"s2">"unknown
"</span><span class=
"o">;
</span>
61 <span class=
"c">/**
</span>
62 <span class=
"c"> * Our hidden IFrame used to store the browsing history.
</span>
63 <span class=
"c"> *
</span>
64 <span class=
"c"> * @property _iframe
</span>
65 <span class=
"c"> * @type HTMLIFrameElement
</span>
66 <span class=
"c"> * @default null
</span>
67 <span class=
"c"> * @private
</span>
68 <span class=
"c"> */
</span>
69 <span class=
"k">var
</span> <span class=
"nx">_iframe
</span> <span class=
"o">=
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
71 <span class=
"c">/**
</span>
72 <span class=
"c"> * INPUT field (with type=
"hidden
" or type=
"text
") or TEXTAREA.
</span>
73 <span class=
"c"> * This field keeps the value of the initial state, current state
</span>
74 <span class=
"c"> * the list of all states across pages within a single browser session.
</span>
75 <span class=
"c"> *
</span>
76 <span class=
"c"> * @property _storageField
</span>
77 <span class=
"c"> * @type HTMLInputElement|HTMLTextAreaElement
</span>
78 <span class=
"c"> * @default null
</span>
79 <span class=
"c"> * @private
</span>
80 <span class=
"c"> */
</span>
81 <span class=
"k">var
</span> <span class=
"nx">_storageField
</span> <span class=
"o">=
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
83 <span class=
"c">/**
</span>
84 <span class=
"c"> * Flag used to tell whether YAHOO.util.History.initialize has been called.
</span>
85 <span class=
"c"> *
</span>
86 <span class=
"c"> * @property _initialized
</span>
87 <span class=
"c"> * @type boolean
</span>
88 <span class=
"c"> * @default false
</span>
89 <span class=
"c"> * @private
</span>
90 <span class=
"c"> */
</span>
91 <span class=
"k">var
</span> <span class=
"nx">_initialized
</span> <span class=
"o">=
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
93 <span class=
"c">/**
</span>
94 <span class=
"c"> * Flag used to tell whether the storage field is ready to be used.
</span>
95 <span class=
"c"> *
</span>
96 <span class=
"c"> * @property _storageFieldReady
</span>
97 <span class=
"c"> * @type boolean
</span>
98 <span class=
"c"> * @default false
</span>
99 <span class=
"c"> * @private
</span>
100 <span class=
"c"> */
</span>
101 <span class=
"k">var
</span> <span class=
"nx">_storageFieldReady
</span> <span class=
"o">=
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
103 <span class=
"c">/**
</span>
104 <span class=
"c"> * Flag used to tell whether the Browser History Manager is ready.
</span>
105 <span class=
"c"> *
</span>
106 <span class=
"c"> * @property _bhmReady
</span>
107 <span class=
"c"> * @type boolean
</span>
108 <span class=
"c"> * @default false
</span>
109 <span class=
"c"> * @private
</span>
110 <span class=
"c"> */
</span>
111 <span class=
"k">var
</span> <span class=
"nx">_bhmReady
</span> <span class=
"o">=
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
113 <span class=
"c">/**
</span>
114 <span class=
"c"> * List of registered modules.
</span>
115 <span class=
"c"> *
</span>
116 <span class=
"c"> * @property _modules
</span>
117 <span class=
"c"> * @type array
</span>
118 <span class=
"c"> * @default []
</span>
119 <span class=
"c"> * @private
</span>
120 <span class=
"c"> */
</span>
121 <span class=
"k">var
</span> <span class=
"nx">_modules
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
123 <span class=
"c">/**
</span>
124 <span class=
"c"> * List of fully qualified states. This is used only by Safari.
</span>
125 <span class=
"c"> *
</span>
126 <span class=
"c"> * @property _fqstates
</span>
127 <span class=
"c"> * @type array
</span>
128 <span class=
"c"> * @default []
</span>
129 <span class=
"c"> * @private
</span>
130 <span class=
"c"> */
</span>
131 <span class=
"k">var
</span> <span class=
"nx">_fqstates
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
133 <span class=
"c">/**
</span>
134 <span class=
"c"> * Trims a string.
</span>
135 <span class=
"c"> *
</span>
136 <span class=
"c"> * @method _trim
</span>
137 <span class=
"c"> * @param {string} str The string to be trimmed.
</span>
138 <span class=
"c"> * @return {string} The trimmed string
</span>
139 <span class=
"c"> * @private
</span>
140 <span class=
"c"> */
</span>
141 <span class=
"k">function
</span> <span class=
"nx">_trim
</span><span class=
"o">(
</span> <span class=
"nx">str
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
142 <span class=
"k">return
</span> <span class=
"nx">str
</span><span class=
"o">.
</span><span class=
"nx">replace
</span><span class=
"o">(
</span> <span class=
"sr">/^\s*(\S*(\s+\S+)*)\s*$/
</span><span class=
"o">,
</span> <span class=
"s2">"$
1"</span> <span class=
"o">);
</span>
143 <span class=
"o">}
</span>
145 <span class=
"c">/**
</span>
146 <span class=
"c"> * location.hash is a bit buggy on Opera. I have seen instances where
</span>
147 <span class=
"c"> * navigating the history using the back/forward buttons, and hence
</span>
148 <span class=
"c"> * changing the URL, would not change location.hash. That
's ok, the
</span>
149 <span class=
"c"> * implementation of an equivalent is trivial.
</span>
150 <span class=
"c"> *
</span>
151 <span class=
"c"> * @method _getHash
</span>
152 <span class=
"c"> * @return {string} The hash portion of the document
's location
</span>
153 <span class=
"c"> * @private
</span>
154 <span class=
"c"> */
</span>
155 <span class=
"k">function
</span> <span class=
"nx">_getHash
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
156 <span class=
"k">var
</span> <span class=
"nx">href
</span> <span class=
"o">=
</span> <span class=
"nx">top
</span><span class=
"o">.
</span><span class=
"nx">location
</span><span class=
"o">.
</span><span class=
"nx">href
</span><span class=
"o">;
</span>
157 <span class=
"k">var
</span> <span class=
"nx">idx
</span> <span class=
"o">=
</span> <span class=
"nx">href
</span><span class=
"o">.
</span><span class=
"nx">indexOf
</span><span class=
"o">(
</span> <span class=
"s2">"#
"</span> <span class=
"o">);
</span>
158 <span class=
"k">return
</span> <span class=
"nx">idx
</span> <span class=
"o">>=
</span> <span class=
"m">0</span> <span class=
"o">?
</span> <span class=
"nx">href
</span><span class=
"o">.
</span><span class=
"nx">substr
</span><span class=
"o">(
</span> <span class=
"nx">idx
</span><span class=
"o">+
</span><span class=
"m">1</span> <span class=
"o">)
</span> <span class=
"o">:
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
159 <span class=
"o">}
</span>
161 <span class=
"c">/**
</span>
162 <span class=
"c"> * Stores all the registered modules
' initial state and current state.
</span>
163 <span class=
"c"> * On Safari, we also store all the fully qualified states visited by
</span>
164 <span class=
"c"> * the application within a single browser session. The storage takes
</span>
165 <span class=
"c"> * place in the form field specified during initialization.
</span>
166 <span class=
"c"> *
</span>
167 <span class=
"c"> * @method _storeStates
</span>
168 <span class=
"c"> * @private
</span>
169 <span class=
"c"> */
</span>
170 <span class=
"k">function
</span> <span class=
"nx">_storeStates
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
171 <span class=
"k">var
</span> <span class=
"nx">initialStates
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
172 <span class=
"k">var
</span> <span class=
"nx">currentStates
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
173 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"k">var
</span> <span class=
"nx">moduleName
</span> <span class=
"k">in
</span> <span class=
"nx">_modules
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
174 <span class=
"k">var
</span> <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
175 <span class=
"nx">initialStates
</span><span class=
"o">.
</span><span class=
"nx">push
</span><span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"o">+
</span> <span class=
"s2">"=
"</span> <span class=
"o">+
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">initialState
</span> <span class=
"o">);
</span>
176 <span class=
"nx">currentStates
</span><span class=
"o">.
</span><span class=
"nx">push
</span><span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"o">+
</span> <span class=
"s2">"=
"</span> <span class=
"o">+
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">);
</span>
177 <span class=
"o">}
</span>
178 <span class=
"nx">_storageField
</span><span class=
"o">.
</span><span class=
"nx">value
</span> <span class=
"o">=
</span> <span class=
"nx">initialStates
</span><span class=
"o">.
</span><span class=
"nx">join
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">)
</span> <span class=
"o">+
</span> <span class=
"s2">"|
"</span> <span class=
"o">+
</span> <span class=
"nx">currentStates
</span><span class=
"o">.
</span><span class=
"nx">join
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
179 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_browser
</span> <span class=
"o">==
</span> <span class=
"s2">"safari
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
180 <span class=
"nx">_storageField
</span><span class=
"o">.
</span><span class=
"nx">value
</span> <span class=
"o">+=
</span> <span class=
"s2">"|
"</span> <span class=
"o">+
</span> <span class=
"nx">_fqstates
</span><span class=
"o">.
</span><span class=
"nx">join
</span><span class=
"o">(
</span> <span class=
"s2">",
"</span> <span class=
"o">);
</span>
181 <span class=
"o">}
</span>
182 <span class=
"o">}
</span>
184 <span class=
"c">/**
</span>
185 <span class=
"c"> * Periodically checks whether our internal IFrame is ready to be used.
</span>
186 <span class=
"c"> *
</span>
187 <span class=
"c"> * @method _checkIframeLoaded
</span>
188 <span class=
"c"> * @private
</span>
189 <span class=
"c"> */
</span>
190 <span class=
"k">function
</span> <span class=
"nx">_checkIframeLoaded
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
191 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">_iframe
</span><span class=
"o">.
</span><span class=
"nx">contentWindow
</span> <span class=
"o">||
</span> <span class=
"o">!
</span><span class=
"nx">_iframe
</span><span class=
"o">.
</span><span class=
"nx">contentWindow
</span><span class=
"o">.
</span><span class=
"nb">document
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
192 <span class=
"c">// Check again in
10 msec...
</span>
193 <span class=
"c"></span> <span class=
"nx">setTimeout
</span><span class=
"o">(
</span> <span class=
"nx">_checkIframeLoaded
</span><span class=
"o">,
</span> <span class=
"m">10</span> <span class=
"o">);
</span>
194 <span class=
"k">return
</span><span class=
"o">;
</span>
195 <span class=
"o">}
</span>
197 <span class=
"c">// Start the thread that will have the responsibility to
</span>
198 <span class=
"c"></span> <span class=
"c">// periodically check whether a navigate operation has been
</span>
199 <span class=
"c"></span> <span class=
"c">// requested on the main window. This will happen when
</span>
200 <span class=
"c"></span> <span class=
"c">// YAHOO.util.History.navigate has been called or after
</span>
201 <span class=
"c"></span> <span class=
"c">// the user has hit the back/forward button.
</span>
202 <span class=
"c"></span>
203 <span class=
"k">var
</span> <span class=
"nx">doc
</span> <span class=
"o">=
</span> <span class=
"nx">_iframe
</span><span class=
"o">.
</span><span class=
"nx">contentWindow
</span><span class=
"o">.
</span><span class=
"nb">document
</span><span class=
"o">;
</span>
204 <span class=
"k">var
</span> <span class=
"nx">elem
</span> <span class=
"o">=
</span> <span class=
"nx">doc
</span><span class=
"o">.
</span><span class=
"nx">getElementById
</span><span class=
"o">(
</span> <span class=
"s2">"state
"</span> <span class=
"o">);
</span>
205 <span class=
"c">// We must use innerText, and not innerHTML because our string contains
</span>
206 <span class=
"c"></span> <span class=
"c">// the
"&" character (which would end up being escaped as
"&amp;
") and
</span>
207 <span class=
"c"></span> <span class=
"c">// the string comparison would fail...
</span>
208 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">fqstate
</span> <span class=
"o">=
</span> <span class=
"nx">elem
</span> <span class=
"o">?
</span> <span class=
"nx">elem
</span><span class=
"o">.
</span><span class=
"nx">innerText
</span> <span class=
"o">:
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
210 <span class=
"nx">setInterval
</span><span class=
"o">(
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
211 <span class=
"nx">doc
</span> <span class=
"o">=
</span> <span class=
"nx">_iframe
</span><span class=
"o">.
</span><span class=
"nx">contentWindow
</span><span class=
"o">.
</span><span class=
"nb">document
</span><span class=
"o">;
</span>
212 <span class=
"nx">elem
</span> <span class=
"o">=
</span> <span class=
"nx">doc
</span><span class=
"o">.
</span><span class=
"nx">getElementById
</span><span class=
"o">(
</span> <span class=
"s2">"state
"</span> <span class=
"o">);
</span>
213 <span class=
"c">// See my comment above about using innerText instead of innerHTML...
</span>
214 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">newfqstate
</span> <span class=
"o">=
</span> <span class=
"nx">elem
</span> <span class=
"o">?
</span> <span class=
"nx">elem
</span><span class=
"o">.
</span><span class=
"nx">innerText
</span> <span class=
"o">:
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
215 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">newfqstate
</span> <span class=
"o">!=
</span> <span class=
"nx">fqstate
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
216 <span class=
"nx">fqstate
</span> <span class=
"o">=
</span> <span class=
"nx">newfqstate
</span><span class=
"o">;
</span>
217 <span class=
"nx">_handleFQStateChange
</span><span class=
"o">(
</span> <span class=
"nx">fqstate
</span> <span class=
"o">);
</span>
219 <span class=
"k">var
</span> <span class=
"nx">hash
</span><span class=
"o">;
</span>
220 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">fqstate
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
221 <span class=
"k">var
</span> <span class=
"nx">states
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
222 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"k">var
</span> <span class=
"nx">moduleName
</span> <span class=
"k">in
</span> <span class=
"nx">_modules
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
223 <span class=
"k">var
</span> <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
224 <span class=
"nx">states
</span><span class=
"o">.
</span><span class=
"nx">push
</span><span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"o">+
</span> <span class=
"s2">"=
"</span> <span class=
"o">+
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">initialState
</span> <span class=
"o">);
</span>
225 <span class=
"o">}
</span>
226 <span class=
"nx">hash
</span> <span class=
"o">=
</span> <span class=
"nx">states
</span><span class=
"o">.
</span><span class=
"nx">join
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
227 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"o">{
</span>
228 <span class=
"nx">hash
</span> <span class=
"o">=
</span> <span class=
"nx">fqstate
</span><span class=
"o">;
</span>
229 <span class=
"o">}
</span>
231 <span class=
"c">// Allow the state to be bookmarked without messing up the browser history...
</span>
232 <span class=
"c"></span> <span class=
"nx">top
</span><span class=
"o">.
</span><span class=
"nx">location
</span><span class=
"o">.
</span><span class=
"nx">replace
</span><span class=
"o">(
</span> <span class=
"s2">"#
"</span> <span class=
"o">+
</span> <span class=
"nx">hash
</span> <span class=
"o">);
</span>
234 <span class=
"nx">_storeStates
</span><span class=
"o">();
</span>
235 <span class=
"o">}
</span>
236 <span class=
"o">},
</span> <span class=
"m">50</span> <span class=
"o">);
</span>
238 <span class=
"nx">_bhmReady
</span> <span class=
"o">=
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
240 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">History
</span><span class=
"o">.
</span><span class=
"nx">onLoadEvent
</span><span class=
"o">.
</span><span class=
"nx">fire
</span><span class=
"o">();
</span>
241 <span class=
"o">}
</span>
243 <span class=
"c">/**
</span>
244 <span class=
"c"> * Sets the new currentState attribute of all modules depending on the new
</span>
245 <span class=
"c"> * fully qualified state. Also notifies the modules which current state has
</span>
246 <span class=
"c"> * changed.
</span>
247 <span class=
"c"> *
</span>
248 <span class=
"c"> * @method _handleFQStateChange
</span>
249 <span class=
"c"> * @param {string} fqstate Fully qualified state
</span>
250 <span class=
"c"> * @private
</span>
251 <span class=
"c"> */
</span>
252 <span class=
"k">function
</span> <span class=
"nx">_handleFQStateChange
</span><span class=
"o">(
</span> <span class=
"nx">fqstate
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
253 <span class=
"k">var
</span> <span class=
"nx">moduleName
</span><span class=
"o">,
</span> <span class=
"nx">moduleObj
</span><span class=
"o">,
</span> <span class=
"nx">currentState
</span><span class=
"o">;
</span>
255 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">fqstate
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
256 <span class=
"c">// Notifies all modules
</span>
257 <span class=
"c"></span> <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"k">in
</span> <span class=
"nx">_modules
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
258 <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
259 <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">=
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">initialState
</span><span class=
"o">;
</span>
260 <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">onStateChange
</span><span class=
"o">(
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">);
</span>
261 <span class=
"o">}
</span>
262 <span class=
"k">return
</span><span class=
"o">;
</span>
263 <span class=
"o">}
</span>
265 <span class=
"k">var
</span> <span class=
"nx">modules
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
266 <span class=
"k">var
</span> <span class=
"nx">states
</span> <span class=
"o">=
</span> <span class=
"nx">fqstate
</span><span class=
"o">.
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
267 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"k">var
</span> <span class=
"nx">idx
</span><span class=
"o">=
</span><span class=
"m">0</span><span class=
"o">,
</span> <span class=
"nx">len
</span><span class=
"o">=
</span><span class=
"nx">states
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o"><</span><span class=
"nx">len
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o">++
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
268 <span class=
"k">var
</span> <span class=
"nx">tokens
</span> <span class=
"o">=
</span> <span class=
"nx">states
</span><span class=
"o">[
</span><span class=
"nx">idx
</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"=
"</span> <span class=
"o">);
</span>
269 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">tokens
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">==
</span> <span class=
"m">2</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
270 <span class=
"nx">moduleName
</span> <span class=
"o">=
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">];
</span>
271 <span class=
"nx">currentState
</span> <span class=
"o">=
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">];
</span>
272 <span class=
"nx">modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">]
</span> <span class=
"o">=
</span> <span class=
"nx">currentState
</span><span class=
"o">;
</span>
273 <span class=
"o">}
</span>
274 <span class=
"o">}
</span>
276 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"k">in
</span> <span class=
"nx">_modules
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
277 <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
278 <span class=
"nx">currentState
</span> <span class=
"o">=
</span> <span class=
"nx">modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
279 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">currentState
</span> <span class=
"o">||
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">!=
</span> <span class=
"nx">currentState
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
280 <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">=
</span> <span class=
"nx">currentState
</span> <span class=
"o">||
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">initialState
</span><span class=
"o">;
</span>
281 <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">onStateChange
</span><span class=
"o">(
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">);
</span>
282 <span class=
"o">}
</span>
283 <span class=
"o">}
</span>
284 <span class=
"o">}
</span>
286 <span class=
"c">/**
</span>
287 <span class=
"c"> * Finish up the initialization of the Browser History Manager.
</span>
288 <span class=
"c"> *
</span>
289 <span class=
"c"> * @method _initialize
</span>
290 <span class=
"c"> * @private
</span>
291 <span class=
"c"> */
</span>
292 <span class=
"k">function
</span> <span class=
"nx">_initialize
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
294 <span class=
"nx">_storageField
</span> <span class=
"o">=
</span> <span class=
"nb">document
</span><span class=
"o">.
</span><span class=
"nx">getElementById
</span><span class=
"o">(
</span> <span class=
"s2">"yui_hist_field
"</span> <span class=
"o">);
</span>
296 <span class=
"c">// Decode the content of our storage field...
</span>
297 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">parts
</span> <span class=
"o">=
</span> <span class=
"nx">_storageField
</span><span class=
"o">.
</span><span class=
"nx">value
</span><span class=
"o">.
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"|
"</span> <span class=
"o">);
</span>
299 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">parts
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">></span> <span class=
"m">1</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
301 <span class=
"k">var
</span> <span class=
"nx">idx
</span><span class=
"o">,
</span> <span class=
"nx">len
</span><span class=
"o">,
</span> <span class=
"nx">tokens
</span><span class=
"o">,
</span> <span class=
"nx">moduleName
</span><span class=
"o">,
</span> <span class=
"nx">moduleObj
</span><span class=
"o">;
</span>
303 <span class=
"k">var
</span> <span class=
"nx">initialStates
</span> <span class=
"o">=
</span> <span class=
"nx">parts
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
304 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"nx">idx
</span><span class=
"o">=
</span><span class=
"m">0</span><span class=
"o">,
</span> <span class=
"nx">len
</span><span class=
"o">=
</span><span class=
"nx">initialStates
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o"><</span><span class=
"nx">len
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o">++
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
305 <span class=
"nx">tokens
</span> <span class=
"o">=
</span> <span class=
"nx">initialStates
</span><span class=
"o">[
</span><span class=
"nx">idx
</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"=
"</span> <span class=
"o">);
</span>
306 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">tokens
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">==
</span> <span class=
"m">2</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
307 <span class=
"nx">moduleName
</span> <span class=
"o">=
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">];
</span>
308 <span class=
"k">var
</span> <span class=
"nx">initialState
</span> <span class=
"o">=
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">];
</span>
309 <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
310 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">moduleObj
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
311 <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">initialState
</span> <span class=
"o">=
</span> <span class=
"nx">initialState
</span><span class=
"o">;
</span>
312 <span class=
"o">}
</span>
313 <span class=
"o">}
</span>
314 <span class=
"o">}
</span>
316 <span class=
"k">var
</span> <span class=
"nx">currentStates
</span> <span class=
"o">=
</span> <span class=
"nx">parts
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
317 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"nx">idx
</span><span class=
"o">=
</span><span class=
"m">0</span><span class=
"o">,
</span> <span class=
"nx">len
</span><span class=
"o">=
</span><span class=
"nx">currentStates
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o"><</span><span class=
"nx">len
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o">++
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
318 <span class=
"nx">tokens
</span> <span class=
"o">=
</span> <span class=
"nx">currentStates
</span><span class=
"o">[
</span><span class=
"nx">idx
</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"=
"</span> <span class=
"o">);
</span>
319 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">tokens
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">>=
</span> <span class=
"m">2</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
320 <span class=
"nx">moduleName
</span> <span class=
"o">=
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">];
</span>
321 <span class=
"k">var
</span> <span class=
"nx">currentState
</span> <span class=
"o">=
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">];
</span>
322 <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
323 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">moduleObj
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
324 <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">=
</span> <span class=
"nx">currentState
</span><span class=
"o">;
</span>
325 <span class=
"o">}
</span>
326 <span class=
"o">}
</span>
327 <span class=
"o">}
</span>
328 <span class=
"o">}
</span>
330 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">parts
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">></span> <span class=
"m">2</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
331 <span class=
"nx">_fqstates
</span> <span class=
"o">=
</span> <span class=
"nx">parts
</span><span class=
"o">[
</span><span class=
"m">2</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">",
"</span> <span class=
"o">);
</span>
332 <span class=
"o">}
</span>
334 <span class=
"nx">_storageFieldReady
</span> <span class=
"o">=
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
336 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_browser
</span> <span class=
"o">==
</span> <span class=
"s2">"msie
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
338 <span class=
"nx">_iframe
</span> <span class=
"o">=
</span> <span class=
"nb">document
</span><span class=
"o">.
</span><span class=
"nx">getElementById
</span><span class=
"o">(
</span> <span class=
"s2">"yui_hist_iframe
"</span> <span class=
"o">);
</span>
339 <span class=
"nx">_checkIframeLoaded
</span><span class=
"o">();
</span>
341 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"o">{
</span>
343 <span class=
"c">// Start the thread that will have the responsibility to
</span>
344 <span class=
"c"></span> <span class=
"c">// periodically check whether a navigate operation has been
</span>
345 <span class=
"c"></span> <span class=
"c">// requested on the main window. This will happen when
</span>
346 <span class=
"c"></span> <span class=
"c">// YAHOO.util.History.navigate has been called or after
</span>
347 <span class=
"c"></span> <span class=
"c">// the user has hit the back/forward button.
</span>
348 <span class=
"c"></span>
349 <span class=
"c">// On Safari
1.x and
2.0, the only way to catch a back/forward
</span>
350 <span class=
"c"></span> <span class=
"c">// operation is to watch history.length... We basically exploit
</span>
351 <span class=
"c"></span> <span class=
"c">// what I consider to be a bug (history.length is not supposed
</span>
352 <span class=
"c"></span> <span class=
"c">// to change when going back/forward in the history...) This is
</span>
353 <span class=
"c"></span> <span class=
"c">// why, in the following thread, we first compare the hash,
</span>
354 <span class=
"c"></span> <span class=
"c">// because the hash thing will be fixed in the next major
</span>
355 <span class=
"c"></span> <span class=
"c">// version of Safari. So even if they fix the history.length
</span>
356 <span class=
"c"></span> <span class=
"c">// bug, all this will still work!
</span>
357 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">counter
</span> <span class=
"o">=
</span> <span class=
"nx">history
</span><span class=
"o">.
</span><span class=
"nx">length
</span><span class=
"o">;
</span>
359 <span class=
"c">// On Gecko and Opera, we just need to watch the hash...
</span>
360 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">hash
</span> <span class=
"o">=
</span> <span class=
"nx">_getHash
</span><span class=
"o">();
</span>
362 <span class=
"nx">setInterval
</span><span class=
"o">(
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
363 <span class=
"k">var
</span> <span class=
"nx">state
</span><span class=
"o">;
</span>
364 <span class=
"k">var
</span> <span class=
"nx">newHash
</span> <span class=
"o">=
</span> <span class=
"nx">_getHash
</span><span class=
"o">();
</span>
365 <span class=
"k">var
</span> <span class=
"nx">newCounter
</span> <span class=
"o">=
</span> <span class=
"nx">history
</span><span class=
"o">.
</span><span class=
"nx">length
</span><span class=
"o">;
</span>
366 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">newHash
</span> <span class=
"o">!=
</span> <span class=
"nx">hash
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
367 <span class=
"nx">hash
</span> <span class=
"o">=
</span> <span class=
"nx">newHash
</span><span class=
"o">;
</span>
368 <span class=
"nx">counter
</span> <span class=
"o">=
</span> <span class=
"nx">newCounter
</span><span class=
"o">;
</span>
369 <span class=
"nx">_handleFQStateChange
</span><span class=
"o">(
</span> <span class=
"nx">hash
</span> <span class=
"o">);
</span>
370 <span class=
"nx">_storeStates
</span><span class=
"o">();
</span>
371 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">newCounter
</span> <span class=
"o">!=
</span> <span class=
"nx">counter
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
372 <span class=
"c">// If we ever get here, we should be on Safari...
</span>
373 <span class=
"c"></span> <span class=
"nx">hash
</span> <span class=
"o">=
</span> <span class=
"nx">newHash
</span><span class=
"o">;
</span>
374 <span class=
"nx">counter
</span> <span class=
"o">=
</span> <span class=
"nx">newCounter
</span><span class=
"o">;
</span>
375 <span class=
"nx">state
</span> <span class=
"o">=
</span> <span class=
"nx">_fqstates
</span><span class=
"o">[
</span><span class=
"nx">counter
</span><span class=
"o">-
</span><span class=
"m">1</span><span class=
"o">];
</span>
376 <span class=
"nx">_handleFQStateChange
</span><span class=
"o">(
</span> <span class=
"nx">state
</span> <span class=
"o">);
</span>
377 <span class=
"nx">_storeStates
</span><span class=
"o">();
</span>
378 <span class=
"o">}
</span>
379 <span class=
"o">},
</span> <span class=
"m">50</span> <span class=
"o">);
</span>
381 <span class=
"nx">_bhmReady
</span> <span class=
"o">=
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
383 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">History
</span><span class=
"o">.
</span><span class=
"nx">onLoadEvent
</span><span class=
"o">.
</span><span class=
"nx">fire
</span><span class=
"o">();
</span>
384 <span class=
"o">}
</span>
385 <span class=
"o">}
</span>
387 <span class=
"c">// Simple browser detection code
</span>
388 <span class=
"c"></span> <span class=
"c">// After talking with Matt Sweeney, I moved back to using the
</span>
389 <span class=
"c"></span> <span class=
"c">// user agent string instead of doing browser detection.
</span>
390 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">ua
</span> <span class=
"o">=
</span> <span class=
"nx">navigator
</span><span class=
"o">.
</span><span class=
"nx">userAgent
</span><span class=
"o">.
</span><span class=
"nx">toLowerCase
</span><span class=
"o">();
</span>
391 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">ua
</span><span class=
"o">.
</span><span class=
"nx">indexOf
</span><span class=
"o">(
</span> <span class=
"s2">"opera
"</span> <span class=
"o">)
</span> <span class=
"o">!=
</span> <span class=
"o">-
</span><span class=
"m">1</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
392 <span class=
"c">// Opera (check first in case of spoof)
</span>
393 <span class=
"c"></span> <span class=
"nx">_browser
</span> <span class=
"o">=
</span> <span class=
"s2">"opera
"</span><span class=
"o">;
</span>
394 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">ua
</span><span class=
"o">.
</span><span class=
"nx">indexOf
</span><span class=
"o">(
</span> <span class=
"s2">"msie
"</span> <span class=
"o">)
</span> <span class=
"o">!=
</span> <span class=
"o">-
</span><span class=
"m">1</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
395 <span class=
"c">// Microsoft Internet Explorer and derivatives...
</span>
396 <span class=
"c"></span> <span class=
"nx">_browser
</span> <span class=
"o">=
</span> <span class=
"s2">"msie
"</span><span class=
"o">;
</span>
397 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">ua
</span><span class=
"o">.
</span><span class=
"nx">indexOf
</span><span class=
"o">(
</span> <span class=
"s2">"safari
"</span> <span class=
"o">)
</span> <span class=
"o">!=
</span> <span class=
"o">-
</span><span class=
"m">1</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
398 <span class=
"c">// Safari (check before Gecko because it includes
"like Gecko
")
</span>
399 <span class=
"c"></span> <span class=
"nx">_browser
</span> <span class=
"o">=
</span> <span class=
"s2">"safari
"</span><span class=
"o">;
</span>
400 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">ua
</span><span class=
"o">.
</span><span class=
"nx">indexOf
</span><span class=
"o">(
</span> <span class=
"s2">"gecko
"</span> <span class=
"o">)
</span> <span class=
"o">!=
</span> <span class=
"o">-
</span><span class=
"m">1</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
401 <span class=
"c">// Gecko
</span>
402 <span class=
"c"></span> <span class=
"nx">_browser
</span> <span class=
"o">=
</span> <span class=
"s2">"gecko
"</span><span class=
"o">;
</span>
403 <span class=
"o">}
</span>
405 <span class=
"k">return
</span> <span class=
"o">{
</span>
407 <span class=
"c">/**
</span>
408 <span class=
"c"> * Fired when the Browser History Manager is ready.
</span>
409 <span class=
"c"> *
</span>
410 <span class=
"c"> * @event onLoadEvent
</span>
411 <span class=
"c"> */
</span>
412 <span class=
"nx">onLoadEvent
</span> <span class=
"o">:
</span> <span class=
"k">new
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">CustomEvent
</span><span class=
"o">(
</span> <span class=
"s2">"onLoad
"</span> <span class=
"o">),
</span>
414 <span class=
"c">/**
</span>
415 <span class=
"c"> * Registers a new module.
</span>
416 <span class=
"c"> *
</span>
417 <span class=
"c"> * @method register
</span>
418 <span class=
"c"> * @param {string} module Non-empty string uniquely identifying the
</span>
419 <span class=
"c"> * module you wish to register.
</span>
420 <span class=
"c"> * @param {string} initialState The initial state of the specified
</span>
421 <span class=
"c"> * module corresponding to its earliest history entry.
</span>
422 <span class=
"c"> * @param {function} onStateChange Callback called when the
</span>
423 <span class=
"c"> * state of the specified module has changed.
</span>
424 <span class=
"c"> */
</span>
425 <span class=
"nx">register
</span> <span class=
"o">:
</span> <span class=
"k">function
</span><span class=
"o">(
</span> <span class=
"nx">module
</span><span class=
"o">,
</span> <span class=
"nx">initialState
</span><span class=
"o">,
</span> <span class=
"nx">onStateChange
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
426 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"k">typeof
</span> <span class=
"nx">module
</span> <span class=
"o">!=
</span> <span class=
"s2">"string
"</span> <span class=
"o">||
</span> <span class=
"nx">_trim
</span><span class=
"o">(
</span> <span class=
"nx">module
</span> <span class=
"o">)
</span> <span class=
"o">===
</span> <span class=
"s2">""</span> <span class=
"o">||
</span>
427 <span class=
"k">typeof
</span> <span class=
"nx">initialState
</span> <span class=
"o">!=
</span> <span class=
"s2">"string
"</span> <span class=
"o">||
</span>
428 <span class=
"k">typeof
</span> <span class=
"nx">onStateChange
</span> <span class=
"o">!=
</span> <span class=
"s2">"function
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
429 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"Missing or invalid argument passed to YAHOO.util.History.register
"</span> <span class=
"o">);
</span>
430 <span class=
"o">}
</span>
432 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">module
</span><span class=
"o">]
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
433 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"A module cannot be registered twice
"</span> <span class=
"o">);
</span>
434 <span class=
"o">}
</span>
436 <span class=
"c">// Note: A module CANNOT be registered after calling
</span>
437 <span class=
"c"></span> <span class=
"c">// YAHOO.util.History.initialize. Indeed, we set the initial state
</span>
438 <span class=
"c"></span> <span class=
"c">// of each registered module in YAHOO.util.History.initialize.
</span>
439 <span class=
"c"></span> <span class=
"c">// If you could register a module after initializing the Browser
</span>
440 <span class=
"c"></span> <span class=
"c">// History Manager, you would not read the correct state using
</span>
441 <span class=
"c"></span> <span class=
"c">// YAHOO.util.History.getCurrentState when coming back to the
</span>
442 <span class=
"c"></span> <span class=
"c">// page using the back button.
</span>
443 <span class=
"c"></span> <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_initialized
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
444 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"All modules must be registered before calling YAHOO.util.History.initialize
"</span> <span class=
"o">);
</span>
445 <span class=
"o">}
</span>
447 <span class=
"c">// Make sure the strings passed in do not contain our separators
",
" and
"|
"</span>
448 <span class=
"c"></span> <span class=
"nx">module
</span> <span class=
"o">=
</span> <span class=
"nx">escape
</span><span class=
"o">(
</span> <span class=
"nx">module
</span> <span class=
"o">);
</span>
449 <span class=
"nx">initialState
</span> <span class=
"o">=
</span> <span class=
"nx">escape
</span><span class=
"o">(
</span> <span class=
"nx">initialState
</span> <span class=
"o">);
</span>
451 <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">module
</span><span class=
"o">]
</span> <span class=
"o">=
</span> <span class=
"o">{
</span>
452 <span class=
"nx">name
</span> <span class=
"o">:
</span> <span class=
"nx">module
</span><span class=
"o">,
</span>
453 <span class=
"nx">initialState
</span> <span class=
"o">:
</span> <span class=
"nx">initialState
</span><span class=
"o">,
</span>
454 <span class=
"nx">currentState
</span> <span class=
"o">:
</span> <span class=
"nx">initialState
</span><span class=
"o">,
</span>
455 <span class=
"nx">onStateChange
</span> <span class=
"o">:
</span> <span class=
"nx">onStateChange
</span>
456 <span class=
"o">};
</span>
457 <span class=
"o">},
</span>
459 <span class=
"c">/**
</span>
460 <span class=
"c"> * Initializes the Browser History Manager. Call this method
</span>
461 <span class=
"c"> * from a script block located right after the opening body tag.
</span>
462 <span class=
"c"> *
</span>
463 <span class=
"c"> * @method initialize
</span>
464 <span class=
"c"> * @param {string} iframeTarget Optional - Path to an existing
</span>
465 <span class=
"c"> * HTML document accessible from the same domain. If not
</span>
466 <span class=
"c"> * specified, defaults to
"blank.html
"</span>
467 <span class=
"c"> * @public
</span>
468 <span class=
"c"> */
</span>
469 <span class=
"nx">initialize
</span> <span class=
"o">:
</span> <span class=
"k">function
</span><span class=
"o">(
</span> <span class=
"nx">iframeTarget
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
470 <span class=
"c">// Return if the browser history manager has already been initialized
</span>
471 <span class=
"c"></span> <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_initialized
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
472 <span class=
"k">return
</span><span class=
"o">;
</span>
473 <span class=
"o">}
</span>
475 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_browser
</span> <span class=
"o">==
</span> <span class=
"s2">"unknown
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
476 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"Your web browser is not supported by the Browser History Manager
"</span> <span class=
"o">);
</span>
477 <span class=
"o">}
</span>
479 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">iframeTarget
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
480 <span class=
"nx">iframeTarget
</span> <span class=
"o">=
</span> <span class=
"s2">"blank.html
"</span><span class=
"o">;
</span>
481 <span class=
"o">}
</span>
483 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"k">typeof
</span> <span class=
"nx">iframeTarget
</span> <span class=
"o">!=
</span> <span class=
"s2">"string
"</span> <span class=
"o">||
</span> <span class=
"nx">_trim
</span><span class=
"o">(
</span> <span class=
"nx">iframeTarget
</span> <span class=
"o">)
</span> <span class=
"o">===
</span> <span class=
"s2">""</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
484 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"Invalid argument passed to YAHOO.util.History.initialize
"</span> <span class=
"o">);
</span>
485 <span class=
"o">}
</span>
487 <span class=
"nb">document
</span><span class=
"o">.
</span><span class=
"nx">write
</span><span class=
"o">(
</span> <span class=
"s1">'<input type=
"hidden
" id=
"yui_hist_field
">'</span> <span class=
"o">);
</span>
488 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_browser
</span> <span class=
"o">==
</span> <span class=
"s2">"msie
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
489 <span class=
"c">// Pointing the IFrame to a file on the server is absolutely
</span>
490 <span class=
"c"></span> <span class=
"c">// essential. I tried to point it to nothing (by setting
</span>
491 <span class=
"c"></span> <span class=
"c">// src=
"") and create the initial entry in the browser
</span>
492 <span class=
"c"></span> <span class=
"c">// history (by using document.write) but it did not work
</span>
493 <span class=
"c"></span> <span class=
"c">// when coming back to the page... Also, the file must exist
</span>
494 <span class=
"c"></span> <span class=
"c">// on the server!
</span>
495 <span class=
"c"></span> <span class=
"nb">document
</span><span class=
"o">.
</span><span class=
"nx">write
</span><span class=
"o">(
</span> <span class=
"s1">'<iframe id=
"yui_hist_iframe
" src=
"'</span> <span class=
"o">+
</span> <span class=
"nx">iframeTarget
</span> <span class=
"o">+
</span> <span class=
"s1">'" style=
"position:absolute;visibility:hidden;
"></iframe
>'</span> <span class=
"o">);
</span>
496 <span class=
"o">}
</span>
498 <span class=
"c">// We have to wait for the window
's onload handler. Otherwise, our
</span>
499 <span class=
"c"></span> <span class=
"c">// hidden form field will always be empty (i.e. the browser won
't
</span>
500 <span class=
"c"></span> <span class=
"c">// have had enough time to restore the session)
</span>
501 <span class=
"c"></span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">Event
</span><span class=
"o">.
</span><span class=
"nx">addListener
</span><span class=
"o">(
</span> <span class=
"nb">window
</span><span class=
"o">,
</span> <span class=
"s2">"load
"</span><span class=
"o">,
</span> <span class=
"nx">_initialize
</span> <span class=
"o">);
</span>
503 <span class=
"nx">_initialized
</span> <span class=
"o">=
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
504 <span class=
"o">},
</span>
506 <span class=
"c">/**
</span>
507 <span class=
"c"> * Call this method when you want to store a new entry in the browser
's history.
</span>
508 <span class=
"c"> *
</span>
509 <span class=
"c"> * @method navigate
</span>
510 <span class=
"c"> * @param {string} module Non-empty string representing your module.
</span>
511 <span class=
"c"> * @param {string} state String representing the new state of the specified module.
</span>
512 <span class=
"c"> * @return {boolean} Indicates whether the new state was successfully added to the history.
</span>
513 <span class=
"c"> * @public
</span>
514 <span class=
"c"> */
</span>
515 <span class=
"nx">navigate
</span> <span class=
"o">:
</span> <span class=
"k">function
</span><span class=
"o">(
</span> <span class=
"nx">module
</span><span class=
"o">,
</span> <span class=
"nx">state
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
516 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"k">typeof
</span> <span class=
"nx">module
</span> <span class=
"o">!=
</span> <span class=
"s2">"string
"</span> <span class=
"o">||
</span> <span class=
"k">typeof
</span> <span class=
"nx">state
</span> <span class=
"o">!=
</span> <span class=
"s2">"string
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
517 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"Missing or invalid argument passed to YAHOO.util.History.navigate
"</span> <span class=
"o">);
</span>
518 <span class=
"o">}
</span>
520 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">_bhmReady
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
521 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"The Browser History Manager is not initialized
"</span> <span class=
"o">);
</span>
522 <span class=
"o">}
</span>
524 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">module
</span><span class=
"o">]
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
525 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"The following module has not been registered:
"</span> <span class=
"o">+
</span> <span class=
"nx">module
</span> <span class=
"o">);
</span>
526 <span class=
"o">}
</span>
528 <span class=
"c">// Make sure the strings passed in do not contain our separators
",
" and
"|
"</span>
529 <span class=
"c"></span> <span class=
"nx">module
</span> <span class=
"o">=
</span> <span class=
"nx">escape
</span><span class=
"o">(
</span> <span class=
"nx">module
</span> <span class=
"o">);
</span>
530 <span class=
"nx">state
</span> <span class=
"o">=
</span> <span class=
"nx">escape
</span><span class=
"o">(
</span> <span class=
"nx">state
</span> <span class=
"o">);
</span>
532 <span class=
"c">// Generate our new full state string mod1=xxx
&mod2=yyy
</span>
533 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">currentStates
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
534 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"k">var
</span> <span class=
"nx">moduleName
</span> <span class=
"k">in
</span> <span class=
"nx">_modules
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
535 <span class=
"k">var
</span> <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">moduleName
</span><span class=
"o">];
</span>
536 <span class=
"k">var
</span> <span class=
"nx">currentState
</span> <span class=
"o">=
</span> <span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"o">==
</span> <span class=
"nx">module
</span> <span class=
"o">)
</span> <span class=
"o">?
</span> <span class=
"nx">state
</span> <span class=
"o">:
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span><span class=
"o">;
</span>
537 <span class=
"nx">currentStates
</span><span class=
"o">.
</span><span class=
"nx">push
</span><span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"o">+
</span> <span class=
"s2">"=
"</span> <span class=
"o">+
</span> <span class=
"nx">currentState
</span> <span class=
"o">);
</span>
538 <span class=
"o">}
</span>
540 <span class=
"k">var
</span> <span class=
"nx">fqstate
</span> <span class=
"o">=
</span> <span class=
"nx">currentStates
</span><span class=
"o">.
</span><span class=
"nx">join
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
542 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_browser
</span> <span class=
"o">==
</span> <span class=
"s2">"msie
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
544 <span class=
"c">// Add a new entry to the browser
's history...
</span>
545 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">html
</span> <span class=
"o">=
</span> <span class=
"s1">'<html
><body
><div id=
"state
">'</span> <span class=
"o">+
</span> <span class=
"nx">fqstate
</span> <span class=
"o">+
</span> <span class=
"s1">'</div
></body
></html
>'</span><span class=
"o">;
</span>
546 <span class=
"k">try
</span> <span class=
"o">{
</span>
547 <span class=
"k">var
</span> <span class=
"nx">doc
</span> <span class=
"o">=
</span> <span class=
"nx">_iframe
</span><span class=
"o">.
</span><span class=
"nx">contentWindow
</span><span class=
"o">.
</span><span class=
"nb">document
</span><span class=
"o">;
</span>
548 <span class=
"nx">doc
</span><span class=
"o">.
</span><span class=
"nx">open
</span><span class=
"o">();
</span>
549 <span class=
"nx">doc
</span><span class=
"o">.
</span><span class=
"nx">write
</span><span class=
"o">(
</span> <span class=
"nx">html
</span> <span class=
"o">);
</span>
550 <span class=
"nx">doc
</span><span class=
"o">.
</span><span class=
"nx">close
</span><span class=
"o">();
</span>
551 <span class=
"o">}
</span> <span class=
"k">catch
</span> <span class=
"o">(
</span> <span class=
"nx">e
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
552 <span class=
"k">return
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
553 <span class=
"o">}
</span>
555 <span class=
"o">}
</span> <span class=
"k">else
</span> <span class=
"o">{
</span>
557 <span class=
"c">// Known bug: On Safari
1.x and
2.0, if you have tab browsing
</span>
558 <span class=
"c"></span> <span class=
"c">// enabled, Safari will show an endless loading icon in the
</span>
559 <span class=
"c"></span> <span class=
"c">// tab. This has apparently been fixed in recent WebKit builds.
</span>
560 <span class=
"c"></span> <span class=
"c">// One work around found by Dav Glass is to submit a form that
</span>
561 <span class=
"c"></span> <span class=
"c">// points to the same document. This indeed works on Safari
1.x
</span>
562 <span class=
"c"></span> <span class=
"c">// and
2.0 but creates bigger problems on WebKit. So for now,
</span>
563 <span class=
"c"></span> <span class=
"c">// we
'll consider this an acceptable bug, and hope that Apple
</span>
564 <span class=
"c"></span> <span class=
"c">// comes out with their next version of Safari very soon.
</span>
565 <span class=
"c"></span> <span class=
"nx">top
</span><span class=
"o">.
</span><span class=
"nx">location
</span><span class=
"o">.
</span><span class=
"nx">hash
</span> <span class=
"o">=
</span> <span class=
"nx">fqstate
</span><span class=
"o">;
</span>
566 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">_browser
</span> <span class=
"o">==
</span> <span class=
"s2">"safari
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
567 <span class=
"c">// The following two lines are only useful for Safari
1.x
</span>
568 <span class=
"c"></span> <span class=
"c">// and
2.0. Recent nightly builds of WebKit do not require
</span>
569 <span class=
"c"></span> <span class=
"c">// that, but unfortunately, it is not easy to differentiate
</span>
570 <span class=
"c"></span> <span class=
"c">// between the two. Once Safari
2.0 departs the A-grade
</span>
571 <span class=
"c"></span> <span class=
"c">// list, we can remove the following two lines...
</span>
572 <span class=
"c"></span> <span class=
"nx">_fqstates
</span><span class=
"o">[
</span><span class=
"nx">history
</span><span class=
"o">.
</span><span class=
"nx">length
</span><span class=
"o">]
</span> <span class=
"o">=
</span> <span class=
"nx">fqstate
</span><span class=
"o">;
</span>
573 <span class=
"nx">_storeStates
</span><span class=
"o">();
</span>
574 <span class=
"o">}
</span>
576 <span class=
"o">}
</span>
578 <span class=
"k">return
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
579 <span class=
"o">},
</span>
581 <span class=
"c">/**
</span>
582 <span class=
"c"> * Returns the current state of the specified module.
</span>
583 <span class=
"c"> *
</span>
584 <span class=
"c"> * @method getCurrentState
</span>
585 <span class=
"c"> * @param {string} module Non-empty string representing your module.
</span>
586 <span class=
"c"> * @return {string} The current state of the specified module.
</span>
587 <span class=
"c"> * @public
</span>
588 <span class=
"c"> */
</span>
589 <span class=
"nx">getCurrentState
</span> <span class=
"o">:
</span> <span class=
"k">function
</span><span class=
"o">(
</span> <span class=
"nx">module
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
590 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"k">typeof
</span> <span class=
"nx">module
</span> <span class=
"o">!=
</span> <span class=
"s2">"string
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
591 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"Missing or invalid argument passed to YAHOO.util.History.getCurrentState
"</span> <span class=
"o">);
</span>
592 <span class=
"o">}
</span>
594 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">_storageFieldReady
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
595 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"The Browser History Manager is not initialized
"</span> <span class=
"o">);
</span>
596 <span class=
"o">}
</span>
598 <span class=
"k">var
</span> <span class=
"nx">moduleObj
</span> <span class=
"o">=
</span> <span class=
"nx">_modules
</span><span class=
"o">[
</span><span class=
"nx">module
</span><span class=
"o">];
</span>
599 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"o">!
</span><span class=
"nx">moduleObj
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
600 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"No such registered module:
"</span> <span class=
"o">+
</span> <span class=
"nx">module
</span> <span class=
"o">);
</span>
601 <span class=
"o">}
</span>
603 <span class=
"k">return
</span> <span class=
"nx">unescape
</span><span class=
"o">(
</span> <span class=
"nx">moduleObj
</span><span class=
"o">.
</span><span class=
"nx">currentState
</span> <span class=
"o">);
</span>
604 <span class=
"o">},
</span>
606 <span class=
"c">/**
</span>
607 <span class=
"c"> * Returns the state of a module according to the URL fragment
</span>
608 <span class=
"c"> * identifier. This method is useful to initialize your modules
</span>
609 <span class=
"c"> * if your application was bookmarked from a particular state.
</span>
610 <span class=
"c"> *
</span>
611 <span class=
"c"> * @method getBookmarkedState
</span>
612 <span class=
"c"> * @param {string} module Non-empty string representing your module.
</span>
613 <span class=
"c"> * @return {string} The bookmarked state of the specified module.
</span>
614 <span class=
"c"> * @public
</span>
615 <span class=
"c"> */
</span>
616 <span class=
"nx">getBookmarkedState
</span> <span class=
"o">:
</span> <span class=
"k">function
</span><span class=
"o">(
</span> <span class=
"nx">module
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
617 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"k">typeof
</span> <span class=
"nx">module
</span> <span class=
"o">!=
</span> <span class=
"s2">"string
"</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
618 <span class=
"k">throw
</span> <span class=
"k">new
</span> <span class=
"nb">Error
</span><span class=
"o">(
</span> <span class=
"s2">"Missing or invalid argument passed to YAHOO.util.History.getBookmarkedState
"</span> <span class=
"o">);
</span>
619 <span class=
"o">}
</span>
621 <span class=
"k">var
</span> <span class=
"nx">hash
</span> <span class=
"o">=
</span> <span class=
"nx">top
</span><span class=
"o">.
</span><span class=
"nx">location
</span><span class=
"o">.
</span><span class=
"nx">hash
</span><span class=
"o">.
</span><span class=
"nx">substr
</span><span class=
"o">(
</span><span class=
"m">1</span><span class=
"o">);
</span>
622 <span class=
"k">var
</span> <span class=
"nx">states
</span> <span class=
"o">=
</span> <span class=
"nx">hash
</span><span class=
"o">.
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
623 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"k">var
</span> <span class=
"nx">idx
</span><span class=
"o">=
</span><span class=
"m">0</span><span class=
"o">,
</span> <span class=
"nx">len
</span><span class=
"o">=
</span><span class=
"nx">states
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o"><</span><span class=
"nx">len
</span> <span class=
"o">;
</span> <span class=
"nx">idx
</span><span class=
"o">++
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
624 <span class=
"k">var
</span> <span class=
"nx">tokens
</span> <span class=
"o">=
</span> <span class=
"nx">states
</span><span class=
"o">[
</span><span class=
"nx">idx
</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"=
"</span> <span class=
"o">);
</span>
625 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">tokens
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">==
</span> <span class=
"m">2</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
626 <span class=
"k">var
</span> <span class=
"nx">moduleName
</span> <span class=
"o">=
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">];
</span>
627 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">moduleName
</span> <span class=
"o">==
</span> <span class=
"nx">module
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
628 <span class=
"k">return
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">];
</span>
629 <span class=
"o">}
</span>
630 <span class=
"o">}
</span>
631 <span class=
"o">}
</span>
633 <span class=
"k">return
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
634 <span class=
"o">},
</span>
636 <span class=
"c">/**
</span>
637 <span class=
"c"> * Returns the value of the specified query string parameter.
</span>
638 <span class=
"c"> * This method is not used internally by the Browser History Manager.
</span>
639 <span class=
"c"> * However, it is provided here as a helper since many applications
</span>
640 <span class=
"c"> * using the Browser History Manager will want to read the value of
</span>
641 <span class=
"c"> * url parameters to initialize themselves.
</span>
642 <span class=
"c"> *
</span>
643 <span class=
"c"> * @method getQueryStringParameter
</span>
644 <span class=
"c"> * @param {string} paramName Name of the parameter we want to look up.
</span>
645 <span class=
"c"> * @param {string} queryString Optional URL to look at. If not specified,
</span>
646 <span class=
"c"> * this method uses the URL in the address bar.
</span>
647 <span class=
"c"> * @return {string} The value of the specified parameter, or null.
</span>
648 <span class=
"c"> * @public
</span>
649 <span class=
"c"> */
</span>
650 <span class=
"nx">getQueryStringParameter
</span> <span class=
"o">:
</span> <span class=
"k">function
</span><span class=
"o">(
</span> <span class=
"nx">paramName
</span><span class=
"o">,
</span> <span class=
"nx">url
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
651 <span class=
"nx">url
</span> <span class=
"o">=
</span> <span class=
"nx">url
</span> <span class=
"o">||
</span> <span class=
"nx">top
</span><span class=
"o">.
</span><span class=
"nx">location
</span><span class=
"o">.
</span><span class=
"nx">href
</span><span class=
"o">;
</span>
652 <span class=
"k">var
</span> <span class=
"nx">idx
</span> <span class=
"o">=
</span> <span class=
"nx">url
</span><span class=
"o">.
</span><span class=
"nx">indexOf
</span><span class=
"o">(
</span> <span class=
"s2">"?
"</span> <span class=
"o">);
</span>
653 <span class=
"k">var
</span> <span class=
"nx">queryString
</span> <span class=
"o">=
</span> <span class=
"nx">idx
</span> <span class=
"o">>=
</span> <span class=
"m">0</span> <span class=
"o">?
</span> <span class=
"nx">url
</span><span class=
"o">.
</span><span class=
"nx">substr
</span><span class=
"o">(
</span> <span class=
"nx">idx
</span><span class=
"o">+
</span><span class=
"m">1</span> <span class=
"o">)
</span> <span class=
"o">:
</span> <span class=
"nx">url
</span><span class=
"o">;
</span>
654 <span class=
"k">var
</span> <span class=
"nx">params
</span> <span class=
"o">=
</span> <span class=
"nx">queryString
</span><span class=
"o">.
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"&"</span> <span class=
"o">);
</span>
655 <span class=
"k">for
</span> <span class=
"o">(
</span> <span class=
"k">var
</span> <span class=
"nx">i
</span><span class=
"o">=
</span><span class=
"m">0</span><span class=
"o">,
</span> <span class=
"nx">len
</span><span class=
"o">=
</span><span class=
"nx">params
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">;
</span> <span class=
"nx">i
</span><span class=
"o"><</span><span class=
"nx">len
</span> <span class=
"o">;
</span> <span class=
"nx">i
</span><span class=
"o">++
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
656 <span class=
"k">var
</span> <span class=
"nx">tokens
</span> <span class=
"o">=
</span> <span class=
"nx">params
</span><span class=
"o">[
</span><span class=
"nx">i
</span><span class=
"o">].
</span><span class=
"nx">split
</span><span class=
"o">(
</span> <span class=
"s2">"=
"</span> <span class=
"o">);
</span>
657 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">tokens
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">>=
</span> <span class=
"m">2</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
658 <span class=
"k">if
</span> <span class=
"o">(
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">0</span><span class=
"o">]
</span> <span class=
"o">==
</span> <span class=
"nx">paramName
</span> <span class=
"o">)
</span> <span class=
"o">{
</span>
659 <span class=
"k">return
</span> <span class=
"nx">tokens
</span><span class=
"o">[
</span><span class=
"m">1</span><span class=
"o">];
</span>
660 <span class=
"o">}
</span>
661 <span class=
"o">}
</span>
662 <span class=
"o">}
</span>
663 <span class=
"k">return
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
664 <span class=
"o">}
</span>
666 <span class=
"o">};
</span>
668 <span class=
"o">}
</span> <span class=
"o">)();
</span>
680 <li class=
""><a href=
"module_animation.html">animation
</a></li>
682 <li class=
""><a href=
"module_autocomplete.html">autocomplete
</a></li>
684 <li class=
""><a href=
"module_button.html">button
</a></li>
686 <li class=
""><a href=
"module_calendar.html">calendar
</a></li>
688 <li class=
""><a href=
"module_connection.html">connection
</a></li>
690 <li class=
""><a href=
"module_container.html">container
</a></li>
692 <li class=
""><a href=
"module_datasource.html">datasource
</a></li>
694 <li class=
""><a href=
"module_datatable.html">datatable
</a></li>
696 <li class=
""><a href=
"module_dom.html">dom
</a></li>
698 <li class=
""><a href=
"module_dragdrop.html">dragdrop
</a></li>
700 <li class=
""><a href=
"module_element.html">element
</a></li>
702 <li class=
""><a href=
"module_event.html">event
</a></li>
704 <li class=
"selected"><a href=
"module_history.html">history
</a></li>
706 <li class=
""><a href=
"module_logger.html">logger
</a></li>
708 <li class=
""><a href=
"module_menu.html">menu
</a></li>
710 <li class=
""><a href=
"module_slider.html">slider
</a></li>
712 <li class=
""><a href=
"module_tabview.html">tabview
</a></li>
714 <li class=
""><a href=
"module_treeview.html">treeview
</a></li>
716 <li class=
""><a href=
"module_yahoo.html">yahoo
</a></li>
723 <li class=
""><a href=
"YAHOO.util.History.html">YAHOO.util.History
</a></li>
730 <li class=
"selected"><a href=
"history.js.html">history.js
</a></li>
743 Copyright
© 2007 Yahoo! Inc. All rights reserved.