Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add event listener passive support to address chrome dev tools violation warning

Ed Platoda3259d89af4
diff --git a/web/js/main.js b/web/js/main.js
index c824edf30..a7b06d958 100644
--- a/web/js/main.js
+++ b/web/js/main.js
@@ -243,6 +243,18 @@ window.onload = () => {
ui.activeLayers = layersActive(models, ui, config);
ui.addModal = layersModal(models, ui, config);
+ // Test via a getter in the options object to see if the passive property is accessed
+ ui.supportsPassive = false;
+ try {
+ var opts = Object.defineProperty({}, 'passive', {
+ get: function() {
+ ui.supportsPassive = true;
+ }
+ });
+ window.addEventListener("testPassive", null, opts);
+ window.removeEventListener("testPassive", null, opts);
+ } catch (e) {}
+
function timelineInit() {
ui.timeline = timeline(models, config, ui);
ui.timeline.data = timelineData(models, config, ui);
diff --git a/web/js/natural-events/markers.js b/web/js/natural-events/markers.js
index a81667e80..af97d2099 100644
--- a/web/js/natural-events/markers.js
+++ b/web/js/natural-events/markers.js
@@ -102,12 +102,14 @@ export default function markers (models, ui) {
// moved to `element`. Maybe this was a change to OpenLayers.
var pinEl = marker.pin.element_ || marker.pin.element;
+
+ // Use passiveSupport detect in ui. passive applied if supported, capture will be false either way.
['pointerdown', 'mousedown', 'touchstart'].forEach(function (type) {
pinEl.addEventListener(type, function (e) {
willSelect = true;
moveCount = 0;
passEventToTarget(e, olViewport);
- });
+ }, ui.supportsPassive ? { passive: true } : false);
});
[
@@ -120,7 +122,7 @@ export default function markers (models, ui) {
].forEach(function (type) {
pinEl.addEventListener(type, function (e) {
passEventToTarget(e, olViewport);
- });
+ }, ui.supportsPassive ? { passive: true } : false);
});
['pointermove', 'mousemove'].forEach(function (type) {
@@ -129,7 +131,7 @@ export default function markers (models, ui) {
if (moveCount > 2) {
willSelect = false;
}
- });
+ }, ui.supportsPassive ? { passive: true } : false);
});
pinEl.addEventListener('click', function (e) {
@@ -138,7 +140,7 @@ export default function markers (models, ui) {
} else {
passEventToTarget(e, olViewport);
}
- });
+ }, ui.supportsPassive ? { passive: true } : false);
}
return marker;