@@ -190,6 +190,7 @@ issueList.SearchView = Backbone.View.extend({
190
190
initialize : function ( ) {
191
191
issueList . events . on ( "search:update" , _ . bind ( this . updateSearchQuery , this ) ) ;
192
192
issueList . events . on ( "search:clear" , _ . bind ( this . clearSearchBox , this ) ) ;
193
+ issueList . events . on ( "search:current" , _ . bind ( this . currentSearch , this ) ) ;
193
194
} ,
194
195
template : _ . template ( $ ( "#issuelist-search-tmpl" ) . html ( ) ) ,
195
196
render : function ( cb ) {
@@ -207,6 +208,9 @@ issueList.SearchView = Backbone.View.extend({
207
208
updateSearchQuery : function ( data ) {
208
209
this . input . val ( data ) ;
209
210
} ,
211
+ currentSearch : function ( data ) {
212
+ this . _currentSearch = data ;
213
+ } ,
210
214
_isEmpty : true ,
211
215
_currentSearch : null ,
212
216
searchIfNotEmpty : _ . debounce ( function ( e ) {
@@ -218,8 +222,8 @@ issueList.SearchView = Backbone.View.extend({
218
222
// don't search if nothing has changed
219
223
// (or user just added whitespace)
220
224
if ( $ . trim ( searchValue ) !== this . _currentSearch ) {
221
- this . _currentSearch = $ . trim ( searchValue ) ;
222
- this . doSearch ( this . _currentSearch ) ;
225
+ this . currentSearch ( $ . trim ( searchValue ) ) ;
226
+ this . doSearch ( $ . trim ( searchValue ) ) ;
223
227
// clear any filters that have been set.
224
228
issueList . events . trigger ( "filter:clear" , { removeQ : false } ) ;
225
229
}
@@ -228,9 +232,10 @@ issueList.SearchView = Backbone.View.extend({
228
232
// if it's empty and the user searches, show the default results
229
233
// (but only once)
230
234
if ( ! searchValue . length && this . _currentSearch !== "" ) {
231
- this . _currentSearch = "" ;
235
+ this . doSearch ( "" ) ;
236
+ this . currentSearch ( "" ) ;
237
+ issueList . events . trigger ( "filter:clear" , { removeQ : true } ) ;
232
238
this . _isEmpty = true ;
233
- issueList . events . trigger ( "issues:update" ) ;
234
239
}
235
240
} , 350 ) ,
236
241
doSearch : _ . throttle ( function ( value ) {
@@ -336,14 +341,22 @@ issueList.IssueView = Backbone.View.extend(
336
341
// There are some params in the URL
337
342
if ( urlParams . length !== 0 ) {
338
343
queryMatch = urlParams . match ( this . _searchRegex ) ;
344
+ if ( queryMatch ) {
345
+ _ . delay ( function ( ) {
346
+ issueList . events . trigger (
347
+ "search:update" ,
348
+ decodeURIComponent ( queryMatch [ 1 ] )
349
+ ) ;
350
+ issueList . events . trigger (
351
+ "search:current" ,
352
+ decodeURIComponent ( queryMatch [ 1 ] )
353
+ ) ;
354
+ } , 0 ) ;
355
+ }
339
356
if ( ! this . _isLoggedIn && queryMatch ) {
340
357
// We're dealing with an un-authed user, with a q param.
341
358
this . doGitHubSearch ( urlParams ) ;
342
359
this . updateModelParams ( urlParams ) ;
343
- _ . delay ( function ( ) {
344
- // TODO: update search input from query param for authed users.
345
- issueList . events . trigger ( "search:update" , queryMatch [ 1 ] ) ;
346
- } , 0 ) ;
347
360
} else if (
348
361
( category = window . location . search . match ( this . _filterRegex ) )
349
362
) {
@@ -473,13 +486,22 @@ issueList.IssueView = Backbone.View.extend(
473
486
this . issues . setURLState ( "/api/issues/search" , paramsCopy ) ;
474
487
}
475
488
} else if ( _ . contains ( issuesAPICategories , category ) ) {
476
- this . issues . setURLState ( "/api/issues/category/" + category , params ) ;
489
+ this . issues . setURLState (
490
+ "/api/issues/category/" + category ,
491
+ this . removeParamQuery ( params )
492
+ ) ;
477
493
} else {
478
- this . issues . setURLState ( "/api/issues" , params ) ;
494
+ this . issues . setURLState ( "/api/issues" , this . removeParamQuery ( params ) ) ;
479
495
}
480
496
481
497
this . fetchAndRenderIssues ( ) ;
482
498
} ,
499
+ removeParamQuery : function ( params ) {
500
+ if ( params && params . q ) {
501
+ delete params . q ;
502
+ }
503
+ return params ;
504
+ } ,
483
505
addParamsToModel : function ( paramsArray ) {
484
506
// this method just puts the params in the model's params property.
485
507
// paramsArray is an array of param 'key=value' string pairs
@@ -489,7 +511,7 @@ issueList.IssueView = Backbone.View.extend(
489
511
var kvArray = param . split ( "=" ) ;
490
512
var key = kvArray [ 0 ] ;
491
513
var value = kvArray [ 1 ] ;
492
- this . issues . params [ key ] = value ;
514
+ this . issues . params [ key ] = decodeURIComponent ( value ) ;
493
515
} , this )
494
516
) ;
495
517
} ,
0 commit comments