git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 72b6c6ce34bbd3cdbde8d7ce8efb35bf50fbe7ef

max height of 1500px on posts, add "See more" button when exceeding

Matt McKegg committed on 11/2/2017, 10:49:41 PM
Parent: 42ce7079c3fb1c0fed6c733b7f8cef04102d9267

Files changed

lib/expander-hook.jsadded
locales/en.jsonchanged
plugs/message/html/layout/default.jschanged
styles/dark/message.mcsschanged
styles/light/message.mcsschanged
lib/expander-hook.jsView
@@ -1,0 +1,26 @@
1+module.exports = ExpanderHook
2+
3+function ExpanderHook (needsExpand) {
4+ return expander.bind(null, needsExpand)
5+}
6+
7+function expander (needsExpand, element) {
8+ var handler = { handleEvent, needsExpand, element }
9+ handleEvent.bind(handler)
10+
11+ if (element.querySelector('img')) {
12+ // just in case images are still loading
13+ setTimeout(handleEvent.bind(handler), 200)
14+ element.addEventListener('mouseover', handler)
15+ return element.removeEventListener.bind(element, 'mouseover', handler)
16+ }
17+}
18+
19+function handleEvent (ev) {
20+ var { needsExpand, element } = this
21+ if (!needsExpand()) {
22+ if (element.firstElementChild.clientHeight > element.clientHeight) {
23+ needsExpand.set(true)
24+ }
25+ }
26+}
locales/en.jsonView
@@ -179,6 +179,8 @@
179179 "one": "You follow someone that follows this person.",
180180 "other": "You follow %s people that follow this person."
181181 },
182182 "Followed by": "Followed by",
183- "pt-BR": "Brazillian Portuguese"
184-}
183+ "pt-BR": "Brazillian Portuguese",
184+ "See less": "See less",
185+ "See more": "See more"
186+}
plugs/message/html/layout/default.jsView
@@ -1,7 +1,8 @@
1-const { h, computed } = require('mutant')
1+const { h, computed, Value, when } = require('mutant')
22 var nest = require('depnest')
33 var ref = require('ssb-ref')
4+var ExpanderHook = require('../../../../lib/expander-hook')
45
56 exports.needs = nest({
67 'profile.html.person': 'first',
78 'message.obs.backlinks': 'first',
@@ -29,8 +30,11 @@
2930
3031 var classList = ['Message']
3132 var replyInfo = null
3233
34+ var needsExpand = Value(false)
35+ var expanded = Value(false)
36+
3337 if (msg.value.content.root) {
3438 classList.push('-reply')
3539 var branch = msg.value.content.branch
3640 if (branch) {
@@ -48,13 +52,24 @@
4852
4953 return h('div', {
5054 classList
5155 }, [
52- messageHeader(msg, { replyInfo, priority }),
53- h('section', [content]),
56+ messageHeader(msg, { replyInfo, priority, needsExpand, expanded }),
57+ h('section', {
58+ classList: [ when(expanded, '-expanded') ],
59+ hooks: [ ExpanderHook(needsExpand) ]
60+ }, [content]),
5461 computed(msg.key, (key) => {
5562 if (ref.isMsg(key)) {
5663 return h('footer', [
64+ when(needsExpand, h('div.expander', {
65+ classList: when(expanded, null, '-truncated')
66+ }, [
67+ h('a', {
68+ href: '#',
69+ 'ev-click': toggle(expanded)
70+ }, when(expanded, i18n('See less'), i18n('See more')))
71+ ])),
5772 h('div.actions', [
5873 api.message.html.action(msg)
5974 ])
6075 ])
@@ -100,4 +115,15 @@
100115 } else {
101116 return array
102117 }
103118 }
119+
120+function toggle (param) {
121+ return {
122+ handleEvent: handleToggle,
123+ param
124+ }
125+}
126+
127+function handleToggle (ev) {
128+ this.param.set(!this.param())
129+}
styles/dark/message.mcssView
@@ -251,8 +251,15 @@
251251
252252 section {
253253 margin: 0
254254 padding: 0 20px
255+ max-height: 1500px
256+ overflow: hidden
257+
258+ -expanded {
259+ max-height: none
260+ }
261+
255262 (img) {
256263 max-width: 100%
257264 }
258265 }
@@ -274,8 +281,22 @@
274281 footer {
275282 margin: 5px 0 20px;
276283 padding: 0 20px
277284
285+ div.expander {
286+ text-align: center;
287+ background-color: #383736;
288+
289+ -truncated {
290+ padding-top: 50px;
291+ margin-top: -50px;
292+ -webkit-mask-image: linear-gradient(0deg, rgba(0,0,0,1) 50%, rgba(0,0,0,0));
293+ a {
294+ :before { content: '▼ '; font-size: 80% }
295+ }
296+ }
297+ }
298+
278299 div.actions {
279300 a.like {
280301 :before {
281302 content: "❤ "
styles/light/message.mcssView
@@ -203,11 +203,18 @@
203203
204204 section {
205205 margin: 0
206206 padding: 0 20px
207+ max-height: 1500vh
208+ overflow: hidden
209+
207210 (img) {
208211 max-width: 100%
209212 }
213+
214+ -expanded {
215+ max-height: none
216+ }
210217 }
211218
212219 a.backlink {
213220 display: block;
@@ -227,8 +234,22 @@
227234 footer {
228235 margin: 5px 0 20px;
229236 padding: 0 20px
230237
238+ div.expander {
239+ text-align: center;
240+ background-color: white;
241+
242+ -truncated {
243+ padding-top: 50px;
244+ margin-top: -50px;
245+ -webkit-mask-image: linear-gradient(0deg, rgba(0,0,0,1) 50%, rgba(0,0,0,0));
246+ a {
247+ :before { content: '▼ '; font-size: 80% }
248+ }
249+ }
250+ }
251+
231252 div.actions {
232253 a {
233254 opacity: 0.4
234255 transition: opacity 0.2s

Built with git-ssb-web