Files: 134d423c26820a78c6bbfbc506df577e0673b6b2 / modules / tabs.js
784 bytesRaw
1 | var tabs = require('tabs') |
2 | var h = require('hyperscript') |
3 | var pull = require('pull-stream') |
4 | var u = require('../util') |
5 | |
6 | |
7 | function ancestor (el) { |
8 | if(!el) return |
9 | if(el.tagName !== 'A') return ancestor(el.parentElement) |
10 | return el |
11 | } |
12 | exports.app = function (_, sbot) { |
13 | |
14 | function screen (path) { |
15 | return u.first(exports.screen_view, function (fn) { |
16 | return fn(path, sbot) |
17 | }) |
18 | } |
19 | |
20 | var t = tabs() |
21 | var main = screen('/') |
22 | if(main) t.add('main', main, true) |
23 | |
24 | t.onclick = function (ev) { |
25 | var link = ancestor(ev.target) |
26 | EV = ev |
27 | var path = link.hash.substring(1) |
28 | var el = screen(path) |
29 | if(el) t.add(path, el, !ev.ctrlKey) |
30 | |
31 | ev.preventDefault() |
32 | ev.stopPropagation() |
33 | } |
34 | |
35 | return t |
36 | } |
37 | |
38 | exports.message_render = [] |
39 | exports.screen_view = [] |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 |
Built with git-ssb-web