1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-06 19:02:30 +01:00

Merge pull request #477 from chrisaljoudi/master

Safari: more compatible build, better popover sizing
This commit is contained in:
Raymond Hill 2015-01-11 21:14:51 -05:00
commit 87ccd82b8b
4 changed files with 52 additions and 52 deletions

View File

@ -27,12 +27,8 @@
<dict> <dict>
<key>Filename</key> <key>Filename</key>
<string>popup.html</string> <string>popup.html</string>
<key>Height</key>
<real>310</real>
<key>Identifier</key> <key>Identifier</key>
<string>popover</string> <string>popover</string>
<key>Width</key>
<real>180</real>
</dict> </dict>
</array> </array>
<key>Toolbar Items</key> <key>Toolbar Items</key>

View File

@ -104,48 +104,6 @@ vAPI.i18n = function(s) {
return this.i18nData[s] || 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);
}
/******************************************************************************/
})(); })();
/******************************************************************************/ /******************************************************************************/

View File

@ -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 = '<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>';
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);

View File

@ -3,6 +3,7 @@
import os import os
import json import json
import sys import sys
import codecs
from time import time from time import time
from shutil import rmtree from shutil import rmtree
from collections import OrderedDict from collections import OrderedDict
@ -27,7 +28,7 @@ locale_dir = pj(build_dir, '_locales')
for alpha2 in os.listdir(locale_dir): for alpha2 in os.listdir(locale_dir):
locale_path = pj(locale_dir, alpha2, 'messages.json') 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) string_data = json.load(f, object_pairs_hook=OrderedDict)
if alpha2 == 'en': if alpha2 == 'en':
@ -43,7 +44,7 @@ for alpha2 in os.listdir(locale_dir):
mkdirs(pj(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) 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], '..') proj_dir = pj(os.path.split(os.path.abspath(__file__))[0], '..')
chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json') 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 = json.load(m)
manifest['buildNumber'] = int(time()) manifest['buildNumber'] = int(time())
manifest['description'] = description 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() info_plist = f.read()
f.seek(0) 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 = pj(proj_dir, 'platform', 'safari', 'Update.plist')
update_plist_build = pj(build_dir, '..', os.path.basename(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 codecs.open(update_plist_build, 'w', encoding='utf8') as f:
with open(update_plist, encoding='utf-8') as u: with codecs.open(update_plist, encoding='utf8') as u:
update_plist = u.read() update_plist = u.read()
f.write(update_plist.format(**manifest)) f.write(update_plist.format(**manifest))