Files: 3c201fb3cd2ad22f338850c91b72818022074849 / modules_core / app.js
1090 bytesRaw
1 | var h = require('hyperscript') |
2 | var insertCss = require('insert-css') |
3 | |
4 | module.exports = { |
5 | needs: { |
6 | screen_view: 'first', |
7 | styles: 'first' |
8 | }, |
9 | gives: 'app', |
10 | create: function (api) { |
11 | return function () { |
12 | process.nextTick(function () { |
13 | insertCss(api.styles()) |
14 | }) |
15 | |
16 | window.addEventListener('error', window.onError = function (e) { |
17 | document.body.appendChild(h('div.error', |
18 | h('h1', e.message), |
19 | h('big', h('code', e.filename + ':' + e.lineno)), |
20 | h('pre', e.error ? (e.error.stack || e.error.toString()) : e.toString()))) |
21 | }) |
22 | |
23 | function hash() { |
24 | return window.location.hash.substring(1) |
25 | } |
26 | |
27 | var view = api.screen_view(hash() || 'tabs') |
28 | |
29 | var screen = h('div.screen.column', view) |
30 | |
31 | window.onhashchange = function (ev) { |
32 | var _view = view |
33 | view = api.screen_view(hash() || 'tabs') |
34 | |
35 | if(_view) screen.replaceChild(view, _view) |
36 | else document.body.appendChild(view) |
37 | } |
38 | |
39 | document.body.appendChild(screen) |
40 | |
41 | return screen |
42 | } |
43 | } |
44 | } |
45 | |
46 | |
47 |
Built with git-ssb-web