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