From c5e5ad65b6236a11af275aa07d828edd3b8dc8b1 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 11 Jan 2015 18:05:22 -0700 Subject: [PATCH 1/3] More compatible build -- use codecs module --- tools/make-safari-meta.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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)) From 0d034998587c06bc54049da712a2f3d3cac26ce3 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 11 Jan 2015 18:06:29 -0700 Subject: [PATCH 2/3] Better Safari popover sizing, no mutation events --- platform/safari/Info.plist | 4 ---- 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 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..406f49ddb 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='
'; +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 Date: Sun, 11 Jan 2015 19:07:25 -0700 Subject: [PATCH 3/3] Abstract out platform-specific popup UI JavaScript --- platform/safari/vapi-common.js | 21 ---------------- platform/safari/vapi-popup.js | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 platform/safari/vapi-popup.js diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index 406f49ddb..ecfb04610 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -104,27 +104,6 @@ vAPI.i18n = function(s) { return this.i18nData[s] || 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='
'; -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 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);