var h = require('hyperscript') var route = require('./views') var avatar = require('./avatar') var compose = require('./compose') var id = require('./keys').id // append global stylesheet to (built using style.js) document.head.appendChild(h('style', require('./style.css.json'))) // #screen is the element everything else gets appended. var screen = h('div#screen') // navbar is appended to the top of the document (outside of screen) var nav = h('div.navbar', h('div.internal', h('li', h('a', {href: '#' + id}, h('span.avatar--small', avatar.image(id)))), h('li', h('a', {href: '#' + id}, avatar.name(id))), h('li', h('a', 'New Post', { onclick: function () { if (document.getElementById('composer')) { return } else { var currentScreen = document.getElementById('screen') var opts = {} opts.type = 'post' var composer = h('div.content#composer', h('div.message', h('div.messageContent', compose(opts)))) if (currentScreen.firstChild.firstChild) { currentScreen.firstChild.insertBefore(composer, currentScreen.firstChild.firstChild) } else { currentScreen.firstChild.appendChild(composer) } } } })), h('li', h('a', {href: '#' }, 'All')), h('li', h('a', {href: '#wall/' + id }, 'Wall')), h('li', h('a', {href: '#key' }, 'Key')) ) ) //append those two elements document.body.appendChild(nav) document.body.appendChild(screen) // call the router route() // this code clears the #screen element when the #hash changes window.onhashchange = function () { var oldscreen = document.getElementById('screen') var newscreen = h('div#screen') oldscreen.parentNode.replaceChild(newscreen, oldscreen) route() }