Skip to content

Commit 1015aaa

Browse files
authored
Merge pull request #845 from BBaoVanC/highlight-linked-comment
[client] Highlight linked comments to identify them
2 parents 8d2f799 + 3929744 commit 1015aaa

6 files changed

Lines changed: 111 additions & 1 deletion

File tree

docs/docs/guides/tips-and-tricks.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ From `blog.mdosch.de <https://blog.mdosch.de/2018/05/20/isso-ip-adressen-woechen
166166
them to to zero.*
167167

168168

169+
Change linked comment highlight color
170+
-------------------------------------
171+
172+
When you click a link that goes to a specific Isso comment (such as ``https://example.com/example-post/#isso-43``),
173+
the comment will be highlighted yellow and then fade out over a few seconds.
174+
175+
Add the following CSS to your site to change that color (replace ``#3f3c1c`` with any color of your choice):
176+
177+
.. code-block:: css
178+
179+
@keyframes isso-target-fade {
180+
0% { background-color: #3f3c1c; }
181+
}
182+
183+
169184
.. attention::
170185

171186
This section of the Isso documentation is incomplete. Please help by expanding it.

isso/css/isso.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@
162162
display: none;
163163
}
164164

165+
/* "target" means the comment that's being linked to, for example:
166+
* https://example.com/blog/example/#isso-15
167+
*/
168+
.isso-target {
169+
animation: isso-target-fade 5s ease-out;
170+
}
171+
@keyframes isso-target-fade {
172+
0% { background-color: #eee5a1; }
173+
/* This color should be changed when used on a dark background,
174+
* maybe #3f3c1c for example
175+
*/
176+
}
177+
165178
.isso-postbox {
166179
max-width: 68em;
167180
margin: 0 auto 2em;

isso/js/embed.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ function init() {
5454
// and the call to fetch those is in fetchComments()
5555
isso_thread.append(heading);
5656
isso_thread.append('<div id="isso-root"></div>');
57+
58+
window.addEventListener('hashchange', function() {
59+
if (!window.location.hash.match("^#isso-[0-9]+$")) {
60+
return;
61+
}
62+
63+
var existingTarget = $(".isso-target");
64+
if (existingTarget != null) {
65+
existingTarget.classList.remove("isso-target");
66+
}
67+
68+
$(window.location.hash + " > .isso-text-wrapper").classList.add("isso-target");
69+
});
5770
}
5871

5972
function fetchComments() {
@@ -105,6 +118,11 @@ function fetchComments() {
105118
if (window.location.hash.length > 0 &&
106119
window.location.hash.match("^#isso-[0-9]+$")) {
107120
$(window.location.hash).scrollIntoView();
121+
122+
// We can't just set the id to `#isso-target` because it's already set to `#isso-[number]`
123+
// So a class `.isso-target` has to be used instead, and then we can manually remove the
124+
// class from the old target comment in the `hashchange` listener.
125+
$(window.location.hash + " > .isso-text-wrapper").classList.add("isso-target");
108126
}
109127
},
110128
function(err) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const ISSO_ENDPOINT = process.env.ISSO_ENDPOINT ?
2+
process.env.ISSO_ENDPOINT : 'http://localhost:8080';
3+
4+
beforeEach(async () => {
5+
await page.goto(
6+
ISSO_ENDPOINT + '/demo#isso-1',
7+
{ waitUntil: 'load' }
8+
)
9+
await expect(page.url()).toBe(ISSO_ENDPOINT + '/demo/index.html#isso-1');
10+
})
11+
12+
test('Linked should be highlighted', async () => {
13+
await expect(page).toFill(
14+
'.isso-textarea',
15+
'A comment with *italics* and [a link](http://link.com)'
16+
);
17+
const [postCreated] = await Promise.all([
18+
page.waitForResponse(async (response) =>
19+
response.url().includes('/new') && response.ok(),
20+
{ timout: 500 }
21+
),
22+
expect(page).toClick('.isso-post-action > input[type=submit]'),
23+
]);
24+
25+
// Refresh page to arm window.location.hash listeners
26+
await page.goto(
27+
ISSO_ENDPOINT + '/demo#isso-1',
28+
{ waitUntil: 'load' }
29+
)
30+
31+
let highlightedComment = await expect(page).toMatchElement('#isso-1');
32+
let wrapper = await expect(highlightedComment).toMatchElement('.isso-target');
33+
34+
// Use another (invalid) hash
35+
await page.goto(
36+
ISSO_ENDPOINT + '/demo#isso-x',
37+
{ waitUntil: 'load' }
38+
)
39+
await expect(page).not.toMatchElement('.isso-target');
40+
41+
// Cleanup
42+
// Need to click once to surface "confirm" and then again to confirm
43+
await expect(page).toClick('#isso-1 > .isso-text-wrapper > .isso-comment-footer > .isso-delete');
44+
await expect(page).toClick('#isso-1 > .isso-text-wrapper > .isso-comment-footer > .isso-delete');
45+
});

isso/js/tests/integration/puppet.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,23 @@ test("should fill Postbox with valid data and receive 201 reply", async () => {
128128
.toEqual(
129129
expect.objectContaining(expected)
130130
);
131+
132+
await page.waitForSelector('#isso-1 > .isso-text-wrapper > .isso-comment-footer > .isso-edit');
133+
134+
// Edit comment
135+
await expect(page).toClick('#isso-1 > .isso-text-wrapper > .isso-comment-footer > .isso-edit');
136+
await expect(page).toFill(
137+
'#isso-1 > .isso-text-wrapper > .isso-textarea-wrapper > .isso-textarea',
138+
'Some other comment. *Emphasis* and [a link](https://example.com/foo).'
139+
);
140+
// .isso-edit is now 'Save' button
141+
await expect(page).toClick('#isso-1 > .isso-text-wrapper > .isso-comment-footer > .isso-edit');
142+
143+
await expect(page).toMatchElement('#isso-1 > .isso-text-wrapper > .isso-text',
144+
{ text: 'Some other comment. Emphasis and a link.' });
145+
146+
// Delete comment again
147+
await expect(page).toClick('#isso-1 > .isso-text-wrapper > .isso-comment-footer > .isso-delete');
148+
// Need to click once to surface "confirm" and then again to confirm
149+
await expect(page).toClick('#isso-1 > .isso-text-wrapper > .isso-comment-footer > .isso-delete');
131150
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"test": "jest --config isso/js/jest.config.js isso/js/tests/",
99
"test-unit": "jest --config isso/js/jest-unit.config.js isso/js/tests/unit/",
10-
"test-integration": "jest --config isso/js/jest-integration.config.js isso/js/tests/integration/",
10+
"test-integration": "jest --runInBand --config isso/js/jest-integration.config.js isso/js/tests/integration/",
1111
"build-dev": "webpack --config isso/js/webpack.config.js --config-name dev",
1212
"watch-dev": "webpack --config isso/js/webpack.config.js --config-name dev --watch",
1313
"build-prod": "webpack --config isso/js/webpack.config.js --merge --config-name dev --config-name prod"

0 commit comments

Comments
 (0)