diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "d3": "^5.15.0", "datatables.net-responsive-bs4": "^2.2.3", "dompurify": "^2.0.7", - "elementsfrompoint-polyfill": "^1.0.0", "font-awesome": "^4.7.0", "highlight.js": "^9.18.0", "highlightjs-line-numbers.js": "^2.7.0", diff --git a/swh/web/assets/src/bundles/vendors/elementsfrompoint-polyfill.js b/swh/web/assets/src/bundles/vendors/elementsfrompoint-polyfill.js new file mode 100644 --- /dev/null +++ b/swh/web/assets/src/bundles/vendors/elementsfrompoint-polyfill.js @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2020 The Software Heritage developers + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU Affero General Public License version 3, or any later version + * See top-level LICENSE file for more information + */ + +/** + * Some old browsers (Safari 11.0, Firefox 36.0) do not support + * document.elementsFromPoint, only document.elementFromPoint. + * https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/elementsFromPoint + * Polyfill is based on https://github.com/JSmith01/elementsfrompoint-polyfill (public domain) + * and fix a bug in that implementation + */ + +if (typeof document !== 'undefined' && typeof document.elementsFromPoint === 'undefined') { + document.elementsFromPoint = elementsFromPointPolyfill; +} + +function elementsFromPointPolyfill(x, y) { + var elements = []; + var pointerEvents = []; + var el; + + do { + var parent = document.elementFromPoint(x, y); + if (parent) { + el = parent; + elements.push(el); + pointerEvents.push(el.style.pointerEvents); + el.style.pointerEvents = 'none'; + } else { + el = null; + } + } while (el); + + for (var i = 0; i < elements.length; i++) { + elements[i].style.pointerEvents = pointerEvents[i]; + } + + return elements; +} diff --git a/swh/web/assets/src/bundles/vendors/index.js b/swh/web/assets/src/bundles/vendors/index.js --- a/swh/web/assets/src/bundles/vendors/index.js +++ b/swh/web/assets/src/bundles/vendors/index.js @@ -12,7 +12,7 @@ import 'core-js/stable'; import 'regenerator-runtime/runtime'; import 'whatwg-fetch/dist/fetch.umd'; -import 'elementsfrompoint-polyfill'; +import './elementsfrompoint-polyfill'; // jquery and bootstrap import 'jquery';