mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
this fixes sticky popup when legacy toolbar button + multiple windows
This commit is contained in:
parent
d66b0de338
commit
be7db835a8
@ -2639,56 +2639,38 @@ vAPI.toolbarButton = {
|
|||||||
var sss = null;
|
var sss = null;
|
||||||
var styleSheetUri = null;
|
var styleSheetUri = null;
|
||||||
|
|
||||||
var addLegacyToolbarButtonLater = function(details) {
|
var onReadyStateComplete = function(window, callback, tryCount) {
|
||||||
details.tryCount = details.tryCount ? details.tryCount + 1 : 1;
|
tryCount = tryCount ? tryCount + 1 : 1;
|
||||||
if ( details.tryCount > 8 ) {
|
if ( tryCount > 8 ) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
vAPI.setTimeout(function(details) {
|
|
||||||
addLegacyToolbarButton(details.window, details.tryCount);
|
|
||||||
},
|
|
||||||
200,
|
|
||||||
details
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
var addLegacyToolbarButton = function(window, tryCount) {
|
|
||||||
var document = window.document;
|
|
||||||
|
|
||||||
// https://github.com/gorhill/uMatrix/issues/357
|
|
||||||
// Already installed?
|
|
||||||
if ( document.getElementById(tbb.id) !== null ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var document = window.document;
|
||||||
var toolbox = document.getElementById('navigator-toolbox') ||
|
var toolbox = document.getElementById('navigator-toolbox') ||
|
||||||
document.getElementById('mail-toolbox');
|
document.getElementById('mail-toolbox');
|
||||||
if (
|
if ( toolbox === null ) {
|
||||||
toolbox === null &&
|
vAPI.setTimeout(onReadyStateComplete.bind(null, window, callback, tryCount), 200);
|
||||||
addLegacyToolbarButtonLater({ window: window, tryCount: tryCount })
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// palette might take a little longer to appear on some platforms,
|
// palette might take a little longer to appear on some platforms,
|
||||||
// give it a small delay and try again.
|
// give it a small delay and try again.
|
||||||
var palette = toolbox.palette;
|
if ( toolbox.palette === null ) {
|
||||||
if (
|
vAPI.setTimeout(onReadyStateComplete.bind(null, window, callback, tryCount), 200);
|
||||||
palette === null &&
|
|
||||||
addLegacyToolbarButtonLater({ window: window, tryCount: tryCount })
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var navbar = document.getElementById('nav-bar');
|
if ( document.getElementById('nav-bar') === null ) {
|
||||||
if (
|
vAPI.setTimeout(onReadyStateComplete.bind(null, window, callback, tryCount), 200);
|
||||||
navbar === null &&
|
|
||||||
addLegacyToolbarButtonLater({ window: window, tryCount: tryCount })
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback(window);
|
||||||
|
};
|
||||||
|
|
||||||
|
var createToolbarButton = function(window) {
|
||||||
|
var document = window.document;
|
||||||
|
|
||||||
var toolbarButton = document.createElement('toolbarbutton');
|
var toolbarButton = document.createElement('toolbarbutton');
|
||||||
toolbarButton.setAttribute('id', tbb.id);
|
toolbarButton.setAttribute('id', tbb.id);
|
||||||
// type = panel would be more accurate, but doesn't look as good
|
// type = panel would be more accurate, but doesn't look as good
|
||||||
@ -2707,19 +2689,28 @@ vAPI.toolbarButton = {
|
|||||||
toolbarButtonPanel.addEventListener('popuphiding', tbb.onViewHiding);
|
toolbarButtonPanel.addEventListener('popuphiding', tbb.onViewHiding);
|
||||||
toolbarButton.appendChild(toolbarButtonPanel);
|
toolbarButton.appendChild(toolbarButtonPanel);
|
||||||
|
|
||||||
|
return toolbarButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
var addLegacyToolbarButton = function(window) {
|
||||||
|
var document = window.document;
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/357
|
||||||
|
// Already installed?
|
||||||
|
if ( document.getElementById(tbb.id) !== null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var toolbox = document.getElementById('navigator-toolbox') ||
|
||||||
|
document.getElementById('mail-toolbox');
|
||||||
|
var palette = toolbox.palette;
|
||||||
|
var navbar = document.getElementById('nav-bar');
|
||||||
|
var toolbarButton = createToolbarButton(window);
|
||||||
|
|
||||||
if ( palette !== null && palette.querySelector('#' + tbb.id) === null ) {
|
if ( palette !== null && palette.querySelector('#' + tbb.id) === null ) {
|
||||||
palette.appendChild(toolbarButton);
|
palette.appendChild(toolbarButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
tbb.closePopup = function() {
|
|
||||||
// `hidePopup` reported as not existing while testing legacy button
|
|
||||||
// on FF 41.0.2.
|
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1151796
|
|
||||||
if ( typeof toolbarButtonPanel.hidePopup === 'function' ) {
|
|
||||||
toolbarButtonPanel.hidePopup();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Find the place to put the button
|
// Find the place to put the button
|
||||||
var toolbars = toolbox.externalToolbars.slice();
|
var toolbars = toolbox.externalToolbars.slice();
|
||||||
for ( var child of toolbox.children ) {
|
for ( var child of toolbox.children ) {
|
||||||
@ -2769,8 +2760,19 @@ vAPI.toolbarButton = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var onPopupCloseRequested = function({target}) {
|
var onPopupCloseRequested = function({target}) {
|
||||||
if ( typeof tbb.closePopup === 'function' ) {
|
var document = target.ownerDocument;
|
||||||
tbb.closePopup(target);
|
if ( !document ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var toolbarButtonPanel = document.getElementById(tbb.viewId);
|
||||||
|
if ( toolbarButtonPanel === null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// `hidePopup` reported as not existing while testing legacy button
|
||||||
|
// on FF 41.0.2.
|
||||||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1151796
|
||||||
|
if ( typeof toolbarButtonPanel.hidePopup === 'function' ) {
|
||||||
|
toolbarButtonPanel.hidePopup();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2797,7 +2799,7 @@ vAPI.toolbarButton = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tbb.attachToNewWindow = function(win) {
|
tbb.attachToNewWindow = function(win) {
|
||||||
addLegacyToolbarButton(win);
|
onReadyStateComplete(win, addLegacyToolbarButton);
|
||||||
};
|
};
|
||||||
|
|
||||||
tbb.init = function() {
|
tbb.init = function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user