Files: 08e1fc42a3722f8f133fdcb3a7460462d599f889 / modules / tabs.js
1144 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 | console.log(link) |
33 | |
34 | ev.preventDefault() |
35 | ev.stopPropagation() |
36 | |
37 | //open external links. |
38 | //this ought to be made into something more runcible |
39 | if(/^https?/.test(link.href)) |
40 | return require('shell').openExternal(link.href) |
41 | |
42 | if(tabs.has(path)) return tabs.select(path) |
43 | |
44 | var el = screen(path) |
45 | if(el) tabs.add(path, el, !ev.ctrlKey) |
46 | |
47 | } |
48 | |
49 | return tabs |
50 | } |
51 | |
52 | exports.message_render = [] |
53 | exports.screen_view = [] |
54 | |
55 | |
56 | |
57 | |
58 |
Built with git-ssb-web