Skip to content

Commit ade7558

Browse files
committed
Append if infinite scroll
1 parent 0f5901b commit ade7558

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

unbxdSearch.js

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
2-
var unbxdSearchInit = function(jQuery, Handlebars){
2+
var unbxdSearchInit = function(jQuery, Handlebars){
33
window.Unbxd = window.Unbxd || {};
44

55
// Production steps of ECMA-262, Edition 5, 15.4.4.14
@@ -67,7 +67,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
6767
return -1;
6868
};
6969
}
70-
70+
7171
/**
7272
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
7373
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
@@ -80,7 +80,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
8080
(function () {
8181
'use strict';
8282
var _slice = Array.prototype.slice;
83-
83+
8484
try {
8585
// Can't be used with DOM elements in IE < 9
8686
_slice.call(document.documentElement);
@@ -242,7 +242,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
242242
return A;
243243
};
244244
}
245-
245+
246246
if (!Array.prototype.filter) {
247247
Array.prototype.filter = function(fun/*, thisArg*/) {
248248
'use strict';
@@ -277,7 +277,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
277277
return res;
278278
};
279279
}
280-
280+
281281
// Production steps of ECMA-262, Edition 5, 15.4.4.21
282282
// Reference: http://es5.github.io/#x15.4.4.21
283283
if (!Array.prototype.reduce) {
@@ -633,15 +633,15 @@ var unbxdSearchInit = function(jQuery, Handlebars){
633633
(e.currentTarget === e.target) ? $t : undefined,
634634
field = $selected && $selected.attr('unbxdsortfield'),
635635
value = $selected && $selected.attr('unbxdsortvalue');
636-
636+
637637
if($selected){
638638
self
639639
.resetSort()
640640
.setPage(1);
641-
641+
642642
if(field && value)
643643
self.addSort(field, value);
644-
644+
645645
self.callResults(self.paintOnlyResultSet, true);
646646
}
647647
};
@@ -795,7 +795,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
795795
,checkbox_sel = self.options.facetCheckBoxSelector + "[unbxdParam_facetName='"+ name +"'][unbxdParam_facetValue='" + val + "']";
796796

797797
jQuery(checkbox_sel).removeAttr("checked");
798-
798+
799799
if(typeof self.options.facetOnDeselect == "function"){
800800
self.options.facetOnDeselect(jQuery(checkbox_sel).parents(self.options.facetElementSelector));
801801
}
@@ -857,7 +857,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
857857
}
858858
self.callResults(self.paintOnlyResultSet, true);
859859
}
860-
860+
861861
});
862862
}
863863

@@ -968,16 +968,16 @@ var unbxdSearchInit = function(jQuery, Handlebars){
968968
}
969969
,addRangeFilter : function(field, lb, ub){
970970
if(!(field in this.params.ranges))
971-
this.params.ranges[field] = {};
972-
971+
this.params.ranges[field] = {};
972+
973973
this.params.ranges[field][lb + ' TO ' + ub] = {lb : lb || '*', ub : ub || '*'};
974974

975975
return this;
976976
}
977977
,removeRangeFilter : function(field, lb, ub){
978978
if(!lb && !ub && field in this.params.ranges)
979979
delete this.params.ranges[field];
980-
980+
981981
if(lb && ub && field in this.params.ranges && (lb + ' TO ' + ub in this.params.ranges[field]))
982982
delete this.params.ranges[field][lb + ' TO ' + ub];
983983

@@ -1088,7 +1088,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
10881088
else if(b.length > 0)
10891089
nonhistoryPath += '&filter='+b.join(' OR ');
10901090
}
1091-
1091+
10921092
var a = [];
10931093
var b = [];
10941094
for(var field in this.params.sort){
@@ -1142,7 +1142,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
11421142

11431143
if(this.options.facetMultiSelect)
11441144
nonhistoryPath += '&facet.multiselect=true';
1145-
1145+
11461146
nonhistoryPath += '&indent=off';
11471147

11481148
return {
@@ -1155,26 +1155,26 @@ var unbxdSearchInit = function(jQuery, Handlebars){
11551155
if(this.isLoading){
11561156
this.ajaxCall.abort();
11571157
}
1158-
1158+
11591159
this.isLoading = true;
11601160

11611161
if(this.options.loaderSelector.length > 0)
11621162
jQuery(this.options.loaderSelector).show();
1163-
1163+
11641164
var self = this
11651165
,modifiedCB = callback.bind(self)
11661166
,cb = function(data){
11671167
this.isLoading = false;
11681168
if(this.options.loaderSelector.length > 0)
11691169
jQuery(this.options.loaderSelector).hide();
1170-
1170+
11711171
if("error" in data)
11721172
return false;
11731173

11741174
modifiedCB(data);
11751175
}
11761176
,urlobj = self.url();
1177-
1177+
11781178
if(doPush){
11791179
var finalquery = this.options.noEncoding ? urlobj.query : this.encode( urlobj.query );
11801180
if(this.isHistory){
@@ -1199,7 +1199,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
11991199
jQuery(this.options.searchQueryDisplay).empty();
12001200
if(this.options.deferInitRender.indexOf('search') === -1)
12011201
jQuery(this.options.searchResultContainer).empty();
1202-
1202+
12031203
jQuery(this.options.facetContainerSelector).empty();
12041204

12051205
this.options.selectedFacetHolderSelector && jQuery(this.options.selectedFacetHolderSelector).hide();
@@ -1227,7 +1227,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
12271227
}
12281228
,setDefaultParams: function(params){
12291229
this.options.setDefaultFilters.call(this);
1230-
1230+
12311231
if(Object.keys(this.defaultParams).length === 0)
12321232
this.defaultParams = jQuery.extend(true, {}, this.params);
12331233
}
@@ -1263,7 +1263,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
12631263
if(vals.length > 1){
12641264
if(!(arr[0] in params.ranges))
12651265
params.ranges[arr[0]] = {};
1266-
1266+
12671267
params.ranges[arr[0]][arr[1]] = {lb : isNaN(parseFloat(vals[0])) ? '*' : parseFloat(vals[0]), ub : isNaN(parseFloat(vals[1])) ? '*' : parseFloat(vals[1])};
12681268
} else {
12691269
if(!(arr[0] in params.filters))
@@ -1324,7 +1324,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
13241324
,_internalPaintResultSet: function(obj, facetsAlso){
13251325
if("error" in obj)
13261326
return false;
1327-
1327+
13281328
this.totalNumberOfProducts = 0;
13291329

13301330
this.currentNumberOfProducts = 0;
@@ -1342,18 +1342,18 @@ var unbxdSearchInit = function(jQuery, Handlebars){
13421342
this.params.extra.page = this.params.extra.page - 1;
13431343

13441344
this.params.query = obj.didYouMean[0].suggestion;
1345-
1345+
13461346
if(!this.compiledSpellCheckTemp)
13471347
this.compiledSpellCheckTemp = Handlebars.compile(this.options.spellCheckTemp);
1348-
1348+
13491349
jQuery(this.options.spellCheck).html(this.compiledSpellCheckTemp({suggestion : obj.didYouMean[0].suggestion})).show();
1350-
1350+
13511351
facetsAlso ? this.callResults(this.paintAfterSpellCheck) : this.callResults(this.paintOnlyResultSet) ;
13521352

13531353
}else{
1354-
1354+
13551355
this.params.query = obj.searchMetaData.queryParams.q; //obj.didYouMean[0].suggestion;
1356-
1356+
13571357
if(!this.compiledSpellCheckTemp)
13581358
this.compiledSpellCheckTemp = Handlebars.compile(this.options.spellCheckTemp);
13591359

@@ -1434,13 +1434,18 @@ var unbxdSearchInit = function(jQuery, Handlebars){
14341434
this.compiledResultTemp[val] = Handlebars.compile(this.options.searchResultSetTemp[val]);
14351435
}.bind(this));
14361436
}
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+
14381443
}else{
14391444
if(!this.compiledResultTemp)
14401445
this.compiledResultTemp = Handlebars.compile(this.options.searchResultSetTemp);
14411446

14421447
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));
14441449
}
14451450
}
14461451

@@ -1557,8 +1562,8 @@ var unbxdSearchInit = function(jQuery, Handlebars){
15571562
return obj.page > 0 && obj.page <= this.totalPages;
15581563
}.bind(this))
15591564

1560-
1561-
1565+
1566+
15621567
jQuery(this.options.paginationContainerSelector).html(this.compiledPaginationTemp({
15631568
hasFirst: this.getPage() > 1 ? true : false,
15641569
hasPrev: this.getPage() > 1 ? true : false,
@@ -1590,9 +1595,9 @@ var unbxdSearchInit = function(jQuery, Handlebars){
15901595
}
15911596
));
15921597
}.bind(this), []);
1593-
1598+
15941599
jQuery(this.options.bannerSelector).html(bannersToDraw.join(''));
1595-
1600+
15961601
}
15971602
,paintFacets: function(obj){
15981603
if("error" in obj)
@@ -1637,7 +1642,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
16371642
}
16381643

16391644
if((singlefacet.unordered.length) > 0) textfacets.push(singlefacet);
1640-
1645+
16411646
} else {
16421647
for(var i = 0, len = facets[x]['values']['counts'].length/2; i < len; i++){
16431648
facetValStart = parseFloat(facets[x]['values']['counts'][2 * i]).toString();
@@ -1669,15 +1674,15 @@ var unbxdSearchInit = function(jQuery, Handlebars){
16691674
if (this.options.deferInitRender.indexOf('search') > -1){
16701675
this.options.deferInitRender = [];
16711676
}
1672-
1677+
16731678
if (typeof this.options.onFacetLoad == "function") {
16741679
this.options.onFacetLoad.call(this, obj);
16751680
}
16761681

16771682
if(this.options.getFacetStats.length &&
16781683
typeof this.options.processFacetStats == "function" &&
16791684
"stats" in obj && obj.stats[this.options.getFacetStats] != null){
1680-
1685+
16811686
obj.stats[this.options.getFacetStats].values = {
16821687
min: obj.stats[this.options.getFacetStats].min,
16831688
max: obj.stats[this.options.getFacetStats].max
@@ -1693,7 +1698,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
16931698
obj.stats[this.options.getFacetStats].max
16941699
};
16951700
}
1696-
1701+
16971702
}
16981703

16991704
this.options.processFacetStats.call(this,obj.stats);
@@ -1703,15 +1708,15 @@ var unbxdSearchInit = function(jQuery, Handlebars){
17031708
var selFacetKeysLength = Math.max(Object.keys(this.params.filters).length,
17041709
Object.keys(this.params.ranges).length);
17051710
var selectedFacets = {};
1706-
1711+
17071712
if(selFacetKeysLength){
17081713
selectedFacets.filters = this.params.filters;
17091714
selectedFacets.ranges = {};
17101715

17111716
for (var x in this.params.ranges){
17121717
if(!selectedFacets.ranges.hasOwnProperty(x))
17131718
selectedFacets.ranges[x] = {};
1714-
1719+
17151720
for (var y in this.params.ranges[x]){
17161721
selectedFacets.ranges[x][y] = x;
17171722
}
@@ -1745,7 +1750,7 @@ var unbxdSearchInit = function(jQuery, Handlebars){
17451750
while (e = r.exec(q)) {
17461751
var e1 = e[1].indexOf("[")
17471752
//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)
17491754
,i = e1 != "-1" ? d(e[1].slice(e1+1, e[1].indexOf("]", e1))) : ""
17501755
,v = d(e[2]);
17511756

@@ -1854,11 +1859,11 @@ var unbxdSearchInit = function(jQuery, Handlebars){
18541859
});
18551860
};
18561861

1857-
if(!window.jQuery || !window.Handlebars)
1862+
if(!window.jQuery || !window.Handlebars)
18581863
throw "Please include jQuery & Handlebars libraries before loading unbxdSearch.js";
18591864

18601865
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) )
18621867
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)";
18631868

18641869

0 commit comments

Comments
 (0)