Files: 798d7ea858881504d038705f550581dd75eabaa3 / modules / tabs.js
1114 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 | var plugs = require('../plugs') |
14 | var screen_view = plugs.first(exports.screen_view = []) |
15 | |
16 | exports.message_render = [] |
17 | |
18 | |
19 | exports.app = function (_, sbot) { |
20 | var tabs = Tabs() |
21 | tabs.classList.add('screen') |
22 | |
23 | var main = screen_view('/') |
24 | if(main) tabs.add('main', main, true) |
25 | |
26 | var private = screen_view('/private') |
27 | if(private) tabs.add('private', private, true) |
28 | |
29 | |
30 | tabs.onclick = function (ev) { |
31 | var link = ancestor(ev.target) |
32 | if(!link) return |
33 | var path = link.hash.substring(1) |
34 | |
35 | ev.preventDefault() |
36 | ev.stopPropagation() |
37 | |
38 | //open external links. |
39 | //this ought to be made into something more runcible |
40 | if(/^https?/.test(link.href)) |
41 | return require('shell').openExternal(link.href) |
42 | |
43 | if(tabs.has(path)) return tabs.select(path) |
44 | |
45 | var el = screen_view(path) |
46 | if(el) tabs.add(path, el, !ev.ctrlKey) |
47 | |
48 | } |
49 | |
50 | return tabs |
51 | } |
52 | |
53 | |
54 | |
55 | |
56 |
Built with git-ssb-web