git ssb

16+

Dominic / patchbay



Commit c7c8921e2864618a237860e416900eed3b9acbe9

extract click catcher

mix irving committed on 3/26/2017, 11:48:38 PM
Parent: 84955f6a151e18bfc8131c8ffbcd043272b13500

Files changed

main/html/app.jschanged
main/async/catch-link-click.jsadded
main/html/app.jsView
@@ -5,12 +5,17 @@
55
66 exports.gives = nest('main.html.app')
77
88 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+ }
1318 },
1419 'router.html.page': 'first',
1520 'styles.css': 'reduce'
1621 })
@@ -21,15 +26,8 @@
2126 function app () {
2227 const css = values(api.styles.css()).join('\n')
2328 insertCss(css)
2429
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- }
3230 const search = api.main.html.search((path, change) => {
3331 if (tabs.has(path)) {
3432 tabs.select(path)
3533 return true
@@ -38,8 +36,12 @@
3836 var page = addPage(path, true, false)
3937 return change
4038 })
4139 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+
4244 const App = h('App', tabs)
4345
4446 function addPage (link, change, split) {
4547 const page = api.router.html.page(link)
@@ -47,13 +49,15 @@
4749
4850 page.id = page.id || link
4951 tabs.add(page, change, split)
5052 }
53+
5154 const initialTabs = ['/public', '/private', '/notifications']
5255 initialTabs.forEach(p => addPage(p))
5356 tabs.select(0)
5457
55- catchClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
58+ // Catch link clicks
59+ api.main.async.catchLinkClick(App, (link, { ctrlKey: openBackground, isExternal }) => {
5660 if (isExternal) api.main.html.externalConfirm(link)
5761
5862 if (tabs.has(link)) tabs.select(link)
5963 else {
@@ -79,39 +83,4 @@
7983 const keys = Object.keys(object)
8084 return keys.map(k => object[k])
8185 }
8286
83-// TODO - replace with extracted module
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 // TODO check this is in the right place
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-
main/async/catch-link-click.jsView
@@ -1,0 +1,42 @@

Built with git-ssb-web