git ssb

16+

Dominic / patchbay



Tree: 79c10b336a5d261d0c19aedbef677d2a5d332ff3

Files: 79c10b336a5d261d0c19aedbef677d2a5d332ff3 / modules / tabs.js

1537 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 return tabs
69}
70
71
72
73
74
75
76
77
78
79
80
81
82

Built with git-ssb-web