Add _qutebrowser_ prefix for custom JS functions

With QtWebKit or QtWebEngine with Qt < 5.7, the functions end up in the
page's namespace. We can't easily avoid this, but at least we can name
them in a way which reduces conflicts.
This commit is contained in:
Florian Bruhin 2016-08-05 10:30:09 +02:00
parent ab0d9ca499
commit 0169f3a24f
3 changed files with 5 additions and 5 deletions

View File

@ -17,7 +17,7 @@
* along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
*/
function scroll_to_perc(x, y) {
function _qutebrowser_scroll_to_perc(x, y) {
var elem = document.documentElement;
var x_px = window.scrollX;
var y_px = window.scrollY;
@ -33,13 +33,13 @@ function scroll_to_perc(x, y) {
window.scroll(x_px, y_px);
}
function scroll_delta_page(x, y) {
function _qutebrowser_scroll_delta_page(x, y) {
var dx = document.documentElement.clientWidth * x;
var dy = document.documentElement.clientHeight * y;
window.scrollBy(dx, dy);
}
function scroll_pos() {
function _qutebrowser_scroll_pos() {
var elem = document.documentElement;
var dx = (elem.scrollWidth - elem.clientWidth);
var dy = (elem.scrollHeight - elem.clientHeight);

View File

@ -64,7 +64,7 @@ def _convert_js_arg(arg):
def assemble(name, function, *args):
"""Assemble a javascript file and a function call."""
code = "{code}\n{function}({args});".format(
code = "{code}\n_qutebrowser_{function}({args});".format(
code=utils.read_file('javascript/{}.js'.format(name)),
function=function,
args=', '.join(_convert_js_arg(arg) for arg in args),

View File

@ -140,5 +140,5 @@ def test_convert_js_arg(arg, expected):
def test_assemble(monkeypatch):
monkeypatch.setattr(javascript.utils, 'read_file',
'<code from {}>'.format)
expected = '<code from javascript/foo.js>\nfunc(23);'
expected = '<code from javascript/foo.js>\n_qutebrowser_func(23);'
assert javascript.assemble('foo', 'func', 23) == expected