From f782afef8d6b6f8d4735999c99bdf5af07ef6ebd Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Sat, 14 Jul 2012 00:13:33 +0000 Subject: [PATCH] Add scrollbar width to iframe height, so vertical scrollbar doesn't appear FIXME: add horizontal scrollbar detection so only adding the extra height when it is actually needed. --- apps/routerconsole/jsp/i2ptunnelmgr.jsp | 26 ++++++++++++++++++++++++- apps/routerconsole/jsp/torrents.jsp | 26 ++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/apps/routerconsole/jsp/i2ptunnelmgr.jsp b/apps/routerconsole/jsp/i2ptunnelmgr.jsp index f47f41147b..b459476334 100644 --- a/apps/routerconsole/jsp/i2ptunnelmgr.jsp +++ b/apps/routerconsole/jsp/i2ptunnelmgr.jsp @@ -50,7 +50,31 @@ // but does not include the margin. Therefore, any content within the iframe // should have no margins at the very top or very bottom to avoid a scrollbar. var doc = 'contentDocument' in f? f.contentDocument : f.contentWindow.document; - f.style.height = doc.body.offsetHeight + "px"; + var totalHeight = doc.body.offsetHeight; + + // Detect if horizontal scrollbar is present, and add its width to height if so. + // This prevents a vertical scrollbar appearing when the min-width is passed. + // FIXME: How to detect horizontal scrollbar in iframe? Always apply for now. + if (true) { + // Create the measurement node + var scrollDiv = document.createElement("div"); + scrollDiv.className = "scrollbar-measure"; + scrollDiv.style.width = "100px"; + scrollDiv.style.height = "100px"; + scrollDiv.style.overflow = "scroll"; + scrollDiv.style.position = "absolute"; + scrollDiv.style.top = "-9999px"; + document.body.appendChild(scrollDiv); + + // Get the scrollbar width + var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + totalHeight += scrollbarWidth; + + // Delete the div + document.body.removeChild(scrollDiv); + } + + f.style.height = totalHeight + "px"; } function setupFrame() { f = document.getElementById("i2ptunnelframe"); diff --git a/apps/routerconsole/jsp/torrents.jsp b/apps/routerconsole/jsp/torrents.jsp index e029a48cd6..665f039852 100644 --- a/apps/routerconsole/jsp/torrents.jsp +++ b/apps/routerconsole/jsp/torrents.jsp @@ -32,7 +32,31 @@ // but does not include the margin. Therefore, any content within the iframe // should have no margins at the very top or very bottom to avoid a scrollbar. var doc = 'contentDocument' in f? f.contentDocument : f.contentWindow.document; - f.style.height = doc.body.offsetHeight + "px"; + var totalHeight = doc.body.offsetHeight; + + // Detect if horizontal scrollbar is present, and add its width to height if so. + // This prevents a vertical scrollbar appearing when the min-width is passed. + // FIXME: How to detect horizontal scrollbar in iframe? Always apply for now. + if (true) { + // Create the measurement node + var scrollDiv = document.createElement("div"); + scrollDiv.className = "scrollbar-measure"; + scrollDiv.style.width = "100px"; + scrollDiv.style.height = "100px"; + scrollDiv.style.overflow = "scroll"; + scrollDiv.style.position = "absolute"; + scrollDiv.style.top = "-9999px"; + document.body.appendChild(scrollDiv); + + // Get the scrollbar width + var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + totalHeight += scrollbarWidth; + + // Delete the div + document.body.removeChild(scrollDiv); + } + + f.style.height = totalHeight + "px"; } function setupFrame() { f = document.getElementById("i2psnarkframe"); -- GitLab