Commit b27c7da727a6667120dbf9108cecbef28faa8060
refactor message layouts datasets out into message decorators
mix irving committed on 4/2/2017, 11:37:29 AMParent: 2f61b5b3290364b166a9c8fe8deaa025e501e8b9
Files changed
main/sync/catch-keyboard-shortcut.js | changed |
message/html/layout/default.js | changed |
message/html/layout/mini.js | changed |
message/html/decorate/data-root.js | added |
message/html/decorate/data-text.js | added |
main/sync/catch-keyboard-shortcut.js | ||
---|---|---|
@@ -91,24 +91,24 @@ | ||
91 | 91 | |
92 | 92 | // this uses a crudely exported nav api |
93 | 93 | const search = document.querySelector('input[type=search]') |
94 | 94 | |
95 | - const { root, key } = msg.dataset | |
96 | - if (!root) return search.go(key) | |
95 | + const { root, id } = msg.dataset | |
96 | + if (!root) return search.go(id) | |
97 | 97 | |
98 | 98 | search.go(root) |
99 | - scrollDownToMessage(key, tabs) | |
99 | + scrollDownToMessage(id, tabs) | |
100 | 100 | } |
101 | 101 | |
102 | -function scrollDownToMessage (key, tabs) { | |
102 | +function scrollDownToMessage (id, tabs) { | |
103 | 103 | tabs.get(tabs.selected[0]).firstChild.scroll('first') |
104 | 104 | locateKey() |
105 | 105 | |
106 | 106 | function locateKey () { |
107 | 107 | const msg = tabs.get(tabs.selected[0]).firstChild.scroll(1) |
108 | 108 | if (msg === undefined) return setTimeout(locateKey, 100) |
109 | 109 | |
110 | - if (msg && msg.dataset && msg.dataset.key === key) return | |
110 | + if (msg && msg.dataset && msg.dataset.id === id) return | |
111 | 111 | |
112 | 112 | locateKey() |
113 | 113 | } |
114 | 114 | } |
message/html/layout/default.js | ||
---|---|---|
@@ -21,16 +21,13 @@ | ||
21 | 21 | if (!(opts.layout === undefined || opts.layout === 'default')) return |
22 | 22 | |
23 | 23 | var rawMessage = Value(null) |
24 | 24 | |
25 | - const attributes = { | |
26 | - tabindex: '0', // needed to be able to navigate and show focus() | |
27 | - 'data-key': msg.key, | |
28 | - 'data-text': msg.value.content.text | |
29 | - } | |
30 | - if (msg.value.content.root) attributes['data-root'] = msg.value.content.root | |
31 | - | |
32 | - return h('Message', { attributes }, [ | |
25 | + return h('Message', { | |
26 | + attributes: { | |
27 | + tabindex: '0' // needed to be able to navigate and show focus() | |
28 | + } | |
29 | + }, [ | |
33 | 30 | h('section.avatar', {}, api.about.html.image(msg.value.author)), |
34 | 31 | h('section.timestamp', {}, api.message.html.timestamp(msg)), |
35 | 32 | h('header.author', {}, api.message.html.author(msg)), |
36 | 33 | h('section.meta', {}, api.message.html.meta(msg, { rawMessage })), |
message/html/layout/mini.js | ||
---|---|---|
@@ -17,10 +17,9 @@ | ||
17 | 17 | if (opts.layout !== 'mini') return |
18 | 18 | |
19 | 19 | var rawMessage = Value(null) |
20 | 20 | |
21 | - return h('div', { | |
22 | - classList: 'Message -mini', | |
21 | + return h('Message -mini', { | |
23 | 22 | attributes: { |
24 | 23 | tabindex: '0' |
25 | 24 | } |
26 | 25 | }, [ |
message/html/decorate/data-root.js | ||
---|---|---|
@@ -1,0 +1,10 @@ | ||
1 | +const nest = require('depnest') | |
2 | + | |
3 | +exports.gives = nest('message.html.decorate') | |
4 | + | |
5 | +exports.create = (api) => { | |
6 | + return nest('message.html.decorate', function (element, { msg }) { | |
7 | + if (msg.value.content.root) element.dataset.root = msg.value.content.root | |
8 | + return element | |
9 | + }) | |
10 | +} |
message/html/decorate/data-text.js | ||
---|---|---|
@@ -1,0 +1,11 @@ | ||
1 | +const nest = require('depnest') | |
2 | + | |
3 | +exports.gives = nest('message.html.decorate') | |
4 | + | |
5 | +exports.create = (api) => { | |
6 | + return nest('message.html.decorate', function (element, { msg }) { | |
7 | + if (msg.value.content.text) element.dataset.text = msg.value.content.text | |
8 | + return element | |
9 | + }) | |
10 | +} | |
11 | + |
Built with git-ssb-web