mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 10:03:21 -04:00
Merge pull request #686 from alphagov/no-jump-email
Stop page jumping on first load with a long email
This commit is contained in:
@@ -7,14 +7,6 @@
|
|||||||
|
|
||||||
this.$component = $(component);
|
this.$component = $(component);
|
||||||
|
|
||||||
if (this.$component.height() < this.$component.data('max-height')) return;
|
|
||||||
|
|
||||||
this.$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 = this.$component.find('.toggle')
|
||||||
.on(
|
.on(
|
||||||
"click",
|
"click",
|
||||||
@@ -22,6 +14,10 @@
|
|||||||
)
|
)
|
||||||
.on("keydown", this.filterKeyPresses([32, 13], this.change));
|
.on("keydown", this.filterKeyPresses([32, 13], this.change));
|
||||||
|
|
||||||
|
if (this.getNativeHeight() < this.$component.data('max-height')) {
|
||||||
|
this.change();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.filterKeyPresses = (keys, callback) => function(event) {
|
this.filterKeyPresses = (keys, callback) => function(event) {
|
||||||
@@ -33,9 +29,29 @@
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getNativeHeight = function() {
|
||||||
|
|
||||||
|
var $copy = this.$component.clone().css({
|
||||||
|
'position': 'absolute',
|
||||||
|
'left': '9999px',
|
||||||
|
'width': this.$component.width(),
|
||||||
|
'font-size': this.$component.css('font-size'),
|
||||||
|
'line-height': this.$component.css('line-height')
|
||||||
|
}).addClass('expanded');
|
||||||
|
|
||||||
|
$('body').append($copy);
|
||||||
|
|
||||||
|
var nativeHeight = $copy.height();
|
||||||
|
|
||||||
|
$copy.remove();
|
||||||
|
|
||||||
|
return nativeHeight;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
this.change = () => this.toggleCollapsed() && this.$toggle.remove();
|
this.change = () => this.toggleCollapsed() && this.$toggle.remove();
|
||||||
|
|
||||||
this.toggleCollapsed = () => this.$component.removeClass('collapsed');
|
this.toggleCollapsed = () => this.$component.addClass('expanded');
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,20 +47,24 @@ $button-bottom-border-colour: rgba(0, 0, 0, 0.17);
|
|||||||
|
|
||||||
&-wrapper {
|
&-wrapper {
|
||||||
|
|
||||||
.collapsed & {
|
.js-enabled & {
|
||||||
max-height: 92px;
|
max-height: 92px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.js-enabled .expanded & {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle {
|
.toggle {
|
||||||
|
|
||||||
|
display: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
bottom: -18px;
|
bottom: -18px;
|
||||||
height: 27px;
|
height: 27px;
|
||||||
display: inline-block;
|
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0 0 0 -30px;
|
margin: 0 0 0 -30px;
|
||||||
line-height: 12px;
|
line-height: 12px;
|
||||||
@@ -93,3 +97,11 @@ $button-bottom-border-colour: rgba(0, 0, 0, 0.17);
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.js-enabled .toggle {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.js-enabled .expanded .toggle {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
<div class="email-message-body-wrapper">
|
<div class="email-message-body-wrapper">
|
||||||
{{ body|nl2br }}
|
{{ body|nl2br }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class='toggle' tabindex='0'>...<span class='visually-hidden'>show full email</span></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
Reference in New Issue
Block a user