Files: 231a81f9e0adf80fa3566be93221cf1f5158fcb6 / index.js
1759 bytesRaw
1 | var h = require('hyperscript') |
2 | var route = require('./views') |
3 | var avatar = require('./avatar') |
4 | var compose = require('./compose') |
5 | var id = require('./keys').id |
6 | |
7 | // append global stylesheet to <head> (built using style.js) |
8 | document.head.appendChild(h('style', require('./style.css.json'))) |
9 | |
10 | // #screen is the element everything else gets appended. |
11 | var screen = h('div#screen') |
12 | |
13 | // navbar is appended to the top of the document (outside of screen) |
14 | var nav = h('div.navbar', |
15 | h('div.internal', |
16 | h('li', h('a', {href: '#' + id}, h('span.avatar--small', avatar.image(id)))), |
17 | h('li', h('a', {href: '#' + id}, avatar.name(id))), |
18 | h('li', h('a', 'New Post', { |
19 | onclick: function () { |
20 | if (document.getElementById('composer')) { return } |
21 | else { |
22 | var currentScreen = document.getElementById('screen') |
23 | var opts = {} |
24 | opts.type = 'post' |
25 | var composer = h('div.content#composer', h('div.message', compose(opts))) |
26 | if (currentScreen.firstChild.firstChild) { |
27 | currentScreen.firstChild.insertBefore(composer, currentScreen.firstChild.firstChild) |
28 | } else { |
29 | currentScreen.firstChild.appendChild(composer) |
30 | } |
31 | } |
32 | } |
33 | })), |
34 | h('li', h('a', {href: '#' }, 'All')), |
35 | h('li', h('a', {href: '#wall/' + id }, 'Wall')), |
36 | h('li', h('a', {href: '#key' }, 'Key')) |
37 | ) |
38 | ) |
39 | |
40 | //append those two elements |
41 | document.body.appendChild(nav) |
42 | document.body.appendChild(screen) |
43 | |
44 | // call the router |
45 | route() |
46 | |
47 | // this code clears the #screen element when the #hash changes |
48 | window.onhashchange = function () { |
49 | var oldscreen = document.getElementById('screen') |
50 | var newscreen = h('div#screen') |
51 | oldscreen.parentNode.replaceChild(newscreen, oldscreen) |
52 | route() |
53 | } |
54 | |
55 |
Built with git-ssb-web