MCPcopy Create free account
hub / github.com/microsoft/SandDance / constructor

Method constructor

docs/app/js/sanddance-app.js:94547–94577  ·  view source on GitHub ↗
(element, callback, options)

Source from the content-addressed store, hash-verified

94545const SHIFT_MULTIPLIER = 0.25;
94546class WheelInput extends (0, _inputDefault.default) {
94547 constructor(element, callback, options){
94548 super(element, callback, options);
94549 /* eslint-disable complexity, max-statements */ this.handleEvent = (event)=>{
94550 if (!this.options.enable) return;
94551 let value = event.deltaY;
94552 if ((0, _globals.window).WheelEvent) {
94553 // Firefox doubles the values on retina screens...
94554 if (firefox && event.deltaMode === (0, _globals.window).WheelEvent.DOM_DELTA_PIXEL) value /= (0, _globals.window).devicePixelRatio;
94555 if (event.deltaMode === (0, _globals.window).WheelEvent.DOM_DELTA_LINE) value *= WHEEL_DELTA_PER_LINE;
94556 }
94557 if (value !== 0 && value % WHEEL_DELTA_MAGIC_SCALER === 0) // This one is definitely a mouse wheel event.
94558 // Normalize this value to match trackpad.
94559 value = Math.floor(value / WHEEL_DELTA_MAGIC_SCALER);
94560 if (event.shiftKey && value) value = value * SHIFT_MULTIPLIER;
94561 this.callback({
94562 type: EVENT_TYPE,
94563 center: {
94564 x: event.clientX,
94565 y: event.clientY
94566 },
94567 delta: -value,
94568 srcEvent: event,
94569 pointerType: "mouse",
94570 target: event.target
94571 });
94572 };
94573 this.events = (this.options.events || []).concat(WHEEL_EVENTS);
94574 this.events.forEach((event)=>element.addEventListener(event, this.handleEvent, (0, _globals.passiveSupported) ? {
94575 passive: false
94576 } : false));
94577 }
94578 destroy() {
94579 this.events.forEach((event)=>this.element.removeEventListener(event, this.handleEvent));
94580 }

Callers

nothing calls this directly

Calls 1

forEachMethod · 0.45

Tested by

no test coverage detected