git ssb

16+

Dominic / patchbay



Tree: 98e148d13e4dcd1d5688c01b61c83da5039c4d4d

Files: 98e148d13e4dcd1d5688c01b61c83da5039c4d4d / modules_basic / search-box.js

1332 bytesRaw
1var h = require('hyperscript')
2var suggest = require('suggest-box')
3var pull = require('pull-stream')
4var plugs = require('../plugs')
5var sbot_query = plugs.first(exports.sbot_query = [])
6var sbot_links2 = plugs.first(exports.sbot_links2 = [])
7var suggest_search = plugs.asyncConcat(exports.suggest_search = [])
8
9var channels = []
10
11
12exports.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