Skip to content

Commit 085824c

Browse files
author
praveen
committed
Merge pull request #23 from floydpraveen/search-query-param-name
take searchQueryParam from config options for read/update of browser url
2 parents f6d4b6f + d971dd5 commit 085824c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Consider a normal search page with basic layout as shown in the figure below and
129129
,bannerSelector: ".banner"
130130
,bannerTemp: "<a href='{{landingUrl}}'><img src='{{imageUrl}}'/></a>"
131131
,fields : ['image_url','title','brand','price','uniqueId']
132+
,searchQueryParam:"q"
132133
});
133134
```
134135

@@ -701,6 +702,7 @@ JSON used for this template:
701702
,fields : ['image_url','title','brand','price','uniqueId']
702703
...
703704
```
705+
- **searchQueryParam** : searh query param name to be shown in browser url, default is "q"
704706
- **deferInitRender** : This is an array of library features that need to be disabled on initial load.
705707
```javascript
706708
...

unbxdSearch.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//uglifyjs unbxdSearch.js -o unbxdSearch.min.js && gzip -c unbxdSearch.min.js > unbxdSearch.min.js.gz && aws s3 cp unbxdSearch.min.js.gz s3://unbxd/unbxdSearch.js --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-encoding gzip --cache-control max-age=3600
22
var unbxdSearchInit = function(jQuery, Handlebars){
33
window.Unbxd = window.Unbxd || {};
4+
Unbxd.jsSdkVersion = "1.0.1";
45

56
// Production steps of ECMA-262, Edition 5, 15.4.4.14
67
// Reference: http://es5.github.io/#x15.4.4.14
@@ -477,6 +478,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
477478
'</li>',
478479
'{{/options}}'
479480
].join('')
481+
,searchQueryParam:"q"
480482
};
481483

482484
jQuery.extend(Unbxd.setSearch.prototype,{
@@ -1045,7 +1047,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
10451047
var nonhistoryPath = "";
10461048

10471049
if(this.options.type == "search" && this.params['query'] != undefined){
1048-
url += '&q=' + encodeURIComponent(this.params.query);
1050+
url += '&'+ this.options.searchQueryParam +'='+ encodeURIComponent(this.params.query);
10491051
}else if(this.options.type == "browse" && this.params['categoryId'] != undefined){
10501052
url += '&category-id=' + encodeURIComponent(this.params.categoryId);
10511053
}
@@ -1189,7 +1191,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
11891191
}
11901192

11911193
this.ajaxCall = jQuery.ajax({
1192-
url: urlobj.url
1194+
url: urlobj.url.replace(this.options.searchQueryParam+"=", "q=")
11931195
,dataType: "jsonp"
11941196
,jsonp: 'json.wrf'
11951197
,success: cb.bind(self)
@@ -1300,8 +1302,8 @@ var unbxdSearchInit = function(jQuery, Handlebars){
13001302
params.extra.rows = this.options.pageSize;
13011303

13021304
//lets get query
1303-
if("q" in obj)
1304-
params.query = obj.q;
1305+
if(this.options.searchQueryParam in obj)
1306+
params.query = obj[this.options.searchQueryParam];
13051307

13061308
//lets get category-id
13071309
if("category-id" in obj)

0 commit comments

Comments
 (0)