From edfc1269e35c105571fc28b2a1bb2f648dc5b9a6 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 25 Jan 2022 12:42:51 +0100 Subject: [PATCH] Adding _scripts/js/alpine_search.js --- _scripts/js/alpine_search.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 _scripts/js/alpine_search.js diff --git a/_scripts/js/alpine_search.js b/_scripts/js/alpine_search.js new file mode 100644 index 0000000..0c35f8c --- /dev/null +++ b/_scripts/js/alpine_search.js @@ -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; + } +})