Files: fda7646d7f7350bad33616d4c754cb86951af6e7 / modules / tabs.js
1162 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 public = screen_view('/public') |
24 | if(public) tabs.add('public', public, true) |
25 | |
26 | var private = screen_view('/private') |
27 | if(private) tabs.add('private', private, true) |
28 | |
29 | tabs.select('public') |
30 | |
31 | |
32 | tabs.onclick = function (ev) { |
33 | var link = ancestor(ev.target) |
34 | if(!link) return |
35 | var path = link.hash.substring(1) |
36 | |
37 | ev.preventDefault() |
38 | ev.stopPropagation() |
39 | |
40 | //open external links. |
41 | //this ought to be made into something more runcible |
42 | if(/^https?/.test(link.href)) |
43 | return require('electron').shell.openExternal(link.href) |
44 | |
45 | if(tabs.has(path)) return tabs.select(path) |
46 | |
47 | var el = screen_view(path) |
48 | if(el) tabs.add(path, el, !ev.ctrlKey) |
49 | |
50 | } |
51 | |
52 | return tabs |
53 | } |
54 | |
55 | |
56 | |
57 | |
58 |
Built with git-ssb-web