1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-01 18:10:17 +12:00

#301: resize only if necessary

This commit is contained in:
gorhill 2015-07-28 15:00:31 -04:00
parent a8ceaa5dfb
commit 98c51dbff4
2 changed files with 30 additions and 7 deletions

View file

@ -1970,27 +1970,40 @@ vAPI.toolbarButton = {
};
var scrollBarWidth = 0;
var popupCommittedWidth = 0;
var popupCommittedHeight = 0;
var resizeTimer = null;
var resizePopupDelayed = function(attempts) {
if ( resizeTimer !== null ) {
return;
return false;
}
// Sanity check
attempts = (attempts || 0) + 1;
if ( attempts > 1/*000*/ ) {
console.error('uMatrix> resizePopupDelayed: giving up after too many attempts');
return;
//console.error('uMatrix> resizePopupDelayed: giving up after too many attempts');
return false;
}
resizeTimer = vAPI.setTimeout(resizePopup, 10, attempts);
return true;
};
var resizePopup = function(attempts) {
resizeTimer = null;
var body = iframe.contentDocument.body;
panel.parentNode.style.maxWidth = 'none';
var body = iframe.contentDocument.body;
// https://github.com/gorhill/uMatrix/issues/301
// Don't resize if committed size did not change.
if (
popupCommittedWidth === body.clientWidth &&
popupCommittedHeight === body.clientHeight
) {
return;
}
// We set a limit for height
var height = Math.min(body.clientHeight, 600);
@ -2017,9 +2030,15 @@ vAPI.toolbarButton = {
}
if ( iframe.clientHeight !== height || panel.clientWidth !== width ) {
resizePopupDelayed(attempts);
return;
if ( resizePopupDelayed(attempts) ) {
return;
}
// resizePopupDelayed won't be called again, so commit
// dimentsions.
}
popupCommittedWidth = body.clientWidth;
popupCommittedHeight = body.clientHeight;
};
var onResizeRequested = function() {

View file

@ -369,6 +369,7 @@ function updateMatrixColors() {
cell = cells.nodeAt(i);
cell.className = 'matCell ' + getCellClass(cell.hostname, cell.reqType);
}
resizePopup();
}
/******************************************************************************/
@ -476,7 +477,6 @@ var endMatrixUpdate = function() {
updateMatrixBehavior();
matrixList.css('display', '');
matrixList.appendTo('.paneContent');
resizePopup();
};
var createMatrixGroup = function() {
@ -970,6 +970,7 @@ var makeMenu = function() {
initScopeCell();
updateMatrixButtons();
resizePopup();
};
/******************************************************************************/
@ -1287,6 +1288,9 @@ var matrixSnapshotPoller = (function() {
if ( timer !== null ) {
return;
}
if ( document.defaultView === null ) {
return;
}
timer = vAPI.setTimeout(poll, 1414);
};