git ssb

16+

Dominic / patchbay



Tree: 0812b8ec179f8389faf0bb63ce3c45242f21a07b

Files: 0812b8ec179f8389faf0bb63ce3c45242f21a07b / modules / tabs.js

2179 bytesRaw
1var Tabs = require('hypertabs')
2var h = require('hyperscript')
3var pull = require('pull-stream')
4var u = require('../util')
5
6function ancestor (el) {
7 if(!el) return
8 if(el.tagName !== 'A') return ancestor(el.parentElement)
9 return el
10}
11
12var plugs = require('../plugs')
13var screen_view = plugs.first(exports.screen_view = [])
14
15function openExternal (url) {
16 var _r = require //fool browserify
17
18 //electron@1
19 try {return _r('electron').shell.openExternal(url) }
20 catch (err) { }
21
22 //electron@0
23 try { return _r('shell').openExternal(url) }
24 catch (err) { }
25
26 //browser
27 window.open(url, '_blank')
28}
29
30exports.message_render = []
31
32exports.app = function () {
33 var tabs = Tabs()
34 tabs.classList.add('screen')
35
36 var saved
37 try { saved = JSON.parse(localStorage.openTabs) }
38 catch (_) { saved = ['/public', '/private'] }
39
40 saved.forEach(function (path) {
41 var el = screen_view(path)
42 if(el) tabs.add(path, el, true)
43 })
44
45 tabs.select(saved[0] || '/public')
46
47 tabs.onclick = function (ev) {
48 var link = ancestor(ev.target)
49 if(!link) return
50 var path = link.hash.substring(1)
51
52 ev.preventDefault()
53 ev.stopPropagation()
54
55 //open external links.
56 //this ought to be made into something more runcible
57 if(/^https?/.test(link.href)) return openExternal(link.href)
58
59 if(tabs.has(path)) return tabs.select(path)
60
61 var el = screen_view(path)
62 if(el) {
63 tabs.add(path, el, !ev.ctrlKey)
64 localStorage.openTabs = JSON.stringify(tabs.tabs)
65 }
66 }
67
68 window.addEventListener('keydown', function (ev) {
69 if (ev.target.nodeName === 'INPUT' || ev.target.nodeName === 'TEXTAREA')
70 return
71 switch(ev.keyCode) {
72 // scroll through tabs
73 case 72: // h
74 return tabs.selectRelative(-1)
75 case 76: // l
76 return tabs.selectRelative(1)
77 // scroll through messages
78 case 74: // j
79 return tabs.selectedTab.scroll(1)
80 case 75: // k
81 return tabs.selectedTab.scroll(-1)
82 // close a tab
83 case 88: // x
84 if (tabs.selected !== '/public' && tabs.selected !== '/private')
85 return tabs.remove(tabs.selected)
86 }
87 })
88
89 return tabs
90}
91
92
93
94
95
96
97
98
99
100
101
102
103

Built with git-ssb-web