@@ -163,6 +163,21 @@ module Window {
163
163
window .port == current .port )
164
164
}
165
165
166
+ /*
167
+ Like `Window.navigate()`, but also triggers a jump to the start of the
168
+ document or the hash, if it exists.
169
+
170
+ Window.jump("/new-url")
171
+ */
172
+ fun jump (url : String ) : Promise (Void ) {
173
+ `_navigate (
174
+ #{url},
175
+ /* dispatch */ true ,
176
+ /* triggerJump */ true ,
177
+ /* routeInfo */ null
178
+ )`
179
+ }
180
+
166
181
/*
167
182
Returns `true` if the given media query matches.
168
183
@@ -173,16 +188,22 @@ module Window {
173
188
}
174
189
175
190
/*
176
- Navigates to the given URL.
191
+ Sets the URL of the window. If there is a route defined for this URL, runs
192
+ its handler. Updates the navigation history.
177
193
178
- Window.navigate("https://www.example.com ")
194
+ Window.navigate("/new-url ")
179
195
*/
180
196
fun navigate (url : String ) : Promise (Void ) {
181
- `_navigate (#{url})`
197
+ `_navigate (
198
+ #{url},
199
+ /* dispatch */ true ,
200
+ /* triggerJump */ false ,
201
+ /* routeInfo */ null
202
+ )`
182
203
}
183
204
184
205
/*
185
- Opens the given url in a new window.
206
+ Opens the given url in a new window or tab .
186
207
187
208
Window.open("https://www.google.com")
188
209
*/
@@ -303,12 +324,17 @@ module Window {
303
324
}
304
325
305
326
/*
306
- Sets the URL of the window without navigating to it .
327
+ Sets the URL of the window.
307
328
308
- Window.setUrl("https://www.example.com ")
329
+ Window.setUrl("/new-url ")
309
330
*/
310
331
fun setUrl (url : String ) : Promise (Void ) {
311
- `_navigate (#{url}, false )`
332
+ `_navigate (
333
+ #{url},
334
+ /* dispatch */ false ,
335
+ /* triggerJump */ false ,
336
+ /* routeInfo */ null
337
+ )`
312
338
}
313
339
314
340
/*
@@ -321,15 +347,17 @@ module Window {
321
347
}
322
348
323
349
/*
324
- Triggers the hash location jump on the page.
350
+ Triggers a jump to the current location on the page.
325
351
326
- When a page loads and the current url has a hash `#anchor-name` the browser
327
- automatically jumps to the matching anchor tag `<a name="anchor-name">`, but
328
- this behavior does not happen when the history is manipulated.
352
+ When a page loads and the current url has a hash `#anchor-name`, the browser
353
+ automatically jumps to the element with the matching id or to the anchor tag
354
+ with the matching name `<a name="anchor-name">`. This behavior does not happen
355
+ when the history is manipulated manually.
329
356
330
- This function triggers that behavior.
357
+ This function triggers that behavior. When there is a hash in the current URL,
358
+ it jumps to it, otherwise it jumps to the start of the document.
331
359
*/
332
- fun triggerHashJump : Promise (Void ) {
360
+ fun triggerJump : Promise (Void ) {
333
361
`requestAnimationFrame (() => {
334
362
if (window .location .hash ) {
335
363
window .location .href = window .location .hash
0 commit comments