@@ -479,6 +479,8 @@ var unbxdSearchInit = function(jQuery, Handlebars){
479
479
'{{/options}}'
480
480
] . join ( '' )
481
481
, searchQueryParam :"q"
482
+ , retainbaseParam : false
483
+ , baseParams :[ ]
482
484
} ;
483
485
484
486
jQuery . extend ( Unbxd . setSearch . prototype , {
@@ -1008,6 +1010,21 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1008
1010
1009
1011
var url = "" ;
1010
1012
var nonhistoryPath = "" ;
1013
+ // To Retain the fields which are are required from the params of the base URL
1014
+ var cur_url = this . getUrlSubstring ( ) ;
1015
+ var urlParams = this . getQueryParams ( cur_url ) ;
1016
+ var baseParams = { } ;
1017
+ if ( typeof ( this . options . baseParams ) == "object" && this . options . baseParams . length > 0 ) {
1018
+ for ( i in urlParams ) {
1019
+ if ( ( urlParams . hasOwnProperty ( i ) ) && ! ( i in this . params ) ) {
1020
+ for ( param in this . options . baseParams ) {
1021
+ if ( i == this . options . baseParams [ param ] ) {
1022
+ baseParams [ i ] = urlParams [ i ]
1023
+ }
1024
+ }
1025
+ }
1026
+ }
1027
+ }
1011
1028
1012
1029
if ( this . options . type == "search" && this . params [ 'query' ] != undefined ) {
1013
1030
url += '&' + this . options . searchQueryParam + '=' + encodeURIComponent ( this . params . query ) ;
@@ -1117,6 +1134,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1117
1134
url : host_path + "?" + url + nonhistoryPath
1118
1135
, query : url
1119
1136
, host : host_path
1137
+ , baseParams : baseParams
1120
1138
} ;
1121
1139
}
1122
1140
, callResults : function ( callback , doPush ) {
@@ -1146,6 +1164,15 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1146
1164
if ( doPush ) {
1147
1165
var finalquery = this . options . noEncoding ? urlobj . query : this . encode ( urlobj . query ) ;
1148
1166
if ( this . isHistory ) {
1167
+ if ( self . options . retainbaseParam == true ) {
1168
+ var finalBaseParams = '' ;
1169
+ for ( i in urlobj . baseParams ) {
1170
+ if ( urlobj . baseParams . hasOwnProperty ( i ) ) {
1171
+ finalBaseParams += "&" + i + "=" + urlobj . baseParams [ i ] ;
1172
+ }
1173
+ }
1174
+ finalquery += finalquery + this . options . noEncoding ? finalBaseParams : this . encode ( finalBaseParams ) ;
1175
+ }
1149
1176
history . pushState ( this . params , null , location . protocol + "//" + location . host + location . pathname + "?" + finalquery ) ;
1150
1177
} else {
1151
1178
window . location . hash = finalquery ;
0 commit comments