mirror of https://github.com/gorhill/uBlock.git
Implement popup autoresizing for Safari
By default, Safari doesn't resize the popup to its content, but it's possible to set the size pragmatically. The popup will be resized every time when a change happens in the DOM tree.
This commit is contained in:
parent
775f51a04b
commit
f9602fa5a7
|
@ -27,8 +27,12 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>Filename</key>
|
<key>Filename</key>
|
||||||
<string>popup.html</string>
|
<string>popup.html</string>
|
||||||
|
<key>Height</key>
|
||||||
|
<real>1</real>
|
||||||
<key>Identifier</key>
|
<key>Identifier</key>
|
||||||
<string>popover</string>
|
<string>popover</string>
|
||||||
|
<key>Width</key>
|
||||||
|
<real>1</real>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>Toolbar Items</key>
|
<key>Toolbar Items</key>
|
||||||
|
|
|
@ -27,8 +27,12 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>Filename</key>
|
<key>Filename</key>
|
||||||
<string>popup.html</string>
|
<string>popup.html</string>
|
||||||
|
<key>Height</key>
|
||||||
|
<real>1</real>
|
||||||
<key>Identifier</key>
|
<key>Identifier</key>
|
||||||
<string>popover</string>
|
<string>popover</string>
|
||||||
|
<key>Width</key>
|
||||||
|
<real>1</real>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>Toolbar Items</key>
|
<key>Toolbar Items</key>
|
||||||
|
|
|
@ -49,12 +49,35 @@ if (window.chrome) {
|
||||||
|
|
||||||
// update popover size to its content
|
// update popover size to its content
|
||||||
if (safari.self.identifier === 'popover' && safari.self) {
|
if (safari.self.identifier === 'popover' && safari.self) {
|
||||||
vAPI.updatePopoverSize = function() {
|
(function() {
|
||||||
|
var upadteTimer = null;
|
||||||
|
var resizePopover = function() {
|
||||||
|
if (upadteTimer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
upadteTimer = setTimeout(function() {
|
||||||
safari.self.width = document.body.clientWidth;
|
safari.self.width = document.body.clientWidth;
|
||||||
safari.self.height = document.body.clientHeight;
|
safari.self.height = document.body.clientHeight;
|
||||||
|
upadteTimer = null;
|
||||||
|
}, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(vAPI.updatePopoverSize, 200);
|
var mutObs = window.MutationObserver || window.WebkitMutationObserver;
|
||||||
|
|
||||||
|
if (mutObs) {
|
||||||
|
(new mutObs(resizePopover)).observe(document, {
|
||||||
|
childList: true,
|
||||||
|
attributes: true,
|
||||||
|
characterData: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Safari doesn't support DOMAttrModified
|
||||||
|
document.addEventListener('DOMSubtreeModified', resizePopover);
|
||||||
|
}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue