git ssb

16+

Dominic / patchbay



Tree: 96d0a60a7b7c41087f0c52c4ed0292f86ba7d4b1

Files: 96d0a60a7b7c41087f0c52c4ed0292f86ba7d4b1 / modules / tabs.js

845 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}
12exports.app = function (_, sbot) {
13
14 function screen (path) {
15 return u.first(exports.screen_view, function (fn) {
16 return fn(path, sbot)
17 })
18 }
19
20 var tabs = Tabs()
21 var main = screen('/')
22 if(main) tabs.add('main', main, true)
23
24 tabs.onclick = function (ev) {
25 var link = ancestor(ev.target)
26 var path = link.hash.substring(1)
27
28 ev.preventDefault()
29 ev.stopPropagation()
30
31 if(tabs.has(path)) return tabs.select(path)
32
33 var el = screen(path)
34 if(el) tabs.add(path, el, !ev.ctrlKey)
35
36 }
37
38 return tabs
39}
40
41exports.message_render = []
42exports.screen_view = []
43
44
45
46
47
48
49
50
51

Built with git-ssb-web