Files: b3578789d421c2917e2f144cc3f72f86062ae753 / modules_basic / search-box.js
1332 bytesRaw
1 | var h = require('hyperscript') |
2 | var suggest = require('suggest-box') |
3 | var pull = require('pull-stream') |
4 | var plugs = require('../plugs') |
5 | var sbot_query = plugs.first(exports.sbot_query = []) |
6 | var sbot_links2 = plugs.first(exports.sbot_links2 = []) |
7 | var suggest_search = plugs.asyncConcat(exports.suggest_search = []) |
8 | |
9 | var channels = [] |
10 | |
11 | |
12 | exports.search_box = function (go) { |
13 | |
14 | var suggestBox |
15 | var search = h('input.searchprompt', { |
16 | type: 'search', |
17 | placeholder: 'Commands', |
18 | onkeydown: function (ev) { |
19 | switch (ev.keyCode) { |
20 | case 13: // enter |
21 | if (suggestBox && suggestBox.active) { |
22 | suggestBox.complete() |
23 | ev.stopPropagation() |
24 | } |
25 | if (go(search.value.trim(), !ev.ctrlKey)) |
26 | search.blur() |
27 | return |
28 | case 27: // escape |
29 | ev.preventDefault() |
30 | search.blur() |
31 | return |
32 | } |
33 | } |
34 | }) |
35 | |
36 | search.activate = function (sigil, ev) { |
37 | search.focus() |
38 | ev.preventDefault() |
39 | if (search.value[0] === sigil) { |
40 | search.selectionStart = 1 |
41 | search.selectionEnd = search.value.length |
42 | } else { |
43 | search.value = sigil |
44 | } |
45 | } |
46 | |
47 | var suggestions = {} |
48 | |
49 | // delay until the element has a parent |
50 | setTimeout(function () { |
51 | suggestBox = suggest(search, suggest_search, {}) |
52 | }, 10) |
53 | |
54 | return search |
55 | } |
56 |
Built with git-ssb-web