1
1
//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
2
- var unbxdSearchInit = function ( jQuery , Handlebars ) {
2
+ var unbxdSearchInit = function ( jQuery , Handlebars ) {
3
3
window . Unbxd = window . Unbxd || { } ;
4
4
5
5
// Production steps of ECMA-262, Edition 5, 15.4.4.14
@@ -67,7 +67,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
67
67
return - 1 ;
68
68
} ;
69
69
}
70
-
70
+
71
71
/**
72
72
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
73
73
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
@@ -80,7 +80,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
80
80
( function ( ) {
81
81
'use strict' ;
82
82
var _slice = Array . prototype . slice ;
83
-
83
+
84
84
try {
85
85
// Can't be used with DOM elements in IE < 9
86
86
_slice . call ( document . documentElement ) ;
@@ -242,7 +242,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
242
242
return A ;
243
243
} ;
244
244
}
245
-
245
+
246
246
if ( ! Array . prototype . filter ) {
247
247
Array . prototype . filter = function ( fun /*, thisArg*/ ) {
248
248
'use strict' ;
@@ -277,7 +277,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
277
277
return res ;
278
278
} ;
279
279
}
280
-
280
+
281
281
// Production steps of ECMA-262, Edition 5, 15.4.4.21
282
282
// Reference: http://es5.github.io/#x15.4.4.21
283
283
if ( ! Array . prototype . reduce ) {
@@ -633,15 +633,15 @@ var unbxdSearchInit = function(jQuery, Handlebars){
633
633
( e . currentTarget === e . target ) ? $t : undefined ,
634
634
field = $selected && $selected . attr ( 'unbxdsortfield' ) ,
635
635
value = $selected && $selected . attr ( 'unbxdsortvalue' ) ;
636
-
636
+
637
637
if ( $selected ) {
638
638
self
639
639
. resetSort ( )
640
640
. setPage ( 1 ) ;
641
-
641
+
642
642
if ( field && value )
643
643
self . addSort ( field , value ) ;
644
-
644
+
645
645
self . callResults ( self . paintOnlyResultSet , true ) ;
646
646
}
647
647
} ;
@@ -795,7 +795,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
795
795
, checkbox_sel = self . options . facetCheckBoxSelector + "[unbxdParam_facetName='" + name + "'][unbxdParam_facetValue='" + val + "']" ;
796
796
797
797
jQuery ( checkbox_sel ) . removeAttr ( "checked" ) ;
798
-
798
+
799
799
if ( typeof self . options . facetOnDeselect == "function" ) {
800
800
self . options . facetOnDeselect ( jQuery ( checkbox_sel ) . parents ( self . options . facetElementSelector ) ) ;
801
801
}
@@ -857,7 +857,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
857
857
}
858
858
self . callResults ( self . paintOnlyResultSet , true ) ;
859
859
}
860
-
860
+
861
861
} ) ;
862
862
}
863
863
@@ -968,16 +968,16 @@ var unbxdSearchInit = function(jQuery, Handlebars){
968
968
}
969
969
, addRangeFilter : function ( field , lb , ub ) {
970
970
if ( ! ( field in this . params . ranges ) )
971
- this . params . ranges [ field ] = { } ;
972
-
971
+ this . params . ranges [ field ] = { } ;
972
+
973
973
this . params . ranges [ field ] [ lb + ' TO ' + ub ] = { lb : lb || '*' , ub : ub || '*' } ;
974
974
975
975
return this ;
976
976
}
977
977
, removeRangeFilter : function ( field , lb , ub ) {
978
978
if ( ! lb && ! ub && field in this . params . ranges )
979
979
delete this . params . ranges [ field ] ;
980
-
980
+
981
981
if ( lb && ub && field in this . params . ranges && ( lb + ' TO ' + ub in this . params . ranges [ field ] ) )
982
982
delete this . params . ranges [ field ] [ lb + ' TO ' + ub ] ;
983
983
@@ -1088,7 +1088,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1088
1088
else if ( b . length > 0 )
1089
1089
nonhistoryPath += '&filter=' + b . join ( ' OR ' ) ;
1090
1090
}
1091
-
1091
+
1092
1092
var a = [ ] ;
1093
1093
var b = [ ] ;
1094
1094
for ( var field in this . params . sort ) {
@@ -1142,7 +1142,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1142
1142
1143
1143
if ( this . options . facetMultiSelect )
1144
1144
nonhistoryPath += '&facet.multiselect=true' ;
1145
-
1145
+
1146
1146
nonhistoryPath += '&indent=off' ;
1147
1147
1148
1148
return {
@@ -1155,26 +1155,26 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1155
1155
if ( this . isLoading ) {
1156
1156
this . ajaxCall . abort ( ) ;
1157
1157
}
1158
-
1158
+
1159
1159
this . isLoading = true ;
1160
1160
1161
1161
if ( this . options . loaderSelector . length > 0 )
1162
1162
jQuery ( this . options . loaderSelector ) . show ( ) ;
1163
-
1163
+
1164
1164
var self = this
1165
1165
, modifiedCB = callback . bind ( self )
1166
1166
, cb = function ( data ) {
1167
1167
this . isLoading = false ;
1168
1168
if ( this . options . loaderSelector . length > 0 )
1169
1169
jQuery ( this . options . loaderSelector ) . hide ( ) ;
1170
-
1170
+
1171
1171
if ( "error" in data )
1172
1172
return false ;
1173
1173
1174
1174
modifiedCB ( data ) ;
1175
1175
}
1176
1176
, urlobj = self . url ( ) ;
1177
-
1177
+
1178
1178
if ( doPush ) {
1179
1179
var finalquery = this . options . noEncoding ? urlobj . query : this . encode ( urlobj . query ) ;
1180
1180
if ( this . isHistory ) {
@@ -1199,7 +1199,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1199
1199
jQuery ( this . options . searchQueryDisplay ) . empty ( ) ;
1200
1200
if ( this . options . deferInitRender . indexOf ( 'search' ) === - 1 )
1201
1201
jQuery ( this . options . searchResultContainer ) . empty ( ) ;
1202
-
1202
+
1203
1203
jQuery ( this . options . facetContainerSelector ) . empty ( ) ;
1204
1204
1205
1205
this . options . selectedFacetHolderSelector && jQuery ( this . options . selectedFacetHolderSelector ) . hide ( ) ;
@@ -1227,7 +1227,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1227
1227
}
1228
1228
, setDefaultParams : function ( params ) {
1229
1229
this . options . setDefaultFilters . call ( this ) ;
1230
-
1230
+
1231
1231
if ( Object . keys ( this . defaultParams ) . length === 0 )
1232
1232
this . defaultParams = jQuery . extend ( true , { } , this . params ) ;
1233
1233
}
@@ -1263,7 +1263,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1263
1263
if ( vals . length > 1 ) {
1264
1264
if ( ! ( arr [ 0 ] in params . ranges ) )
1265
1265
params . ranges [ arr [ 0 ] ] = { } ;
1266
-
1266
+
1267
1267
params . ranges [ arr [ 0 ] ] [ arr [ 1 ] ] = { lb : isNaN ( parseFloat ( vals [ 0 ] ) ) ? '*' : parseFloat ( vals [ 0 ] ) , ub : isNaN ( parseFloat ( vals [ 1 ] ) ) ? '*' : parseFloat ( vals [ 1 ] ) } ;
1268
1268
} else {
1269
1269
if ( ! ( arr [ 0 ] in params . filters ) )
@@ -1324,7 +1324,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1324
1324
, _internalPaintResultSet : function ( obj , facetsAlso ) {
1325
1325
if ( "error" in obj )
1326
1326
return false ;
1327
-
1327
+
1328
1328
this . totalNumberOfProducts = 0 ;
1329
1329
1330
1330
this . currentNumberOfProducts = 0 ;
@@ -1342,18 +1342,18 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1342
1342
this . params . extra . page = this . params . extra . page - 1 ;
1343
1343
1344
1344
this . params . query = obj . didYouMean [ 0 ] . suggestion ;
1345
-
1345
+
1346
1346
if ( ! this . compiledSpellCheckTemp )
1347
1347
this . compiledSpellCheckTemp = Handlebars . compile ( this . options . spellCheckTemp ) ;
1348
-
1348
+
1349
1349
jQuery ( this . options . spellCheck ) . html ( this . compiledSpellCheckTemp ( { suggestion : obj . didYouMean [ 0 ] . suggestion } ) ) . show ( ) ;
1350
-
1350
+
1351
1351
facetsAlso ? this . callResults ( this . paintAfterSpellCheck ) : this . callResults ( this . paintOnlyResultSet ) ;
1352
1352
1353
1353
} else {
1354
-
1354
+
1355
1355
this . params . query = obj . searchMetaData . queryParams . q ; //obj.didYouMean[0].suggestion;
1356
-
1356
+
1357
1357
if ( ! this . compiledSpellCheckTemp )
1358
1358
this . compiledSpellCheckTemp = Handlebars . compile ( this . options . spellCheckTemp ) ;
1359
1359
@@ -1434,13 +1434,18 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1434
1434
this . compiledResultTemp [ val ] = Handlebars . compile ( this . options . searchResultSetTemp [ val ] ) ;
1435
1435
} . bind ( this ) ) ;
1436
1436
}
1437
- jQuery ( this . options . searchResultContainer ) . html ( this . compiledResultTemp [ currentViewType ] ( obj . response ) ) ;
1437
+ if ( this . options . deferInitRender . indexOf ( 'search' ) === - 1 || ! this . isUsingPagination ( ) ) {
1438
+ jQuery ( this . options . searchResultContainer ) . append ( this . compiledResultTemp [ currentViewType ] ( obj . response ) ) ;
1439
+ } else {
1440
+ jQuery ( this . options . searchResultContainer ) . html ( this . compiledResultTemp [ currentViewType ] ( obj . response ) ) ;
1441
+ }
1442
+
1438
1443
} else {
1439
1444
if ( ! this . compiledResultTemp )
1440
1445
this . compiledResultTemp = Handlebars . compile ( this . options . searchResultSetTemp ) ;
1441
1446
1442
1447
if ( this . options . deferInitRender . indexOf ( 'search' ) === - 1 || ! this . isUsingPagination ( ) ) {
1443
- jQuery ( this . options . searchResultContainer ) . append ( this . compiledResultTemp ( obj . response ) ) ;
1448
+ jQuery ( this . options . searchResultContainer ) . append ( this . compiledResultTemp ( obj . response ) ) ;
1444
1449
}
1445
1450
}
1446
1451
@@ -1557,8 +1562,8 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1557
1562
return obj . page > 0 && obj . page <= this . totalPages ;
1558
1563
} . bind ( this ) )
1559
1564
1560
-
1561
-
1565
+
1566
+
1562
1567
jQuery ( this . options . paginationContainerSelector ) . html ( this . compiledPaginationTemp ( {
1563
1568
hasFirst : this . getPage ( ) > 1 ? true : false ,
1564
1569
hasPrev : this . getPage ( ) > 1 ? true : false ,
@@ -1590,9 +1595,9 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1590
1595
}
1591
1596
) ) ;
1592
1597
} . bind ( this ) , [ ] ) ;
1593
-
1598
+
1594
1599
jQuery ( this . options . bannerSelector ) . html ( bannersToDraw . join ( '' ) ) ;
1595
-
1600
+
1596
1601
}
1597
1602
, paintFacets : function ( obj ) {
1598
1603
if ( "error" in obj )
@@ -1637,7 +1642,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1637
1642
}
1638
1643
1639
1644
if ( ( singlefacet . unordered . length ) > 0 ) textfacets . push ( singlefacet ) ;
1640
-
1645
+
1641
1646
} else {
1642
1647
for ( var i = 0 , len = facets [ x ] [ 'values' ] [ 'counts' ] . length / 2 ; i < len ; i ++ ) {
1643
1648
facetValStart = parseFloat ( facets [ x ] [ 'values' ] [ 'counts' ] [ 2 * i ] ) . toString ( ) ;
@@ -1669,15 +1674,15 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1669
1674
if ( this . options . deferInitRender . indexOf ( 'search' ) > - 1 ) {
1670
1675
this . options . deferInitRender = [ ] ;
1671
1676
}
1672
-
1677
+
1673
1678
if ( typeof this . options . onFacetLoad == "function" ) {
1674
1679
this . options . onFacetLoad . call ( this , obj ) ;
1675
1680
}
1676
1681
1677
1682
if ( this . options . getFacetStats . length &&
1678
1683
typeof this . options . processFacetStats == "function" &&
1679
1684
"stats" in obj && obj . stats [ this . options . getFacetStats ] != null ) {
1680
-
1685
+
1681
1686
obj . stats [ this . options . getFacetStats ] . values = {
1682
1687
min : obj . stats [ this . options . getFacetStats ] . min ,
1683
1688
max : obj . stats [ this . options . getFacetStats ] . max
@@ -1693,7 +1698,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1693
1698
obj . stats [ this . options . getFacetStats ] . max
1694
1699
} ;
1695
1700
}
1696
-
1701
+
1697
1702
}
1698
1703
1699
1704
this . options . processFacetStats . call ( this , obj . stats ) ;
@@ -1703,15 +1708,15 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1703
1708
var selFacetKeysLength = Math . max ( Object . keys ( this . params . filters ) . length ,
1704
1709
Object . keys ( this . params . ranges ) . length ) ;
1705
1710
var selectedFacets = { } ;
1706
-
1711
+
1707
1712
if ( selFacetKeysLength ) {
1708
1713
selectedFacets . filters = this . params . filters ;
1709
1714
selectedFacets . ranges = { } ;
1710
1715
1711
1716
for ( var x in this . params . ranges ) {
1712
1717
if ( ! selectedFacets . ranges . hasOwnProperty ( x ) )
1713
1718
selectedFacets . ranges [ x ] = { } ;
1714
-
1719
+
1715
1720
for ( var y in this . params . ranges [ x ] ) {
1716
1721
selectedFacets . ranges [ x ] [ y ] = x ;
1717
1722
}
@@ -1745,7 +1750,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1745
1750
while ( e = r . exec ( q ) ) {
1746
1751
var e1 = e [ 1 ] . indexOf ( "[" )
1747
1752
//first group of regex match
1748
- , k = e1 == "-1" ? e [ 1 ] : e [ 1 ] . slice ( 0 , e1 )
1753
+ , k = e1 == "-1" ? e [ 1 ] : e [ 1 ] . slice ( 0 , e1 )
1749
1754
, i = e1 != "-1" ? d ( e [ 1 ] . slice ( e1 + 1 , e [ 1 ] . indexOf ( "]" , e1 ) ) ) : ""
1750
1755
, v = d ( e [ 2 ] ) ;
1751
1756
@@ -1854,11 +1859,11 @@ var unbxdSearchInit = function(jQuery, Handlebars){
1854
1859
} ) ;
1855
1860
} ;
1856
1861
1857
- if ( ! window . jQuery || ! window . Handlebars )
1862
+ if ( ! window . jQuery || ! window . Handlebars )
1858
1863
throw "Please include jQuery & Handlebars libraries before loading unbxdSearch.js" ;
1859
1864
1860
1865
var arr = jQuery . fn . jquery . split ( '.' ) ;
1861
- if ( arr [ 0 ] < 1 || ( arr [ 0 ] == 1 && arr [ 1 ] < 7 ) )
1866
+ if ( arr [ 0 ] < 1 || ( arr [ 0 ] == 1 && arr [ 1 ] < 7 ) )
1862
1867
throw "jQuery version needs to be greater than 1.7 to use unbxdSearch.js. You can pass custom jQuery & Handlebars by calling unbxdSeachInit(jQuery, Handlebars)" ;
1863
1868
1864
1869
0 commit comments