|
3 | 3 | //>>label: AJAX Navigation System |
4 | 4 | //>>group: Navigation |
5 | 5 |
|
6 | | -// TODO break out pushstate support test so we don't |
7 | | -// depend on the whole thing |
| 6 | +// TODO break out pushstate support test so we don't depend on the whole thing |
8 | 7 | define([ "jquery", |
9 | | - "./../../jquery.mobile.support" ], function( $ ) { |
| 8 | + "./../../jquery.mobile.support" ], function( $ ) { |
10 | 9 | //>>excludeEnd("jqmBuildExclude"); |
11 | 10 |
|
12 | 11 | (function( $, undefined ) { |
13 | | - var $win = $( window ), self, bound; |
| 12 | + var $win = $( window ), self, history; |
14 | 13 |
|
15 | 14 | $.event.special.navigate = self = { |
16 | 15 | bound: false, |
17 | 16 |
|
| 17 | + // TODO use the originalEvent property on the event object |
| 18 | + // instead of from |
18 | 19 | popstate: function( event ) { |
| 20 | + var state = event.originalEvent.state; |
| 21 | + |
| 22 | + // NOTE the `|| {}` is there to ensure consistency between |
| 23 | + // the popstate navigate event and the hashchange navigate |
| 24 | + // event data |
19 | 25 | $win.trigger( new $.Event( "navigate" ), { |
20 | 26 | from: "popstate", |
21 | | - state: event.originalEvent.state |
| 27 | + state: state || {} |
22 | 28 | }); |
23 | 29 | }, |
24 | 30 |
|
25 | | - hashchange: function( event ) { |
| 31 | + // TODO use the originalEvent property on the event object |
| 32 | + // instead of from |
| 33 | + hashchange: function( event, data ) { |
| 34 | + // Trigger the hashchange with state provided by the user |
| 35 | + // that altered the hash |
26 | 36 | $win.trigger( new $.Event( "navigate" ), { |
27 | 37 | from: "hashchange", |
28 | | - state: {} |
| 38 | + // Users that want to fully normalize the two events |
| 39 | + // will need to do history management down the stack and |
| 40 | + // add the state to the event before this binding is fired |
| 41 | + state: event.hashchangeState || {} |
29 | 42 | }); |
30 | 43 | }, |
31 | 44 |
|
| 45 | + // TODO We really only want to set this up once |
| 46 | + // but I'm not clear if there's a beter way to achieve |
| 47 | + // this with the jQuery special event structure |
32 | 48 | setup: function( data, namespaces ) { |
33 | 49 | if( self.bound ) { |
34 | 50 | return; |
|
0 commit comments