5
5
@namespace Discourse
6
6
@module Discourse
7
7
**/
8
- Discourse . URL = {
8
+ Discourse . URL = Em . Object . createWithMixins ( {
9
9
10
10
// Used for matching a topic
11
11
TOPIC_REGEXP : / \/ t \/ ( [ ^ \/ ] + ) \/ ( \d + ) \/ ? ( \d + ) ? / ,
@@ -23,7 +23,7 @@ Discourse.URL = {
23
23
**/
24
24
router : function ( ) {
25
25
return Discourse . __container__ . lookup ( 'router:main' ) ;
26
- } ,
26
+ } . property ( ) ,
27
27
28
28
/**
29
29
Browser aware replaceState. Will only be invoked if the browser supports it.
@@ -43,7 +43,8 @@ Discourse.URL = {
43
43
// while URLs are loading. For example, while a topic loads it sets `currentPost`
44
44
// which triggers a replaceState even though the topic hasn't fully loaded yet!
45
45
Em . run . next ( function ( ) {
46
- Discourse . URL . router ( ) . get ( 'location' ) . replaceURL ( path ) ;
46
+ var location = Discourse . URL . get ( 'router.location' ) ;
47
+ if ( location . replaceURL ) { location . replaceURL ( path ) ; }
47
48
} ) ;
48
49
}
49
50
} ,
@@ -85,10 +86,16 @@ Discourse.URL = {
85
86
if ( oldTopicId === newTopicId ) {
86
87
Discourse . URL . replaceState ( path ) ;
87
88
var topicController = Discourse . __container__ . lookup ( 'controller:topic' ) ;
88
- var opts = { trackVisit : false } ;
89
+ var opts = { } ;
89
90
if ( newMatches [ 3 ] ) opts . nearPost = newMatches [ 3 ] ;
90
- topicController . cancelFilter ( ) ;
91
- topicController . loadPosts ( opts ) ;
91
+
92
+ var postStream = topicController . get ( 'postStream' ) ;
93
+ postStream . refresh ( opts ) . then ( function ( ) {
94
+ topicController . setProperties ( {
95
+ currentPost : opts . nearPost || 1 ,
96
+ progressPosition : opts . nearPost || 1
97
+ } ) ;
98
+ } ) ;
92
99
93
100
// Abort routing, we have replaced our state.
94
101
return ;
@@ -102,11 +109,18 @@ Discourse.URL = {
102
109
103
110
// Be wary of looking up the router. In this case, we have links in our
104
111
// HTML, say form compiled markdown posts, that need to be routed.
105
- var router = this . router ( ) ;
112
+ var router = this . get ( 'router' ) ;
106
113
router . router . updateURL ( path ) ;
107
114
return router . handleURL ( path ) ;
108
115
} ,
109
116
117
+ /**
118
+ Replaces the query parameters in the URL. Use no parameters to clear them.
119
+
120
+ @method replaceQueryParams
121
+ **/
122
+ queryParams : Em . computed . alias ( 'router.location.queryParams' ) ,
123
+
110
124
/**
111
125
@private
112
126
@@ -131,4 +145,4 @@ Discourse.URL = {
131
145
window . location = Discourse . getURL ( url ) ;
132
146
}
133
147
134
- } ;
148
+ } ) ;
0 commit comments