Skip to content

Commit ac6c7b7

Browse files
committed
Merge pull request #20 from albingeorge/facet_positions
Sort by positions before looping facets
2 parents 4d80d30 + 564d083 commit ac6c7b7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

unbxdSearch.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,25 @@ var unbxdSearchInit = function(jQuery, Handlebars){
16161616
,isSelected = false
16171617
,selectedOnly = [];
16181618

1619-
for(var x in facets){
1619+
var positionExists = false;
1620+
for(var x in facets) {
1621+
if("position" in facets[x]) {
1622+
positionExists = true;
1623+
}
1624+
break;
1625+
}
1626+
var sortable = [];
1627+
for(var facet in facets) {
1628+
sortable.push(positionExists ? ([facet, facets[facet]["position"]]) : [facet]);
1629+
}
1630+
1631+
if(positionExists) {
1632+
sortable.sort(function(a, b) {return a[1] - b[1]});
1633+
}
1634+
for(var newI = 0; newI < sortable.length; newI++) {
1635+
1636+
var x = sortable[newI][0];
1637+
// for(var x in facets) {
16201638
singlefacet = {
16211639
name : self.prepareFacetName(x)
16221640
,facet_name : x

0 commit comments

Comments
 (0)