@@ -481,6 +481,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
481
481
, searchQueryParam :"q"
482
482
, retainbaseParam : false
483
483
, baseParams :[ ]
484
+ , requestHeaders : { }
484
485
} ;
485
486
486
487
jQuery . extend ( Unbxd . setSearch . prototype , {
@@ -1159,7 +1160,8 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1159
1160
1160
1161
modifiedCB ( data ) ;
1161
1162
}
1162
- , urlobj = self . url ( ) ;
1163
+ , urlobj = self . url ( )
1164
+ , requestHeaders = jQuery . extend ( { } , this . getDefaultRequestHeaders ( ) , this . options . requestHeaders ) ;
1163
1165
1164
1166
if ( doPush ) {
1165
1167
var finalquery = this . options . noEncoding ? urlobj . query : this . encode ( urlobj . query ) ;
@@ -1185,6 +1187,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1185
1187
, dataType : "jsonp"
1186
1188
, jsonp : 'json.wrf'
1187
1189
, success : cb . bind ( self )
1190
+ , headers : requestHeaders
1188
1191
} ) ;
1189
1192
}
1190
1193
, reset : function ( ) {
@@ -1929,6 +1932,37 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1929
1932
1930
1933
return undefined ;
1931
1934
}
1935
+ , getDeviceInfo : function ( ) {
1936
+ var smallDeviceMaxWidth = 768 ,
1937
+ mediumDeviceMaxWidth = 992 ;
1938
+ if ( window . outerWidth < smallDeviceMaxWidth ) {
1939
+ return "Mobile" ;
1940
+ } else if ( window . outerWidth < mediumDeviceMaxWidth ) {
1941
+ return "Tablet" ;
1942
+ } else {
1943
+ return "Desktop" ;
1944
+ }
1945
+ }
1946
+ , getUserType : function ( ) {
1947
+ return this . readCookie ( 'visit' ) === "repeat" ? "repeat" : "new" ;
1948
+ }
1949
+ , getUserId : function ( ) {
1950
+ return this . readCookie ( 'userId' ) ;
1951
+ }
1952
+ , getDefaultRequestHeaders : function ( ) {
1953
+ var self = this ,
1954
+ userId = this . getUserId ( ) ,
1955
+ defaultRequestHeaders = {
1956
+ "Device-Type" : self . getDeviceInfo ( )
1957
+ , "Unbxd-Url" : document . URL
1958
+ , "Unbxd-Referrer" : document . referrer
1959
+ , "User-Type" : self . getUserType ( )
1960
+ } ;
1961
+ if ( userId ) {
1962
+ defaultRequestHeaders [ "User-Id" ] = userId ;
1963
+ }
1964
+ return defaultRequestHeaders ;
1965
+ }
1932
1966
} ) ;
1933
1967
} ;
1934
1968
0 commit comments