mirror of
https://github.com/eosswedenorg/apt
synced 2026-06-16 04:34:56 +02:00
Adding _scripts/js/alpine_search.js
This commit is contained in:
parent
5d9ed07d37
commit
edfc1269e3
1 changed files with 36 additions and 0 deletions
36
_scripts/js/alpine_search.js
Normal file
36
_scripts/js/alpine_search.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
import pkg_idx from './pkg_idx'
|
||||
|
||||
// Alpine search component
|
||||
export default () => ({
|
||||
show: false,
|
||||
query: "",
|
||||
getResults() {
|
||||
if (this.query.length < 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var results = pkg_idx.search(this.query).slice(0, 10);
|
||||
|
||||
var list = results.map(function (item) {
|
||||
return package_data.filter(function (v, i, arr) {
|
||||
return v.id == item.ref;
|
||||
})[0];
|
||||
});
|
||||
|
||||
this.open();
|
||||
return list;
|
||||
},
|
||||
toggle() {
|
||||
this.show = ! this.show;
|
||||
},
|
||||
open() {
|
||||
this.show = true;
|
||||
},
|
||||
close() {
|
||||
this.show = false;
|
||||
},
|
||||
isOpen() {
|
||||
return this.show;
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue