git ssb

16+

Dominic / patchbay



Tree: 6879d129070c6362806ed00ce13ba465f6331e7f

Files: 6879d129070c6362806ed00ce13ba465f6331e7f / modules / search-box.js

1286 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 = [])
6
7exports.search_box = function (go) {
8
9 var search = h('input.searchprompt', {
10 type: 'search',
11 onkeydown: function (ev) {
12 switch (ev.keyCode) {
13 case 13: // enter
14 if (go(search.value.trim(), !ev.ctrlKey))
15 search.blur()
16 return
17 case 27: // escape
18 ev.preventDefault()
19 search.blur()
20 return
21 }
22 }
23 })
24
25 search.activate = function (sigil, ev) {
26 search.focus()
27 ev.preventDefault()
28 if (search.value[0] === sigil) {
29 search.selectionStart = 1
30 search.selectionEnd = search.value.length
31 } else {
32 search.value = sigil
33 }
34 }
35
36 /*
37 var suggestions = []
38
39 pull(
40 sbot_query({query: [
41 {$map: ['value', 'content', 'channel']},
42 {$filter: {$prefix: ''}}
43 ]}),
44 pull.unique(),
45 pull.drain(function (chan) {
46 console.log('chan', chan)
47 suggestions.push({title: '#'+chan, value: '#'+chan})
48 })
49 )
50
51 // delay until the element has a parent
52 setTimeout(function () {
53 suggest(search, {'#': suggestions})
54 }, 10)
55 */
56
57 return search
58}
59

Built with git-ssb-web