Skip to content

Commit

Permalink
(Autocomplétion) Suppression de sortList qui n'est plus nécessaire
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Sep 21, 2024
1 parent 46f28fc commit df1c558
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions assets/js/autocompletion.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
jsonData
.done(function(data) {
self.updateCache(data.results)
self.updateDropdown(self.sortList(data.results, search))
self.updateDropdown(data.results)
})
.fail(function() {
console.error('[Autocompletition] Something went wrong...')
console.error('[Autocompletion] Something went wrong...')
})
this.updateDropdown(this.sortList(this.searchCache(search), search))
this.updateDropdown(this.searchCache(search))
this.showDropdown()
}
}
Expand Down Expand Up @@ -264,32 +264,6 @@
if (!selected) { this.select($list.find('li').first().attr('data-autocomplete-id')) }
},

sortList: function(list, search) {
const bestMatches = []
const otherMatches = []

for (let i = 0; i < list.length; i++) {
if (list[i][this.options.fieldname].indexOf(search) === 0) {
bestMatches.push(list[i])
} else {
otherMatches.push(list[i])
}
}

const sortFn = function(a, b) {
const valueA = a[this.options.fieldname].toLowerCase()
const valueB = b[this.options.fieldname].toLowerCase()
if (valueA < valueB) { return -1 }
if (valueA > valueB) { return 1 }
return 0
}

bestMatches.sort(sortFn.bind(this))
otherMatches.sort(sortFn.bind(this))

return bestMatches.concat(otherMatches)
},

fetchData: function(input, excludeTerms) {
let data = this.options.url.replace('%s', input)
data = data.replace('%e', excludeTerms)
Expand Down

0 comments on commit df1c558

Please sign in to comment.