diff --git a/platform/safari/Info.plist b/platform/safari/Info.plist
index 048bf6173..37223df73 100644
--- a/platform/safari/Info.plist
+++ b/platform/safari/Info.plist
@@ -27,12 +27,8 @@
Filename
popup.html
- Height
- 310
Identifier
popover
- Width
- 180
Toolbar Items
diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js
index 4a607500e..ecfb04610 100644
--- a/platform/safari/vapi-common.js
+++ b/platform/safari/vapi-common.js
@@ -104,48 +104,6 @@ vAPI.i18n = function(s) {
return this.i18nData[s] || s;
};
-/******************************************************************************/
-
-// update popover size to its content
-if (safari.self.identifier === 'popover') {
- 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 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);
- }
- };
-
- window.addEventListener('load', onLoaded);
-}
-
-/******************************************************************************/
-
})();
/******************************************************************************/
diff --git a/platform/safari/vapi-popup.js b/platform/safari/vapi-popup.js
new file mode 100644
index 000000000..1bf7e3352
--- /dev/null
+++ b/platform/safari/vapi-popup.js
@@ -0,0 +1,45 @@
+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 body = document.body, popover = safari.self;
+ var updateSize = function() {
+ popover.width = body.offsetWidth;
+ popover.height = body.offsetHeight;
+ };
+ updateSize();
+ body.style.position = "relative"; // Necessary for size change detection
+ whenSizeChanges(body, updateSize);
+};
+window.addEventListener('load', onLoaded);
diff --git a/tools/make-safari-meta.py b/tools/make-safari-meta.py
index eb0b701e8..1581faaf0 100755
--- a/tools/make-safari-meta.py
+++ b/tools/make-safari-meta.py
@@ -3,6 +3,7 @@
import os
import json
import sys
+import codecs
from time import time
from shutil import rmtree
from collections import OrderedDict
@@ -27,7 +28,7 @@ locale_dir = pj(build_dir, '_locales')
for alpha2 in os.listdir(locale_dir):
locale_path = pj(locale_dir, alpha2, 'messages.json')
- with open(locale_path, encoding='utf-8') as f:
+ with codecs.open(locale_path, 'r', encoding='utf8') as f:
string_data = json.load(f, object_pairs_hook=OrderedDict)
if alpha2 == 'en':
@@ -43,7 +44,7 @@ for alpha2 in os.listdir(locale_dir):
mkdirs(pj(locale_dir))
- with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f:
+ with codecs.open(locale_path, 'w', encoding='utf8') as f:
json.dump(string_data, f, ensure_ascii=False)
@@ -51,13 +52,13 @@ for alpha2 in os.listdir(locale_dir):
proj_dir = pj(os.path.split(os.path.abspath(__file__))[0], '..')
chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json')
-with open(chromium_manifest, encoding='utf-8') as m:
+with codecs.open(chromium_manifest, encoding='utf8') as m:
manifest = json.load(m)
manifest['buildNumber'] = int(time())
manifest['description'] = description
-with open(pj(build_dir, 'Info.plist'), 'r+t', encoding='utf-8', newline='\n') as f:
+with codecs.open(pj(build_dir, 'Info.plist'), 'r+', encoding='utf8') as f:
info_plist = f.read()
f.seek(0)
@@ -67,8 +68,8 @@ with open(pj(build_dir, 'Info.plist'), 'r+t', encoding='utf-8', newline='\n') as
update_plist = pj(proj_dir, 'platform', 'safari', 'Update.plist')
update_plist_build = pj(build_dir, '..', os.path.basename(update_plist))
-with open(update_plist_build, 'wt', encoding='utf-8', newline='\n') as f:
- with open(update_plist, encoding='utf-8') as u:
+with codecs.open(update_plist_build, 'w', encoding='utf8') as f:
+ with codecs.open(update_plist, encoding='utf8') as u:
update_plist = u.read()
f.write(update_plist.format(**manifest))