Files
notifications-admin/app/assets/javascripts/expandCollapse.js
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

42 lines
915 B
JavaScript

(function(Modules) {
"use strict";
Modules.ExpandCollapse = function() {
this.start = function(component) {
this.$component = $(component)
.append(`
<div class='toggle' tabindex='0'>...<span class='visually-hidden'>show full email</span></div>
`)
.addClass('collapsed');
this.$toggle = this.$component.find('.toggle');
this.$toggle
.on(
"click",
".toggle",
this.change
)
.on("keydown", this.filterKeyPresses([32, 13], this.change));
};
this.filterKeyPresses = (keys, callback) => function(event) {
if (keys.indexOf(event.keyCode)) return;
event.preventDefault();
callback();
};
this.change = () => this.toggleCollapsed() && this.$toggle.remove();
this.toggleCollapsed = () => this.$component.toggleClass('collapsed');
};
})(window.GOVUK.Modules);