diff options
author | Chris <abody.97@gmail.com> | 2015-01-11 18:06:29 -0700 |
---|---|---|
committer | Chris <abody.97@gmail.com> | 2015-01-11 18:06:29 -0700 |
commit | 0d034998587c06bc54049da712a2f3d3cac26ce3 (patch) | |
tree | e370f341ea809a5a2cabeb69fea3f74e868c3ac6 /platform | |
parent | c5e5ad65b6236a11af275aa07d828edd3b8dc8b1 (diff) | |
download | uBlock-0d034998587c06bc54049da712a2f3d3cac26ce3.zip uBlock-0d034998587c06bc54049da712a2f3d3cac26ce3.tar.gz uBlock-0d034998587c06bc54049da712a2f3d3cac26ce3.tar.bz2 |
Better Safari popover sizing, no mutation events
Diffstat (limited to 'platform')
-rw-r--r-- | platform/safari/Info.plist | 4 | ||||
-rw-r--r-- | platform/safari/vapi-common.js | 39 |
2 files changed, 9 insertions, 34 deletions
diff --git a/platform/safari/Info.plist b/platform/safari/Info.plist index 048bf61..37223df 100644 --- a/platform/safari/Info.plist +++ b/platform/safari/Info.plist @@ -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> diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index 4a60750..406f49d 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -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); } |