1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Added scroll height and scroll width cap to fix ios safari crash

This commit is contained in:
m-khan-glyptodon 2019-01-07 14:54:00 -08:00
parent 164654143d
commit 8df513fbd3

View File

@ -1581,6 +1581,38 @@ GuacUI.Client.attach = function(guac) {
GuacUI.Client.attachedClient.disconnect();
};
/**
* Calculates maximum possible height that can be scrolled. For additional
* info, visit: https://muffinman.io/ios-safari-get-bounding-client-rect-bug/
*
* @returns {number} A number that represents the max height in pixels.
*/
function getPageMaxHeight() {
return Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.documentElement.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight
) - window.innerHeight; // Subtract viewport height
}
/**
* Calculates maximum possible width that can be scrolled. For additional
* info, visit: https://muffinman.io/ios-safari-get-bounding-client-rect-bug/
*
* @returns {number} A number that represents the max width in pixels.
*/
function getPageMaxWidth() {
return Math.max(
document.body.scrollWidth,
document.body.offsetWidth,
document.documentElement.clientWidth,
document.documentElement.scrollWidth,
document.documentElement.offsetWidth
) - window.innerWidth; // Subtract viewport width
}
/*
* Reflow layout and send size events on resize/scroll
*/
@ -1608,9 +1640,17 @@ GuacUI.Client.attach = function(guac) {
last_scroll_height = document.body.scrollHeight;
last_window_width = window.innerWidth;
last_window_height = window.innerHeight;
// Get appropriate scrolling height (not greater than max value)
var maxHeight = getPageMaxHeight();
var scrollHeight = Math.min(document.body.scrollHeight, maxHeight);
// Get appropriate scrolling width (not greater than max value)
var maxWidth = getPageMaxWidth();
var scrollWidth = Math.min(document.body.scrollWidth, maxWidth);
// Reset scroll and reposition document such that it's on-screen
window.scrollTo(document.body.scrollWidth, document.body.scrollHeight);
window.scrollTo(scrollWidth, scrollHeight);
// Determine height of bottom section (currently only text input)
var bottom = GuacUI.Client.text_input.container;