Browse Source

#301: resize only if necessary

pull/2/head 0.9.2.0
gorhill 9 years ago
parent
commit
98c51dbff4
  1. 29
      platform/firefox/vapi-background.js
  2. 6
      src/js/popup.js

29
platform/firefox/vapi-background.js

@ -1970,27 +1970,40 @@ vAPI.toolbarButton = {
}; };
var scrollBarWidth = 0; var scrollBarWidth = 0;
var popupCommittedWidth = 0;
var popupCommittedHeight = 0;
var resizeTimer = null; var resizeTimer = null;
var resizePopupDelayed = function(attempts) { var resizePopupDelayed = function(attempts) {
if ( resizeTimer !== null ) { if ( resizeTimer !== null ) {
return;
return false;
} }
// Sanity check // Sanity check
attempts = (attempts || 0) + 1; attempts = (attempts || 0) + 1;
if ( attempts > 1/*000*/ ) { 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); resizeTimer = vAPI.setTimeout(resizePopup, 10, attempts);
return true;
}; };
var resizePopup = function(attempts) { var resizePopup = function(attempts) {
resizeTimer = null; resizeTimer = null;
var body = iframe.contentDocument.body;
panel.parentNode.style.maxWidth = 'none'; 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 // We set a limit for height
var height = Math.min(body.clientHeight, 600); var height = Math.min(body.clientHeight, 600);
@ -2017,9 +2030,15 @@ vAPI.toolbarButton = {
} }
if ( iframe.clientHeight !== height || panel.clientWidth !== width ) { if ( iframe.clientHeight !== height || panel.clientWidth !== width ) {
resizePopupDelayed(attempts);
if ( resizePopupDelayed(attempts) ) {
return; return;
} }
// resizePopupDelayed won't be called again, so commit
// dimentsions.
}
popupCommittedWidth = body.clientWidth;
popupCommittedHeight = body.clientHeight;
}; };
var onResizeRequested = function() { var onResizeRequested = function() {

6
src/js/popup.js

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

Loading…
Cancel
Save