Files: d6467d3650ae378a0c0509253c2ab80b74c89e7b / modules / tabs.js
845 bytesRaw
1 | var Tabs = require('hypertabs') |
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 tabs = Tabs() |
21 | var main = screen('/') |
22 | if(main) tabs.add('main', main, true) |
23 | |
24 | tabs.onclick = function (ev) { |
25 | var link = ancestor(ev.target) |
26 | var path = link.hash.substring(1) |
27 | |
28 | ev.preventDefault() |
29 | ev.stopPropagation() |
30 | |
31 | if(tabs.has(path)) return tabs.select(path) |
32 | |
33 | var el = screen(path) |
34 | if(el) tabs.add(path, el, !ev.ctrlKey) |
35 | |
36 | } |
37 | |
38 | return tabs |
39 | } |
40 | |
41 | exports.message_render = [] |
42 | exports.screen_view = [] |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 |
Built with git-ssb-web