2016-04-11 15:16:41 +01:00
|
|
|
(function(Modules) {
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Modules.ExpandCollapse = function() {
|
|
|
|
|
|
|
|
|
|
this.start = function(component) {
|
|
|
|
|
|
2016-04-12 20:58:30 +01:00
|
|
|
this.$component = $(component);
|
|
|
|
|
|
|
|
|
|
if (this.$component.height() < this.$component.data('max-height')) return;
|
|
|
|
|
|
|
|
|
|
this.$component
|
2016-04-11 15:16:41 +01:00
|
|
|
.append(`
|
|
|
|
|
<div class='toggle' tabindex='0'>...<span class='visually-hidden'>show full email</span></div>
|
|
|
|
|
`)
|
|
|
|
|
.addClass('collapsed');
|
|
|
|
|
|
2016-04-12 16:21:41 +01:00
|
|
|
this.$toggle = this.$component.find('.toggle')
|
2016-04-11 15:16:41 +01:00
|
|
|
.on(
|
|
|
|
|
"click",
|
|
|
|
|
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();
|
|
|
|
|
|
2016-04-12 16:21:41 +01:00
|
|
|
this.toggleCollapsed = () => this.$component.removeClass('collapsed');
|
2016-04-11 15:16:41 +01:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})(window.GOVUK.Modules);
|