git ssb

16+

Dominic / patchbay



Tree: cb94bd0d83fae7b007a0e33061df18c620bd6cb1

Files: cb94bd0d83fae7b007a0e33061df18c620bd6cb1 / modules / tabs.js

1144 bytesRaw
1var Tabs = require('hypertabs')
2var h = require('hyperscript')
3var pull = require('pull-stream')
4var u = require('../util')
5
6
7function ancestor (el) {
8 if(!el) return
9 if(el.tagName !== 'A') return ancestor(el.parentElement)
10 return el
11}
12
13exports.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
52exports.message_render = []
53exports.screen_view = []
54
55
56
57
58

Built with git-ssb-web