mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 16:47:15 +02:00
Better Safari popover sizing, no mutation events
This commit is contained in:
parent
c5e5ad65b6
commit
0d03499858
@ -27,12 +27,8 @@
|
||||
<dict>
|
||||
<key>Filename</key>
|
||||
<string>popup.html</string>
|
||||
<key>Height</key>
|
||||
<real>310</real>
|
||||
<key>Identifier</key>
|
||||
<string>popover</string>
|
||||
<key>Width</key>
|
||||
<real>180</real>
|
||||
</dict>
|
||||
</array>
|
||||
<key>Toolbar Items</key>
|
||||
|
@ -108,39 +108,18 @@ vAPI.i18n = function(s) {
|
||||
|
||||
// update popover size to its content
|
||||
if (safari.self.identifier === 'popover') {
|
||||
var whenSizeChanges = function(d,l){(function(a,d){function h(a,b){a.addEventListener("scroll",b)}function e(){k.style.width=b.offsetWidth+10+"px";k.style.height=b.offsetHeight+10+"px";b.scrollLeft=b.scrollWidth;b.scrollTop=b.scrollHeight;c.scrollLeft=c.scrollWidth;c.scrollTop=c.scrollHeight;f=a.offsetWidth;g=a.offsetHeight}a.b=d;a.a=document.createElement("div");a.a.style.cssText="position:absolute;left:0;top:0;right:0;bottom:0;overflow:scroll;z-index:-1;visibility:hidden";a.a.innerHTML='<div style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:scroll;z-index:-1;visibility:hidden"><div style="position:absolute;left:0;top:0;"></div></div><div style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:scroll;z-index:-1;visibility:hidden"><div style="position:absolute;left:0;top:0;width:200%;height:200%"></div></div>';
|
||||
a.appendChild(a.a);var b=a.a.childNodes[0],k=b.childNodes[0],c=a.a.childNodes[1],f,g;e();h(b,function(){(a.offsetWidth>f||a.offsetHeight>g)&&a.b();e()});h(c,function(){(a.offsetWidth<f||a.offsetHeight<g)&&a.b();e()})})(d,l)};
|
||||
var onLoaded = function() {
|
||||
// Initial dimensions are set in Info.plist
|
||||
var pWidth = safari.self.width;
|
||||
var pHeight = safari.self.height;
|
||||
var upadteTimer = null;
|
||||
var resizePopover = function() {
|
||||
if (upadteTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
upadteTimer = setTimeout(function() {
|
||||
safari.self.width = Math.max(pWidth, document.body.clientWidth);
|
||||
safari.self.height = Math.max(pHeight, document.body.clientHeight);
|
||||
upadteTimer = null;
|
||||
}, 20);
|
||||
var body = document.body, popover = safari.self;
|
||||
var updateSize = function() {
|
||||
popover.width = body.offsetWidth;
|
||||
popover.height = body.offsetHeight;
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
body.style.position = "relative"; // Necessary for size change detection
|
||||
whenSizeChanges(body, updateSize);
|
||||
updateSize();
|
||||
};
|
||||
|
||||
window.addEventListener('load', onLoaded);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user