Overview
| Comment: | add like + retweets buttons, keyboard nav |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
b9cf14c14b7e9cacecd6ccdebeca2cd7 |
| User & Date: | lexi on 2021-01-04 15:29:40 |
| Other Links: | manifest | tags |
Context
|
2021-01-04
| ||
| 20:33 | more jabbascript improvements check-in: b6c2a79945 user: lexi tags: trunk | |
| 15:29 | add like + retweets buttons, keyboard nav check-in: b9cf14c14b user: lexi tags: trunk | |
| 06:44 | add likes, retweets, and iterate on a whole bunch of other shit check-in: 78b0198f09 user: lexi tags: trunk | |
Changes
Modified static/live.js from [682908b4c8] to [9100f46c08].
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
..
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
* interactivity beyond what native HTML+CSS can provide. if so,
* we attach the appropriate listeners to them. */
window.addEventListener('load', function() {
/* social media is less fun when you can't just click on a tweet
* to insta-like or -retweet it. this is unfortunately not possible
* (except in various hideously shitty ways) without javascript. */
function mk(elt) { return document.createElement(elt); }
function attachButtons() {
document.querySelectorAll('body:not(.post) main div.post').forEach(function(post){
let url = post.querySelector('.permalink').attributes.getNamedItem('href').value;
function postReq(act,elt) {
fetch(new Request(url, {
method: 'POST',
body: 'act='+act
})).then(function(resp) {
if (resp.ok && resp.status == 200) {
var i = parseInt(elt.innerHTML)
if (isNaN(i)) {i=0}
elt.innerHTML = (i+1).toString()
}
})
}
var stats = post.querySelector('.stats');
if (stats == null) {
/* no stats box; create one */
var n = mk('div');
n.classList.add('stats');
................................................................................
}
return n
} else { return s }
}
var like = ensureElt('like', null);
var rt = ensureElt('rt','.like');
function activate(elt,name) {
elt.addEventListener('click', function(e) { postReq(name,elt) });
elt.style.setProperty('cursor','pointer');
}
activate(like,'like');
activate(rt,'rt');
});
}
/* update hue-picker background when slider is adjusted */
document.querySelectorAll('.color-picker').forEach(function(box) {
let slider = box.querySelector('[data-color-pick]');
box.style.setProperty('--hue', slider.value);
slider.addEventListener('input', function(e) {
|
|
<
|
>
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
* interactivity beyond what native HTML+CSS can provide. if so,
* we attach the appropriate listeners to them. */
window.addEventListener('load', function() {
/* social media is less fun when you can't just click on a tweet
* to insta-like or -retweet it. this is unfortunately not possible
* (except in various hideously shitty ways) without javascript. */
function mk(elt) { return document.createElement(elt); }
function posturl(post) {
return post.querySelector('.permalink').attributes.getNamedItem('href').value;
}
function postReq(url,act,elt) {
fetch(new Request(url, {
method: 'POST',
body: 'act='+act
})).then(function(resp) {
if (resp.ok && resp.status == 200) {
var i = parseInt(elt.innerHTML)
if (isNaN(i)) {i=0}
elt.innerHTML = (i+1).toString()
}
})
}
/* div-based like and rt aren't very keyboard-friendly. add a replacement */
if (document.querySelector('body.timeline, body.profile') != null) {
window.addEventListener('keydown', function(event) {
if (!window._liveTweetMap) { return; }
if (event.isComposing || event.keyCode === 229) { return; } // 🙄
var cururl = window._liveTweetMap.cur;
var nexturl = null;
if (event.key == 'j') { // down
if (cururl == null) {
nexturl = window._liveTweetMap.first
} else {
nexturl = window._liveTweetMap.map.get(cururl).next
}
} else if (event.key == 'k') { // up
if (cururl == null) {
nexturl = window._liveTweetMap.last
} else {
nexturl = window._liveTweetMap.map.get(cururl).prev
}
} else if (cururl != null) {
var post = window._liveTweetMap.map.get(cururl).me
if (event.key == 'f') { // fave
postReq(cururl, 'like', post.querySelector('.stats>.like'))
} else if (event.key == 'r') { // rt
postReq(cururl, 'rt', post.querySelector('.stats>.rt'))
} else if (event.key == 'Enter') { // nav
window.location = cururl;
return;
}
}
if (nexturl != null) {
if (cururl != null) {
var cur = window._liveTweetMap.map.get(cururl);
cur.me.classList.remove('live-selected')
}
var next = window._liveTweetMap.map.get(nexturl);
next.me.classList.add('live-selected')
window._liveTweetMap.cur = nexturl
}
});
}
function attachButtons() {
var last = null;
var newmap = { cur: null, first: null, last: null, map: new Map() }
document.querySelectorAll('body:not(.post) main article.post').forEach(function(post){
let url = posturl(post);
if (last == null) { newmap.first = url; } else {
newmap.map.get(last).next = url
}
newmap.map.set(url, {me: post, prev: last, next: null})
last = url
if (window._liveTweetMap && window._liveTweetMap.cur == url) {
post.classList.add('live-selected');
}
var stats = post.querySelector('.stats');
if (stats == null) {
/* no stats box; create one */
var n = mk('div');
n.classList.add('stats');
................................................................................
}
return n
} else { return s }
}
var like = ensureElt('like', null);
var rt = ensureElt('rt','.like');
function activate(elt,name) {
elt.addEventListener('click', function(e) { postReq(url,name,elt) });
elt.style.setProperty('cursor','pointer');
elt.setAttribute('tabindex','0');
}
activate(like,'like');
activate(rt,'rt');
});
newmap.last = last
if (window._liveTweetMap) {
newmap.cur = window._liveTweetMap.cur // TODO handle vanishments
}
window._liveTweetMap = newmap
}
/* update hue-picker background when slider is adjusted */
document.querySelectorAll('.color-picker').forEach(function(box) {
let slider = box.querySelector('[data-color-pick]');
box.style.setProperty('--hue', slider.value);
slider.addEventListener('input', function(e) {
|
Modified static/style.scss from [322d30fa17] to [ea5ab728f6].
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
border-radius: 2px;
vertical-align: baseline;
box-shadow: 1px 1px 1px black;
}
div.thread {
margin-left: 0.3in;
& + div.post { margin-top: 0.3in; }
}
a[href].username {
>.nym { font-weight: bold; }
color: tone(0%,-0.4);
> span.nym { color: tone(10%) }
> span.handle { color: tone(-5%) }
&:hover {
> span.nym { color: white; }
> span.handle { color: tone(15%) }
}
}
div.post {
@extend %box;
display: grid;
margin: unset;
grid-template-columns: 1in 1fr max-content max-content;
grid-template-rows: min-content max-content;
margin-bottom: 0.1in;
>.avatar {
grid-column: 1/2; grid-row: 1/2;
img { display: block; width: 1in; height: 1in; margin:0; }
background: linear-gradient(to bottom, tone(-53%), tone(-57%));
}
>a[href].username {
display: block;
................................................................................
grid-column: 3/4; grid-row: 2/3;
justify-content: center;
> .like, > .rt {
margin: 0.5em 0.3em;
padding-left: 1.3em;
background-size: 1.1em;
background-repeat: no-repeat;
min-width: 0.3em;
&:empty {
transition: 0.3s;
opacity: 0.1;
&:hover { opacity: 0.6 !important; }
}
}
> .like {
background-image: url(/s/heart.webp);
}
> .rt {
background-image: url(/s/retweet.webp);
}
}
}
div.post:hover div.stats { > .like, > .rt { &:empty {opacity: 0.3;} } }
a[href].rawlink {
@extend %teletype;
}
body.doc main {
@extend %serif;
|
|
|
>
>
|
|
|
|
|
<
<
|
>
>
>
>
>
|
|
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
...
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
border-radius: 2px;
vertical-align: baseline;
box-shadow: 1px 1px 1px black;
}
div.thread {
margin-left: 0.3in;
& + article.post { margin-top: 0.3in; }
}
a[href].username {
>.nym { font-weight: bold; }
color: tone(0%,-0.4);
> span.nym { color: tone(10%) }
> span.handle { color: tone(-5%) }
&:hover {
> span.nym { color: white; }
> span.handle { color: tone(15%) }
}
}
article.post {
@extend %box;
display: grid;
margin: unset;
grid-template-columns: 1in 1fr max-content max-content;
grid-template-rows: min-content max-content;
margin-bottom: 0.1in;
transition: 0.3s;
>.avatar {
grid-column: 1/2; grid-row: 1/2;
img { display: block; width: 1in; height: 1in; margin:0; }
background: linear-gradient(to bottom, tone(-53%), tone(-57%));
}
>a[href].username {
display: block;
................................................................................
grid-column: 3/4; grid-row: 2/3;
justify-content: center;
> .like, > .rt {
margin: 0.5em 0.3em;
padding-left: 1.3em;
background-size: 1.1em;
background-repeat: no-repeat;
pointer-events: all;
min-width: 0.3em;
&:empty {
transition: 0.3s;
opacity: 0.0001; // qutebrowser won't show hints if opacity=0 :(
&:hover, &:focus { opacity: 0.6 !important; }
}
}
> .like { background-image: url(/s/heart.webp); }
> .rt { background-image: url(/s/retweet.webp); }
}
// used for keyboard navigation
&.live-selected {
margin-left: 0.4in;
margin-right: -0.4in;
box-shadow: 0 0 0 1px tone(15%), 0 0 1in tone(5%, -0.5);
}
}
article.post:hover div.stats { > .like, > .rt { &:empty {opacity: 0.3;} } }
a[href].rawlink {
@extend %teletype;
}
body.doc main {
@extend %serif;
|
Modified view/tweet.tpl from [aefe28dd4e] to [80bcf01f8a].
1 2 3 4 5 6 7 8 9 10 |
<div class="post"@attr> <div class="avatar"><img src="@:avatar"></div> <a class="username" href="/@:acctlink">@nym</a> <div class="content"> <div class="subject">@!subject</div> <div class="text">@text</div> </div> @stats <a class="permalink" href="@permalink">@when</a> </div> |
| | | |
1 2 3 4 5 6 7 8 9 10 |
<article class="post"@attr> <div class="avatar"><img src="@:avatar"></div> <a class="username" href="/@:acctlink">@nym</a> <div class="content"> <div class="subject">@!subject</div> <div class="text">@text</div> </div> @stats <a class="permalink" href="@permalink"><time>@when</time></a> </article> |