Files: fe2d16aa6ea53293f876bfca14020babfd4236ab / modules / app.js
1641 bytesRaw
1 | var h = require('hyperscript') |
2 | var id = require('../keys').id |
3 | |
4 | module.exports = { |
5 | needs: { |
6 | screen_view: 'first', |
7 | avatar_name: 'first', |
8 | avatar_image: 'first' |
9 | }, |
10 | gives: 'app', |
11 | |
12 | create: function (api) { |
13 | return function () { |
14 | // document.head.appendChild(h('style', require('../style.css.json'))) |
15 | |
16 | function hash() { |
17 | return window.location.hash.substring(1) |
18 | } |
19 | |
20 | var view = api.screen_view(hash() || 'Public') |
21 | |
22 | |
23 | var screen = h('div.screen.column', view) |
24 | |
25 | window.onhashchange = function (ev) { |
26 | var _view = view |
27 | view = api.screen_view(hash() || 'Public') |
28 | if(_view) screen.replaceChild(view, _view) |
29 | else document.body.appendChild(view) |
30 | } |
31 | |
32 | document.body.appendChild(screen) |
33 | |
34 | var search = h('input.search', {placeholder: 'Search'}) |
35 | |
36 | document.body.appendChild(h('div.navbar', |
37 | h('div.internal', |
38 | h('li', h('a', {href: '#' + id}, api.avatar_image(id, 'tiny'))), |
39 | h('li', h('a', {href: '#' + id}, api.avatar_name(id))), |
40 | h('li', h('a', {href: '#'}, 'Public')), |
41 | h('li', h('a', {href: '#Direct'}, 'Direct')), |
42 | h('li', h('a', {href: '#Mentions'}, 'Mentions')), |
43 | h('li', h('a', {href: '#Theme'}, 'Theme')), |
44 | h('li', h('a', {href: '#Key'}, 'Key')), |
45 | h('form.search', { onsubmit: function (e) { |
46 | //if (err) throw err |
47 | window.location.hash = '?' + search.value |
48 | e.preventDefault() |
49 | }}, |
50 | search, |
51 | h('button.btn.btn-primary.btn-search', 'Search') |
52 | ) |
53 | ) |
54 | )) |
55 | } |
56 | } |
57 | } |
58 |
Built with git-ssb-web