Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should check convertHammerInputType when not supporting touch", () => {
// Given
const MockHammerInput = HammerInputInjector({
"../const": {
SUPPORT_TOUCH : false
}
}).HammerInput;
// When
let inputType = [ "touch", "mouse" ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.equal(Hammer.MouseInput);
// When
inputType = [ "touch" ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.null;
// When
inputType = [ "mouse" ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.equal(Hammer.MouseInput);
// When
inputType = [ ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.null;
});
}).HammerInput;
// When
let inputType = [ "touch", "mouse" ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.equal(Hammer.TouchInput);
// When
inputType = [ "touch" ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.equal(Hammer.TouchInput);
// When
inputType = [ "mouse" ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.equal(Hammer.MouseInput);
// When
inputType = [ ];
// Then
expect(MockHammerInput.convertHammerInputType(inputType)).to.be.null;
});
Hammer.inherit(PointerInput, Hammer.PointerEventInput, {});
PointerInput.prototype.constructor = function() { }; // STUB, avoids init() being called too early
var MOUSE_ELEMENT_EVENTS = 'mousedown';
var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
function MouseInput() {
// OVERRIDE: listen for all event on the element, not on window
// This is needed for event propagation to get the right targets
this.evEl = MOUSE_ELEMENT_EVENTS + ' ' + MOUSE_WINDOW_EVENTS;
this.evWin = '';
this.pressed = false; // mousedown state
Hammer.Input.apply(this, arguments);
}
Hammer.inherit(MouseInput, Hammer.MouseInput, {});
MouseInput.prototype.constructor = function() { }; // STUB, avoids overridden constructor being called
function TouchMouseInput() {
Hammer.Input.apply(this, arguments);
var handler = this.handler.bind(this);
this.touch = new Hammer.TouchInput(this.manager, handler);
this.mouse = new MouseInput(this.manager, handler);
this.primaryTouch = null;
this.lastTouches = [];
}
Hammer.inherit(TouchMouseInput, Hammer.TouchMouseInput, {});
TouchMouseInput.prototype.constructor = function() { }; // STUB, avoids overridden constructor being called
var Input = null;
hasTouch = exports.SUPPORT_TOUCH;
break;
case "pointer": hasPointer = exports.SUPPORT_POINTER_EVENTS;
}
});
if (hasPointer) {
return Hammer.PointerEventInput;
}
else if (hasTouch && hasMouse) {
return Hammer.TouchMouseInput;
}
else if (hasTouch) {
return Hammer.TouchInput;
}
else if (hasMouse) {
return Hammer.MouseInput;
}
return null;
}
exports.convertInputType = convertInputType;