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