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