git ssb

16+

Dominic / patchbay



Tree: f615fd0a3c6e9a30d42fa265b44af3997347103a

Files: f615fd0a3c6e9a30d42fa265b44af3997347103a / modules_core / search-box.js

1273 bytesRaw
1'use strict'
2const h = require('../h')
3const fs = require('fs')
4
5
6exports.needs = {
7 suggest_search: 'map', //REWRITE
8 build_suggest_box: 'first'
9}
10
11exports.gives = {
12 search_box: true,
13 mcss: true
14}
15
16exports.create = function (api) {
17
18 return {
19 search_box,
20 mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
21 }
22
23 function search_box (go) {
24 var search = h('Search', [
25 h('input', {
26 type: 'search',
27 placeholder: 'Commands',
28 'ev-click': ev => {
29 switch (ev.keyCode) {
30 case 13: // enter
31 ev.stopPropagation()
32 suggestBox.complete()
33
34 if (go(search.value.trim(), !ev.ctrlKey))
35 search.blur()
36 return
37 case 27: // escape
38 ev.preventDefault()
39 search.blur()
40 return
41 }
42 }
43 })
44 ])
45
46 search.activate = (sigil, ev) => {
47 search.focus()
48 ev.preventDefault()
49 if (search.value[0] === sigil) {
50 search.selectionStart = 1
51 search.selectionEnd = search.value.length
52 } else {
53 search.value = sigil
54 }
55 }
56
57 var suggestBox = api.build_suggest_box(search, api.suggest_search)
58
59 return search
60 }
61
62}
63
64

Built with git-ssb-web