-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add inputKey option to PanInput and WheelInput #204
Changes from all commits
7c6d63a
f49e489
266828a
ffd17cd
753ac81
974465c
62fcc08
294b668
85a6ae6
9716ebb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ | |
* egjs projects are licensed under the MIT license | ||
*/ | ||
import { $, getDirection, useDirection } from "../utils"; | ||
import { DIRECTION_HORIZONTAL, DIRECTION_VERTICAL } from "../const"; | ||
import { ANY, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL } from "../const"; | ||
import { ElementType } from "../types"; | ||
|
||
import { toAxis, InputType, InputTypeObserver } from "./InputType"; | ||
import { isValidKey } from "../eventInput/EventInput"; | ||
|
||
export interface WheelInputOption { | ||
inputKey?: string[]; | ||
scale?: number; | ||
releaseDelay?: number; | ||
useNormalized?: boolean; | ||
|
@@ -18,6 +20,19 @@ export interface WheelInputOption { | |
/** | ||
* @typedef {Object} WheelInputOption The option object of the eg.Axes.WheelInput module | ||
* @ko eg.Axes.WheelInput 모듈의 옵션 객체 | ||
* @param {String[]} [inputKey=["any"]] List of key combinations to allow input | ||
* - any: any key | ||
* - shift: shift key | ||
* - ctrl: ctrl key and pinch gesture on the trackpad | ||
* - alt: alt key | ||
* - meta: meta key | ||
* - none: none of these keys are pressed <ko>입력을 허용할 키 조합 목록 | ||
* - any: 아무 키 | ||
* - shift: shift 키 | ||
* - ctrl: ctrl 키 및 트랙패드의 pinch 제스쳐 | ||
* - alt: alt 키 | ||
* - meta: meta 키 | ||
* - none: 아무 키도 눌리지 않은 상태 </ko> | ||
* @param {Number} [scale=1] Coordinate scale that a user can move<ko>사용자의 동작으로 이동하는 좌표의 배율</ko> | ||
* @param {Number} [releaseDelay=300] Millisecond that trigger release event after last input<ko>마지막 입력 이후 release 이벤트가 트리거되기까지의 밀리초</ko> | ||
* @param {Boolean} [useNormalized=true] Whether to calculate scroll speed the same in all browsers<ko>모든 브라우저에서 스크롤 속도를 동일하게 처리할지 여부</ko> | ||
|
@@ -63,12 +78,11 @@ export class WheelInput implements InputType { | |
public constructor(el: ElementType, options?: WheelInputOption) { | ||
this.element = $(el); | ||
this.options = { | ||
...{ | ||
scale: 1, | ||
releaseDelay: 300, | ||
useNormalized: true, | ||
useAnimation: false, | ||
}, | ||
inputKey: [ANY], | ||
scale: 1, | ||
releaseDelay: 300, | ||
useNormalized: true, | ||
useAnimation: false, | ||
...options, | ||
}; | ||
this._onWheel = this._onWheel.bind(this); | ||
|
@@ -130,7 +144,7 @@ export class WheelInput implements InputType { | |
} | ||
|
||
private _onWheel(event: WheelEvent) { | ||
if (!this._enabled) { | ||
if (!this._enabled || !isValidKey(event, this.options.inputKey)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wheel will have to be careful. Multi-touch in the browser works with ctrl + wheel. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since ctrl + wheel also has a zoom function in the browser, it looks like it should be handled with |
||
return; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't every event valid when there're no items in
inputKey
andinputButton
in this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since array is type of object, an empty Array is conversed to true and
!inputButton
is conversed to false.The reason to check
!inputButton
here is thatinputButton
is optional like in the case of a pinch gesture where there is noinputButton
option.But for what you said, it seemed nice to add the case where
inputButton
is an empty array to the unit test, so I added it.