Commit 7914d496 authored by Andrea Giammarchi's avatar Andrea Giammarchi

Issue 7134 - Firefox `event.layerX` coordinates off by `element.offsetLeft`

parent 89b927f2
Pipeline #37408120 passed with stages
in 8 minutes and 28 seconds
......@@ -17,6 +17,18 @@
"use strict";
let browserName = "unknown";
// Firefox only, which is exactly the one
// we are looking for in order to patch events' layerX
if (browser.runtime.getBrowserInfo)
{
browser.runtime.getBrowserInfo().then(info =>
{
browserName = info.name.toLowerCase();
});
}
module.exports = {
$: (selector, container = document) => container.querySelector(selector),
$$: (selector, container = document) => container.querySelectorAll(selector),
......@@ -69,10 +81,16 @@ module.exports = {
// good old way that will work properly in older browsers too
// mandatory for Chrome 49, still better than manual fallback
// in all other browsers that provide such functionality
let el = event.currentTarget;
if ("layerX" in event && "layerY" in event)
return {x: event.layerX, y: event.layerY};
{
let {layerX} = event;
// see https://issues.adblockplus.org/ticket/7134
if (browserName === "firefox")
layerX -= el.offsetLeft;
return {x: layerX, y: event.layerY};
}
// fallback when layerX/Y will be removed (since deprecated)
let el = event.currentTarget;
let x = 0;
let y = 0;
do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment