mirror of
https://github.com/toptal/gitignore.io.git
synced 2021-05-12 18:32:24 +03:00
Updated dropdown to filter client side (#327)
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
$(".ignore-search").select2({
|
||||
ajax: {
|
||||
url: "/dropdown/templates.json",
|
||||
data: function(params) {
|
||||
return { term: params.term.toLowerCase() }
|
||||
$.ajax('/dropdown/templates.json').success(function(data) {
|
||||
$(".ignore-search").select2({
|
||||
sorter: function(results) {
|
||||
var query = $('.select2-search__field').val().toLowerCase();
|
||||
return results.sort(function(a, b) {
|
||||
return a.text.toLowerCase().indexOf(query) -
|
||||
b.text.toLowerCase().indexOf(query);
|
||||
});
|
||||
},
|
||||
processResults: function (data) {
|
||||
return { results: data }
|
||||
},
|
||||
cache: true
|
||||
},
|
||||
placeholder: "Search Operating Systems, IDEs, or Programming Languages",
|
||||
minimumInputLength: 1,
|
||||
theme: "bootstrap",
|
||||
multiple: true
|
||||
placeholder: "Search Operating Systems, IDEs, or Programming Languages",
|
||||
minimumInputLength: 1,
|
||||
theme: "bootstrap",
|
||||
multiple: true,
|
||||
data: data
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Delete selecitons by tag instead of individual letter
|
||||
$(".ignore-search").on("select2:unselect", () => {
|
||||
$(".ignore-search").on("select2:open", () => {
|
||||
|
||||
@@ -63,14 +63,14 @@ internal class SiteHandlers {
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Create dropdown template JSON list
|
||||
///
|
||||
/// - Parameter drop: Vapor server side Swift droplet
|
||||
internal func createDropdownTemplates(drop: Droplet) {
|
||||
drop.get("/dropdown/templates.json") { request in
|
||||
guard let queryString = request.query?["term"]?.string?.lowercased() else {
|
||||
return try JSON(node: Node.null)
|
||||
return try JSON(node: self.createSortedDropdownTemplates())
|
||||
}
|
||||
return try JSON(node: self.createSortedDropdownTemplates(query: queryString))
|
||||
}
|
||||
@@ -83,11 +83,14 @@ internal class SiteHandlers {
|
||||
/// - Parameter templates: Template controller template dictionary
|
||||
///
|
||||
/// - Returns: JSON array containing all templates
|
||||
private func createSortedDropdownTemplates(query: String) -> Node {
|
||||
private func createSortedDropdownTemplates(query: String? = nil) -> Node {
|
||||
return Node.array(templates
|
||||
.values
|
||||
.filter({ (templateModel) -> Bool in
|
||||
templateModel.key.contains(query)
|
||||
guard let query = query else {
|
||||
return true
|
||||
}
|
||||
return templateModel.key.contains(query)
|
||||
})
|
||||
.sorted(by: { $0.key < $1.key })
|
||||
.sorted(by: { $0.key.characters.count < $1.key.characters.count })
|
||||
|
||||
Reference in New Issue
Block a user