main/html/app.jsView |
---|
5 | 5 | |
6 | 6 | exports.gives = nest('main.html.app') |
7 | 7 | |
8 | 8 | exports.needs = nest({ |
9 | | - 'main.html': { |
10 | | - error: 'first', |
11 | | - externalConfirm: 'first', |
12 | | - search: 'first' |
| 9 | + main: { |
| 10 | + async: { |
| 11 | + catchLinkClick: 'first' |
| 12 | + }, |
| 13 | + html: { |
| 14 | + error: 'first', |
| 15 | + externalConfirm: 'first', |
| 16 | + search: 'first' |
| 17 | + } |
13 | 18 | }, |
14 | 19 | 'router.html.page': 'first', |
15 | 20 | 'styles.css': 'reduce' |
16 | 21 | }) |
21 | 26 | function app () { |
22 | 27 | const css = values(api.styles.css()).join('\n') |
23 | 28 | insertCss(css) |
24 | 29 | |
25 | | - function onSelect (indexes) { |
26 | | - const ids = indexes.map(index => tabs.get(index).content.id) |
27 | | - if (!search) { console.log('THERE SHOULD BE A SEARCH, GOT', search) ; return } |
28 | | - |
29 | | - if (ids.length > 1) search.input.value = 'split('+ids.join(',')+')' |
30 | | - else search.input.value = ids[0] |
31 | | - } |
32 | 30 | const search = api.main.html.search((path, change) => { |
33 | 31 | if (tabs.has(path)) { |
34 | 32 | tabs.select(path) |
35 | 33 | return true |
38 | 36 | var page = addPage(path, true, false) |
39 | 37 | return change |
40 | 38 | }) |
41 | 39 | const tabs = Tabs(onSelect, { append: h('div.navExtra', [ search ]) }) |
| 40 | + function onSelect (indexes) { |
| 41 | + search.input.value = tabs.get(indexes[0]).content.id |
| 42 | + } |
| 43 | + |
42 | 44 | const App = h('App', tabs) |
43 | 45 | |
44 | 46 | function addPage (link, change, split) { |
45 | 47 | const page = api.router.html.page(link) |
47 | 49 | |
48 | 50 | page.id = page.id || link |
49 | 51 | tabs.add(page, change, split) |
50 | 52 | } |
| 53 | + |
51 | 54 | const initialTabs = ['/public', '/private', '/notifications'] |
52 | 55 | initialTabs.forEach(p => addPage(p)) |
53 | 56 | tabs.select(0) |
54 | 57 | |
55 | | - catchClick(App, (link, { ctrlKey: openBackground, isExternal }) => { |
| 58 | + |
| 59 | + api.main.async.catchLinkClick(App, (link, { ctrlKey: openBackground, isExternal }) => { |
56 | 60 | if (isExternal) api.main.html.externalConfirm(link) |
57 | 61 | |
58 | 62 | if (tabs.has(link)) tabs.select(link) |
59 | 63 | else { |
79 | 83 | const keys = Object.keys(object) |
80 | 84 | return keys.map(k => object[k]) |
81 | 85 | } |
82 | 86 | |
83 | | - |
84 | | -var Url = require('url') |
85 | | - |
86 | | -function catchClick (root, cb) { |
87 | | - root.addEventListener('click', (ev) => { |
88 | | - if (ev.target.tagName === 'INPUT' && ev.target.type === 'file') return |
89 | | - if (ev.defaultPrevented) return |
90 | | - ev.preventDefault() |
91 | | - ev.stopPropagation() |
92 | | - |
93 | | - var anchor = null |
94 | | - for (var n = ev.target; n.parentNode; n = n.parentNode) { |
95 | | - if (n.nodeName === 'A') { |
96 | | - anchor = n |
97 | | - break |
98 | | - } |
99 | | - } |
100 | | - if (!anchor) return true |
101 | | - |
102 | | - var href = anchor.getAttribute('href') |
103 | | - if (!href) return |
104 | | - |
105 | | - var url = Url.parse(href) |
106 | | - var opts = { |
107 | | - altKey: ev.altKey, |
108 | | - ctrlKey: ev.ctrlKey, |
109 | | - metaKey: ev.metaKey, |
110 | | - shiftKey: ev.shiftKey, |
111 | | - isExternal: !!url.host |
112 | | - } |
113 | | - |
114 | | - cb(href, opts) |
115 | | - }) |
116 | | -} |
117 | | - |