Files: 72483d41ff0fbb76209ef40a0cdcf91409b6db7f / modules / tabs.js
1471 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 | var plugs = require('../plugs') |
14 | var screen_view = plugs.first(exports.screen_view = []) |
15 | |
16 | exports.message_render = [] |
17 | |
18 | exports.app = function () { |
19 | var tabs = Tabs() |
20 | tabs.classList.add('screen') |
21 | |
22 | var saved |
23 | try { saved = JSON.parse(localStorage.openTabs) } |
24 | catch (_) { saved = ['/public', '/private'] } |
25 | |
26 | // var public = screen_view('/public') |
27 | // if(public) tabs.add('public', public, true) |
28 | // |
29 | // var private = screen_view('/private') |
30 | // if(private) tabs.add('private', private, true) |
31 | // |
32 | saved.forEach(function (path) { |
33 | var el = screen_view(path) |
34 | if(el) tabs.add(path, el, true) |
35 | }) |
36 | |
37 | tabs.select(saved[0] || '/public') |
38 | |
39 | tabs.onclick = function (ev) { |
40 | var link = ancestor(ev.target) |
41 | if(!link) return |
42 | var path = link.hash.substring(1) |
43 | |
44 | ev.preventDefault() |
45 | ev.stopPropagation() |
46 | |
47 | //open external links. |
48 | //this ought to be made into something more runcible |
49 | // if(/^https?/.test(link.href)) |
50 | // return require('electron').shell.openExternal(link.href) |
51 | |
52 | if(tabs.has(path)) return tabs.select(path) |
53 | |
54 | var el = screen_view(path) |
55 | if(el) { |
56 | tabs.add(path, el, !ev.ctrlKey) |
57 | localStorage.openTabs = JSON.stringify(tabs.tabs) |
58 | } |
59 | } |
60 | |
61 | return tabs |
62 | } |
63 | |
64 | |
65 |
Built with git-ssb-web