From 5e363d1e37cb380daa9a15b1617f3f86f846b5bd Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Mar 2015 17:08:28 -0600 Subject: [PATCH 1/6] Safari: fix popup resizing hiccup --- platform/safari/vapi-popup.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/platform/safari/vapi-popup.js b/platform/safari/vapi-popup.js index 80d68351d..9293be358 100644 --- a/platform/safari/vapi-popup.js +++ b/platform/safari/vapi-popup.js @@ -55,14 +55,27 @@ var whenSizeChanges = function(elm, callback) { reset(); }); }; + var onLoaded = function() { + var style = document.createElement("style"); + style.textContent = "html,body,#panes{width:100%}#panes{white-space:nowrap;text-align:right}#panes > div:nth-of-type(2){display:inline-block !important}"; + var _toggle = DOMTokenList.prototype.toggle; + DOMTokenList.prototype.toggle = function(cls, stt) { + _toggle.apply(this, arguments); + if(cls === "dfEnabled") { + isThere = stt; + setTimeout(updateSize, 0); + var _this = this, _args = arguments; + } + }; var body = document.body, popover = safari.self; + body.appendChild(style); + var isThere = !!document.querySelector(".dfEnabled"); var updateSize = function() { - popover.width = body.clientWidth; + popover.width = 152 + (isThere ? 320 : 0); popover.height = body.clientHeight; }; body.style.position = "relative"; // Necessary for size change detection - whenSizeChanges(body, updateSize); updateSize(); }; window.addEventListener("load", onLoaded); From 30f795caf5cb851fedaa63d947379eb94afb1c75 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Mar 2015 17:13:02 -0600 Subject: [PATCH 2/6] Safari: remove dead code --- platform/safari/vapi-popup.js | 37 ----------------------------------- 1 file changed, 37 deletions(-) diff --git a/platform/safari/vapi-popup.js b/platform/safari/vapi-popup.js index 9293be358..b875657b2 100644 --- a/platform/safari/vapi-popup.js +++ b/platform/safari/vapi-popup.js @@ -21,41 +21,6 @@ (function() { 'use strict'; -var whenSizeChanges = function(elm, callback) { - var reset = function() { - k.style.width = grow.offsetWidth + 10 + "px"; - k.style.height = grow.offsetHeight + 10 + "px"; - grow.scrollLeft = grow.scrollWidth; - grow.scrollTop = grow.scrollHeight; - shrink.scrollLeft = shrink.scrollWidth; - shrink.scrollTop = shrink.scrollHeight; - w = elm.offsetWidth; - h = elm.offsetHeight; - } - var aux = document.createElement("div"); - aux.style.cssText = "position:absolute;left:0;top:0;right:0;bottom:0;overflow:scroll;z-index:-1;visibility:hidden"; - aux.innerHTML = '
\ -
\ -
\ -
\ -
\ -
'; - elm.appendChild(aux); - var grow = aux.childNodes[0], - k = grow.childNodes[0], - shrink = aux.childNodes[1]; - var w, h; - reset(); - grow.addEventListener("scroll", function() { - (elm.offsetWidth > w || elm.offsetHeight > h) && callback(); - reset(); - }); - shrink.addEventListener("scroll", function() { - (elm.offsetWidth < w || elm.offsetHeight < h) && callback(); - reset(); - }); -}; - var onLoaded = function() { var style = document.createElement("style"); style.textContent = "html,body,#panes{width:100%}#panes{white-space:nowrap;text-align:right}#panes > div:nth-of-type(2){display:inline-block !important}"; @@ -65,7 +30,6 @@ var onLoaded = function() { if(cls === "dfEnabled") { isThere = stt; setTimeout(updateSize, 0); - var _this = this, _args = arguments; } }; var body = document.body, popover = safari.self; @@ -75,7 +39,6 @@ var onLoaded = function() { popover.width = 152 + (isThere ? 320 : 0); popover.height = body.clientHeight; }; - body.style.position = "relative"; // Necessary for size change detection updateSize(); }; window.addEventListener("load", onLoaded); From 924bcfab629fc7a3e13ba7070591da4d0a922c7a Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Mar 2015 17:40:17 -0600 Subject: [PATCH 3/6] Safari: remove hardcoded values from popup resizing --- platform/safari/vapi-popup.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/platform/safari/vapi-popup.js b/platform/safari/vapi-popup.js index b875657b2..ce86ea246 100644 --- a/platform/safari/vapi-popup.js +++ b/platform/safari/vapi-popup.js @@ -21,22 +21,29 @@ (function() { 'use strict'; +var DF_ENABLED_CLASS = "dfEnabled"; + var onLoaded = function() { - var style = document.createElement("style"); - style.textContent = "html,body,#panes{width:100%}#panes{white-space:nowrap;text-align:right}#panes > div:nth-of-type(2){display:inline-block !important}"; var _toggle = DOMTokenList.prototype.toggle; - DOMTokenList.prototype.toggle = function(cls, stt) { + DOMTokenList.prototype.toggle = function(className) { _toggle.apply(this, arguments); - if(cls === "dfEnabled") { - isThere = stt; + if(className === DF_ENABLED_CLASS) { setTimeout(updateSize, 0); } }; var body = document.body, popover = safari.self; + + var style = document.createElement("style"); + style.textContent = "html,body,#panes{width:100%}#panes{white-space:nowrap;text-align:right}#panes > div:nth-of-type(2){display:inline-block !important}"; body.appendChild(style); - var isThere = !!document.querySelector(".dfEnabled"); + + var panes = document.getElementById("panes"), + powerAndStatsPane = panes.children[0], + dfPane = panes.children[1]; + var updateSize = function() { - popover.width = 152 + (isThere ? 320 : 0); + var dfEnabled = panes.classList.contains(DF_ENABLED_CLASS); + popover.width = powerAndStatsPane.clientWidth + (dfEnabled ? dfPane.clientWidth : 0); popover.height = body.clientHeight; }; updateSize(); From 3c9f5c0da172c1aadc5efe06671ca8f0c1eee4f1 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Mar 2015 18:08:12 -0600 Subject: [PATCH 4/6] Safari: don't need to inject a stylesheet into popup --- platform/safari/vapi-popup.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/platform/safari/vapi-popup.js b/platform/safari/vapi-popup.js index ce86ea246..ce3819695 100644 --- a/platform/safari/vapi-popup.js +++ b/platform/safari/vapi-popup.js @@ -33,14 +33,15 @@ var onLoaded = function() { }; var body = document.body, popover = safari.self; - var style = document.createElement("style"); - style.textContent = "html,body,#panes{width:100%}#panes{white-space:nowrap;text-align:right}#panes > div:nth-of-type(2){display:inline-block !important}"; - body.appendChild(style); - var panes = document.getElementById("panes"), powerAndStatsPane = panes.children[0], dfPane = panes.children[1]; + body.style.setProperty("width", "100%"); + panes.style.setProperty("text-align", "right"); + panes.style.setProperty("width", "100%"); + dfPane.style.setProperty("display", "inline-block", "important"); + var updateSize = function() { var dfEnabled = panes.classList.contains(DF_ENABLED_CLASS); popover.width = powerAndStatsPane.clientWidth + (dfEnabled ? dfPane.clientWidth : 0); From cf3816b494f3c06e38576486767c7be523676e3b Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Mar 2015 18:09:06 -0600 Subject: [PATCH 5/6] Safari: code review for readability --- platform/safari/vapi-popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/safari/vapi-popup.js b/platform/safari/vapi-popup.js index ce3819695..0f9dd8d13 100644 --- a/platform/safari/vapi-popup.js +++ b/platform/safari/vapi-popup.js @@ -38,8 +38,8 @@ var onLoaded = function() { dfPane = panes.children[1]; body.style.setProperty("width", "100%"); - panes.style.setProperty("text-align", "right"); panes.style.setProperty("width", "100%"); + panes.style.setProperty("text-align", "right"); dfPane.style.setProperty("display", "inline-block", "important"); var updateSize = function() { From 339ffe969895925c02a94155bc8ba1e56a2a89b1 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Mar 2015 22:50:39 -0600 Subject: [PATCH 6/6] Safari: enable storage-used number formatting consistent with other browsers --- platform/safari/vapi-common.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index 8dde1c596..49cab7cf8 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -130,6 +130,14 @@ vAPI.closePopup = function() { /******************************************************************************/ +Number.prototype._toLocaleString = Number.prototype.toLocaleString; +Number.prototype.toLocaleString = function() { + // some parts expect comma-formatting; Safari doesn't do it automatically + return this._toLocaleString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); +}; + +/******************************************************************************/ + // A localStorage-like object which should be accessible from the // background page or auxiliary pages. // This storage is optional, but it is nice to have, for a more polished user