less glitchy autoresize of the popup while in use

pull/2/head
gorhill 9 years ago
parent cbc0337110
commit 303291fe09

@ -1578,6 +1578,7 @@ vAPI.toolbarButton.onBeforeCreated = function(doc) {
.appendChild(panel) .appendChild(panel)
.appendChild(iframe); .appendChild(iframe);
var scrollBarWidth = 0;
var updateTimer = null; var updateTimer = null;
var delayedResize = function() { var delayedResize = function() {
if ( updateTimer ) { if ( updateTimer ) {
@ -1591,18 +1592,22 @@ vAPI.toolbarButton.onBeforeCreated = function(doc) {
panel.parentNode.style.maxWidth = 'none'; panel.parentNode.style.maxWidth = 'none';
// We set a limit for height // We set a limit for height
var height = Math.min(body.clientHeight, 600); var height = Math.min(body.clientHeight, 600);
var width = body.clientWidth;
// https://github.com/chrisaljoudi/uBlock/issues/730 // https://github.com/chrisaljoudi/uBlock/issues/730
// Voodoo programming: this recipe works // Voodoo programming: this recipe works
panel.style.setProperty('height', height + 'px'); panel.style.setProperty('height', height + 'px');
iframe.style.setProperty('height', height + 'px'); iframe.style.setProperty('height', height + 'px');
// Adjust width for presence/absence of vertical scroll bar which may // Adjust width for presence/absence of vertical scroll bar which may
// have appeared as a result of last operation. // have appeared as a result of last operation.
var contentWindow = iframe.contentWindow;
var width = body.clientWidth;
if ( contentWindow.scrollMaxY !== 0 ) {
width += scrollBarWidth;
}
panel.style.setProperty('width', width + 'px'); panel.style.setProperty('width', width + 'px');
var cw = panel.clientWidth; // scrollMaxX should always be zero once we know the scrollbar width
var dw = iframe.contentWindow.document.documentElement.clientWidth; if ( contentWindow.scrollMaxX !== 0 ) {
if ( cw !== dw ) { scrollBarWidth = contentWindow.scrollMaxX;
width = 2 * cw - dw; width += scrollBarWidth;
panel.style.setProperty('width', width + 'px'); panel.style.setProperty('width', width + 'px');
} }
if ( iframe.clientHeight !== height || panel.clientWidth !== width ) { if ( iframe.clientHeight !== height || panel.clientWidth !== width ) {

Loading…
Cancel
Save