Safari-specific popup JS is now.. nicer

This commit is contained in:
Chris 2015-04-07 00:34:36 -06:00
parent 53768aff22
commit a3bef3a1bd
1 changed files with 24 additions and 15 deletions

View File

@ -19,34 +19,43 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
(function() { (function() {
'use strict'; "use strict";
var DF_ENABLED_CLASS = "dfEnabled"; if(typeof safari.self === "undefined") {
return;
}
var onLoaded = function() { var onLoaded = function() {
var _toggle = DOMTokenList.prototype.toggle; var _toggle = DOMTokenList.prototype.toggle;
DOMTokenList.prototype.toggle = function(className) { DOMTokenList.prototype.toggle = function(className, enabled) {
if(className === "dfEnabled") {
updateSize(enabled);
}
_toggle.apply(this, arguments); _toggle.apply(this, arguments);
if(className === DF_ENABLED_CLASS) { if(className === "dfEnabled") {
setTimeout(updateSize, 0); setTimeout(updateSize, 0);
} }
}; };
var body = document.body, popover = safari.self; var body = document.body,
popover = safari.self,
panes = document.getElementById("panes"),
pane1 = panes.children[0],
pane2 = panes.children[1];
var panes = document.getElementById("panes"), body.style.width = "100%";
powerAndStatsPane = panes.children[0], panes.style.width = "100%";
dfPane = panes.children[1];
var updateSize = function(isOpen) {
var updateSize = function() { var w = pane2.clientWidth;
var dfEnabled = panes.classList.contains(DF_ENABLED_CLASS); if(typeof isOpen === "undefined") {
popover.width = powerAndStatsPane.clientWidth + (dfEnabled ? dfPane.clientWidth : 0); isOpen = (w !== 0);
}
popover.width = (isOpen ? w : 0) + pane1.clientWidth;
popover.height = body.clientHeight; popover.height = body.clientHeight;
}; };
body.style.setProperty("width", "100%");
panes.style.setProperty("width", "100%");
dfPane.style.setProperty("display", "inline-block", "important");
setTimeout(updateSize, 0); setTimeout(updateSize, 0);
}; };
window.addEventListener("load", onLoaded); window.addEventListener("load", onLoaded);
})(); })();