Commit Graph

4 Commits

Author SHA1 Message Date
Chris Hill-Scott
66a33e4e47 Stop page jumping on first load with a long email
A long email message needs to be collapsed to only show the first few
lines. The problem is that we were doing this by adding a class with
Javascript, meaning that the email wasn’t being collapsed until the
script in the footer ran.

This caused a jump in the page because the browser was painting the
whole email message, then repainting it once it was collapsed.

This commit takes advantage of the `.js-enabled` class added to the
`<body>` by a script in the `<head>` of GOV.UK template.

This means that the email message is collapsed with CSS before the first
paint of the page, so no jump.

This introduces some complexity in how we determine which emails get the
expander toggle. Because they’re already collapsed we can’t get their
height and work out if they’re long enough to need collapsing.

So we need to take a copy of the message, put it off-screen, expand it,
get its height, then remove it from the DOM. Bit of a faff.

Because of this there’s still a quick flash of the toggle if you see an
email message that’s too short to need collapsing. I think this is the
lesser of two evils—very short email messages will be few and far
between in the real world.
2016-06-15 09:35:55 +01:00
Chris Hill-Scott
bdf746131f Only collapse email templates if they’re long
It’s a bit silly to have email templates expandable if you’re only going
to reveal a couple more lines.

This commit adds a data attribute which specifies how high (in pixels)
the email template can be before it gets truncated. It then changes the
script to only truncate emails which are naturally taller than this
height.

Currently the cut off is at 200px, which is approximately 8 lines of
text: `200px / (font-size: 19px * line-height: 1.31) = 8.03`
2016-04-13 09:50:18 +01:00
Chris Hill-Scott
cffd941742 Fix email expand/collapse not working
The click event was scoped to the wrong element.
2016-04-12 16:21:41 +01:00
Chris Hill-Scott
3a5b76ce2a Truncate previews of email messages to ~3 lines
Emails can get very long.

When you’re trying to do other things on the page this results in a lot
of scrolling.

This commit truncates email messages to about 3 lines, and adds a JS
toggle which reveal the full contents of the email.
2016-04-11 17:24:22 +01:00