@syncfusion/ej2-base 24.2.7 → 25.1.35-579988
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +2 -1
- package/CHANGELOG.md +641 -677
- package/{README.md → ReadMe.md} +100 -100
- package/dist/ej2-base.umd.min.js +1 -10
- package/dist/ej2-base.umd.min.js.map +1 -1
- package/dist/es6/ej2-base.es2015.js +178 -1025
- package/dist/es6/ej2-base.es2015.js.map +1 -1
- package/dist/es6/ej2-base.es5.js +226 -934
- package/dist/es6/ej2-base.es5.js.map +1 -1
- package/dist/global/ej2-base.min.js +1 -10
- package/dist/global/ej2-base.min.js.map +1 -1
- package/dist/global/index.d.ts +0 -9
- package/dist/ts/ajax.ts +236 -0
- package/dist/ts/animation.ts +544 -0
- package/dist/ts/base.ts +357 -0
- package/dist/ts/browser.ts +387 -0
- package/dist/ts/child-property.ts +192 -0
- package/dist/ts/component.ts +519 -0
- package/dist/ts/dom.ts +488 -0
- package/dist/ts/draggable.ts +1155 -0
- package/dist/ts/droppable.ts +172 -0
- package/dist/ts/event-handler.ts +169 -0
- package/dist/ts/internationalization.ts +369 -0
- package/dist/ts/intl/date-formatter.ts +317 -0
- package/dist/ts/intl/date-parser.ts +426 -0
- package/dist/ts/intl/intl-base.ts +1104 -0
- package/dist/ts/intl/number-formatter.ts +411 -0
- package/dist/ts/intl/number-parser.ts +158 -0
- package/dist/ts/intl/parser-base.ts +394 -0
- package/dist/ts/keyboard.ts +238 -0
- package/dist/ts/l10n.ts +94 -0
- package/dist/ts/module-loader.ts +149 -0
- package/dist/ts/notify-property-change.ts +726 -0
- package/dist/ts/observer.ts +236 -0
- package/dist/ts/sanitize-helper.ts +224 -0
- package/dist/ts/template-engine.ts +191 -0
- package/dist/ts/template.ts +329 -0
- package/dist/ts/touch.ts +544 -0
- package/dist/ts/util.ts +523 -0
- package/dist/ts/validate-lic.ts +0 -0
- package/e2e/crypto.js +16 -16
- package/e2e/m.protractor.config.js +286 -286
- package/e2e/modified-protractor/protractor.config.js +316 -316
- package/e2e/protractor.config.js +389 -332
- package/helpers/e2e/index.js +3 -3
- package/license +10 -10
- package/package.json +225 -174
- package/src/ajax.d.ts +1 -1
- package/src/ajax.js +3 -8
- package/src/animation-model.d.ts +41 -41
- package/src/animation.d.ts +6 -6
- package/src/animation.js +25 -25
- package/src/base.d.ts +2 -1
- package/src/base.js +9 -7
- package/src/component-model.d.ts +16 -16
- package/src/component.d.ts +9 -3
- package/src/component.js +50 -38
- package/src/draggable-model.d.ts +113 -113
- package/src/draggable.d.ts +2 -0
- package/src/draggable.js +45 -29
- package/src/droppable-model.d.ts +23 -23
- package/src/droppable.js +19 -19
- package/src/event-handler.js +2 -1
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -3
- package/src/intl/date-formatter.js +2 -6
- package/src/intl/date-parser.js +1 -20
- package/src/intl/intl-base.js +1 -164
- package/src/intl/number-formatter.d.ts +3 -0
- package/src/intl/number-formatter.js +7 -7
- package/src/intl/number-parser.js +1 -0
- package/src/keyboard-model.d.ts +16 -16
- package/src/keyboard.js +19 -19
- package/src/module-loader.d.ts +12 -0
- package/src/module-loader.js +11 -0
- package/src/notify-property-change.js +3 -2
- package/src/observer.js +2 -0
- package/src/sanitize-helper.js +5 -0
- package/src/template-engine.js +1 -0
- package/src/template.js +3 -2
- package/src/touch-model.d.ts +39 -39
- package/src/touch.js +19 -19
- package/src/validate-lic.d.ts +0 -11
- package/src/validate-lic.js +1 -259
- package/styles/_all.scss +2 -2
- package/styles/_bds-dark-definition.scss +15 -0
- package/styles/_bds-definition.scss +15 -0
- package/styles/_bootstrap-dark-definition.scss +42 -42
- package/styles/_bootstrap-definition.scss +42 -42
- package/styles/_bootstrap4-definition.scss +11 -11
- package/styles/_bootstrap5-dark-definition.scss +9 -9
- package/styles/_bootstrap5-definition.scss +8 -8
- package/styles/_fabric-dark-definition.scss +42 -42
- package/styles/_fabric-definition.scss +42 -42
- package/styles/_fluent-dark-definition.scss +9 -9
- package/styles/_fluent-definition.scss +9 -9
- package/styles/_fluent2-definition.scss +9 -0
- package/styles/_fusionnew-dark-definition.scss +8 -8
- package/styles/_fusionnew-definition.scss +8 -8
- package/styles/_highcontrast-definition.scss +42 -42
- package/styles/_highcontrast-light-definition.scss +42 -42
- package/styles/_material-dark-definition.scss +48 -48
- package/styles/_material-definition.scss +49 -49
- package/styles/_material3-dark-definition.scss +14 -14
- package/styles/_material3-definition.scss +15 -15
- package/styles/_tailwind-dark-definition.scss +15 -15
- package/styles/_tailwind-definition.scss +15 -15
- package/styles/animation/_all.scss +560 -560
- package/styles/bootstrap-dark.css +10 -1
- package/styles/bootstrap.css +10 -1
- package/styles/bootstrap4.css +10 -1
- package/styles/bootstrap5-dark.css +10 -1
- package/styles/bootstrap5.css +10 -1
- package/styles/common/_all.scss +2 -2
- package/styles/common/_core.scss +117 -117
- package/styles/common/_mixin.scss +9 -9
- package/styles/definition/_bds-dark.scss +1179 -0
- package/styles/definition/_bds.scss +1474 -0
- package/styles/definition/_bootstrap-dark.scss +219 -219
- package/styles/definition/_bootstrap.scss +215 -215
- package/styles/definition/_bootstrap4.scss +167 -167
- package/styles/definition/_bootstrap5-dark.scss +493 -493
- package/styles/definition/_bootstrap5.scss +494 -494
- package/styles/definition/_fabric-dark.scss +200 -200
- package/styles/definition/_fabric.scss +198 -198
- package/styles/definition/_fluent-dark.scss +557 -557
- package/styles/definition/_fluent.scss +558 -558
- package/styles/definition/_fluent2.scss +2198 -0
- package/styles/definition/_fusionnew-dark.scss +362 -362
- package/styles/definition/_fusionnew.scss +363 -363
- package/styles/definition/_highcontrast-light.scss +193 -193
- package/styles/definition/_highcontrast.scss +195 -195
- package/styles/definition/_material-dark.scss +198 -198
- package/styles/definition/_material.scss +192 -192
- package/styles/definition/_material3-dark.scss +710 -710
- package/styles/definition/_material3.scss +792 -792
- package/styles/definition/_tailwind-dark.scss +488 -488
- package/styles/definition/_tailwind.scss +485 -485
- package/styles/fabric-dark.css +10 -1
- package/styles/fabric.css +10 -1
- package/styles/fluent-dark.css +10 -1
- package/styles/fluent.css +10 -1
- package/styles/highcontrast-light.css +10 -1
- package/styles/highcontrast.css +10 -1
- package/styles/material-dark.css +10 -1
- package/styles/material.css +10 -1
- package/styles/material3-dark.css +10 -1
- package/styles/material3.css +10 -1
- package/styles/offline-theme/material-dark.css +10 -1
- package/styles/offline-theme/material.css +10 -1
- package/styles/offline-theme/tailwind-dark.css +10 -1
- package/styles/offline-theme/tailwind.css +10 -1
- package/styles/tailwind-dark.css +10 -1
- package/styles/tailwind.css +10 -1
- package/.github/PULL_REQUEST_TEMPLATE/Bug.md +0 -60
- package/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -42
- package/bin/syncfusion-license.js +0 -2
- package/dist/ej2-base.min.js +0 -10
- package/e2e/index.d.ts +0 -27
- package/src/fetch.d.ts +0 -114
- package/src/fetch.js +0 -116
- package/src/hijri-parser.d.ts +0 -19
- package/src/hijri-parser.js +0 -204
package/dist/ts/touch.ts
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { extend } from './util';
|
|
2
|
+
import { Property, Complex, NotifyPropertyChanges, INotifyPropertyChanged, Event } from './notify-property-change';
|
|
3
|
+
import { Browser } from './browser';
|
|
4
|
+
import { Base, EmitType } from './base';
|
|
5
|
+
import { ChildProperty } from './child-property';
|
|
6
|
+
import { EventHandler, BaseEventArgs } from './event-handler';
|
|
7
|
+
import { TouchModel, SwipeSettingsModel } from './touch-model';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* SwipeSettings is a framework module that provides support to handle swipe event like swipe up, swipe right, etc..,
|
|
11
|
+
*/
|
|
12
|
+
export class SwipeSettings extends ChildProperty<SwipeSettings> {
|
|
13
|
+
/**
|
|
14
|
+
* Property specifies minimum distance of swipe moved.
|
|
15
|
+
*/
|
|
16
|
+
@Property(50)
|
|
17
|
+
public swipeThresholdDistance: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const swipeRegex: RegExp = /(Up|Down)/;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Touch class provides support to handle the touch event like tap, double tap, tap hold, etc..,
|
|
24
|
+
* ```typescript
|
|
25
|
+
* let node: HTMLElement;
|
|
26
|
+
* let touchObj: Touch = new Touch({
|
|
27
|
+
* element: node,
|
|
28
|
+
* tap: function (e) {
|
|
29
|
+
* // tap handler function code
|
|
30
|
+
* }
|
|
31
|
+
* tapHold: function (e) {
|
|
32
|
+
* // tap hold handler function code
|
|
33
|
+
* }
|
|
34
|
+
* scroll: function (e) {
|
|
35
|
+
* // scroll handler function code
|
|
36
|
+
* }
|
|
37
|
+
* swipe: function (e) {
|
|
38
|
+
* // swipe handler function code
|
|
39
|
+
* }
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
@NotifyPropertyChanges
|
|
44
|
+
export class Touch extends Base<HTMLElement> implements INotifyPropertyChanged {
|
|
45
|
+
|
|
46
|
+
//Internal Variables
|
|
47
|
+
private isTouchMoved: boolean;
|
|
48
|
+
private startPoint: Points;
|
|
49
|
+
private movedPoint: Points;
|
|
50
|
+
private endPoint: Points;
|
|
51
|
+
private startEventData: MouseEventArgs | TouchEventArgs;
|
|
52
|
+
private lastTapTime: number;
|
|
53
|
+
private lastMovedPoint: Points;
|
|
54
|
+
private scrollDirection: string;
|
|
55
|
+
private hScrollLocked: boolean;
|
|
56
|
+
private vScrollLocked: boolean;
|
|
57
|
+
private defaultArgs: TapEventArgs;
|
|
58
|
+
private distanceX: number;
|
|
59
|
+
private distanceY: number;
|
|
60
|
+
private movedDirection: string;
|
|
61
|
+
private tStampStart: number;
|
|
62
|
+
private touchAction: boolean = true;
|
|
63
|
+
// eslint-disable-next-line
|
|
64
|
+
private timeOutTap: any;
|
|
65
|
+
// eslint-disable-next-line
|
|
66
|
+
private modeClear: any;
|
|
67
|
+
// eslint-disable-next-line
|
|
68
|
+
private timeOutTapHold: any;
|
|
69
|
+
|
|
70
|
+
/* Properties */
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Specifies the callback function for tap event.
|
|
74
|
+
*
|
|
75
|
+
* @event tap
|
|
76
|
+
*/
|
|
77
|
+
@Event()
|
|
78
|
+
public tap: EmitType<TapEventArgs>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Specifies the callback function for tapHold event.
|
|
82
|
+
*
|
|
83
|
+
* @event tapHold
|
|
84
|
+
*/
|
|
85
|
+
@Event()
|
|
86
|
+
public tapHold: EmitType<TapEventArgs>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Specifies the callback function for swipe event.
|
|
90
|
+
*
|
|
91
|
+
* @event swipe
|
|
92
|
+
*/
|
|
93
|
+
@Event()
|
|
94
|
+
public swipe: EmitType<SwipeEventArgs>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Specifies the callback function for scroll event.
|
|
98
|
+
*
|
|
99
|
+
* @event scroll
|
|
100
|
+
*/
|
|
101
|
+
@Event()
|
|
102
|
+
public scroll: EmitType<ScrollEventArgs>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Specifies the time delay for tap.
|
|
106
|
+
*
|
|
107
|
+
* @default 350
|
|
108
|
+
*/
|
|
109
|
+
@Property(350)
|
|
110
|
+
public tapThreshold: number;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Specifies the time delay for tap hold.
|
|
114
|
+
*
|
|
115
|
+
* @default 750
|
|
116
|
+
*/
|
|
117
|
+
@Property(750)
|
|
118
|
+
public tapHoldThreshold: number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Customize the swipe event configuration.
|
|
122
|
+
*
|
|
123
|
+
* @default { swipeThresholdDistance: 50 }
|
|
124
|
+
*/
|
|
125
|
+
@Complex<SwipeSettingsModel>({}, SwipeSettings)
|
|
126
|
+
public swipeSettings: SwipeSettingsModel;
|
|
127
|
+
|
|
128
|
+
private tapCount: number = 0;
|
|
129
|
+
|
|
130
|
+
/* End-Properties */
|
|
131
|
+
constructor(element: HTMLElement, options?: TouchModel) {
|
|
132
|
+
super(options, element);
|
|
133
|
+
this.bind();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// triggers when property changed
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @private
|
|
140
|
+
* @param {TouchModel} newProp ?
|
|
141
|
+
* @param {TouchModel} oldProp ?
|
|
142
|
+
* @returns {void} ?
|
|
143
|
+
*/
|
|
144
|
+
// eslint-disable-next-line
|
|
145
|
+
public onPropertyChanged(newProp: TouchModel, oldProp: TouchModel): void {
|
|
146
|
+
//No Code to handle
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected bind(): void {
|
|
150
|
+
this.wireEvents();
|
|
151
|
+
if (Browser.isIE) { this.element.classList.add('e-block-touch'); }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* To destroy the touch instance.
|
|
156
|
+
*
|
|
157
|
+
* @returns {void}
|
|
158
|
+
*/
|
|
159
|
+
public destroy(): void {
|
|
160
|
+
this.unwireEvents();
|
|
161
|
+
super.destroy();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Need to changes the event binding once we updated the event handler.
|
|
165
|
+
private wireEvents(): void {
|
|
166
|
+
EventHandler.add(this.element, Browser.touchStartEvent, this.startEvent, this);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private unwireEvents(): void {
|
|
170
|
+
EventHandler.remove(this.element, Browser.touchStartEvent, this.startEvent);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Returns module name as touch
|
|
175
|
+
*
|
|
176
|
+
* @returns {string} ?
|
|
177
|
+
* @private
|
|
178
|
+
*/
|
|
179
|
+
public getModuleName(): string {
|
|
180
|
+
return 'touch';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Returns if the HTML element is Scrollable.
|
|
185
|
+
*
|
|
186
|
+
* @param {HTMLElement} element - HTML Element to check if Scrollable.
|
|
187
|
+
* @returns {boolean} ?
|
|
188
|
+
*/
|
|
189
|
+
private isScrollable(element: HTMLElement): boolean {
|
|
190
|
+
const eleStyle: CSSStyleDeclaration = getComputedStyle(element);
|
|
191
|
+
const style: string = eleStyle.overflow + eleStyle.overflowX + eleStyle.overflowY;
|
|
192
|
+
if ((/(auto|scroll)/).test(style)) { return true; }
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* @param {MouseEventArgs | TouchEventArgs} evt ?
|
|
199
|
+
* @returns {void} ?
|
|
200
|
+
*/
|
|
201
|
+
private startEvent: Function = (evt: MouseEventArgs | TouchEventArgs): void => {
|
|
202
|
+
if (this.touchAction === true) {
|
|
203
|
+
const point: MouseEventArgs | TouchEventArgs = this.updateChangeTouches(evt);
|
|
204
|
+
if (evt.changedTouches !== undefined) {
|
|
205
|
+
this.touchAction = false;
|
|
206
|
+
}
|
|
207
|
+
this.isTouchMoved = false;
|
|
208
|
+
this.movedDirection = '';
|
|
209
|
+
this.startPoint = this.lastMovedPoint = { clientX: point.clientX, clientY: point.clientY };
|
|
210
|
+
this.startEventData = point;
|
|
211
|
+
this.hScrollLocked = this.vScrollLocked = false;
|
|
212
|
+
this.tStampStart = Date.now();
|
|
213
|
+
this.timeOutTapHold = setTimeout(() => { this.tapHoldEvent(evt); }, this.tapHoldThreshold);
|
|
214
|
+
EventHandler.add(this.element, Browser.touchMoveEvent, this.moveEvent, this);
|
|
215
|
+
EventHandler.add(this.element, Browser.touchEndEvent, this.endEvent, this);
|
|
216
|
+
EventHandler.add(this.element, Browser.touchCancelEvent, this.cancelEvent, this);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
*
|
|
222
|
+
* @param {MouseEventArgs | TouchEventArgs} evt ?
|
|
223
|
+
* @returns {void} ?
|
|
224
|
+
*/
|
|
225
|
+
private moveEvent: Function = (evt: MouseEventArgs | TouchEventArgs): void => {
|
|
226
|
+
const point: MouseEventArgs | TouchEventArgs = this.updateChangeTouches(evt);
|
|
227
|
+
this.movedPoint = point;
|
|
228
|
+
this.isTouchMoved = !(point.clientX === this.startPoint.clientX && point.clientY === this.startPoint.clientY);
|
|
229
|
+
let eScrollArgs: Object = {};
|
|
230
|
+
if (this.isTouchMoved) {
|
|
231
|
+
clearTimeout(this.timeOutTapHold);
|
|
232
|
+
this.calcScrollPoints(evt);
|
|
233
|
+
const scrollArg: ScrollEventArgs = {
|
|
234
|
+
startEvents: this.startEventData,
|
|
235
|
+
originalEvent: evt, startX: this.startPoint.clientX,
|
|
236
|
+
startY: this.startPoint.clientY, distanceX: this.distanceX,
|
|
237
|
+
distanceY: this.distanceY, scrollDirection: this.scrollDirection,
|
|
238
|
+
velocity: this.getVelocity(point)
|
|
239
|
+
};
|
|
240
|
+
eScrollArgs = extend(eScrollArgs, {}, scrollArg);
|
|
241
|
+
this.trigger('scroll', eScrollArgs);
|
|
242
|
+
this.lastMovedPoint = { clientX: point.clientX, clientY: point.clientY };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
*
|
|
248
|
+
* @param {MouseEventArgs | TouchEventArgs} evt ?
|
|
249
|
+
* @returns {void} ?
|
|
250
|
+
*/
|
|
251
|
+
private cancelEvent: Function = (evt: MouseEventArgs | TouchEventArgs): void => {
|
|
252
|
+
clearTimeout(this.timeOutTapHold);
|
|
253
|
+
clearTimeout(this.timeOutTap);
|
|
254
|
+
this.tapCount = 0;
|
|
255
|
+
this.swipeFn(evt);
|
|
256
|
+
EventHandler.remove(this.element, Browser.touchCancelEvent, this.cancelEvent);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @param {MouseEventArgs | TouchEventArgs} evt ?
|
|
262
|
+
* @returns {void} ?
|
|
263
|
+
*/
|
|
264
|
+
private tapHoldEvent(evt: MouseEvent | TouchEventArgs): void {
|
|
265
|
+
this.tapCount = 0;
|
|
266
|
+
this.touchAction = true;
|
|
267
|
+
let eTapArgs: TapEventArgs;
|
|
268
|
+
EventHandler.remove(this.element, Browser.touchMoveEvent, this.moveEvent);
|
|
269
|
+
EventHandler.remove(this.element, Browser.touchEndEvent, this.endEvent);
|
|
270
|
+
// eslint-disable-next-line
|
|
271
|
+
eTapArgs = { originalEvent: <TouchEventArgs>evt };
|
|
272
|
+
this.trigger('tapHold', eTapArgs);
|
|
273
|
+
EventHandler.remove(this.element, Browser.touchCancelEvent, this.cancelEvent);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
* @param {MouseEventArgs | TouchEventArgs} evt ?
|
|
279
|
+
* @returns {void} ?
|
|
280
|
+
*/
|
|
281
|
+
private endEvent: Function = (evt: MouseEventArgs | TouchEventArgs): void => {
|
|
282
|
+
this.swipeFn(evt);
|
|
283
|
+
if (!this.isTouchMoved) {
|
|
284
|
+
if (typeof this.tap === 'function') {
|
|
285
|
+
this.trigger('tap', { originalEvent: evt, tapCount: ++this.tapCount });
|
|
286
|
+
this.timeOutTap = setTimeout(
|
|
287
|
+
() => {
|
|
288
|
+
this.tapCount = 0;
|
|
289
|
+
},
|
|
290
|
+
this.tapThreshold);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
this.modeclear();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
*
|
|
298
|
+
* @param {MouseEventArgs | TouchEventArgs} evt ?
|
|
299
|
+
* @returns {void} ?
|
|
300
|
+
*/
|
|
301
|
+
private swipeFn: Function = (evt: MouseEventArgs | TouchEventArgs): void => {
|
|
302
|
+
clearTimeout(this.timeOutTapHold);
|
|
303
|
+
clearTimeout(this.timeOutTap);
|
|
304
|
+
const point: MouseEventArgs | TouchEventArgs = this.updateChangeTouches(evt);
|
|
305
|
+
let diffX: number = point.clientX - this.startPoint.clientX;
|
|
306
|
+
let diffY: number = point.clientY - this.startPoint.clientY;
|
|
307
|
+
diffX = Math.floor(diffX < 0 ? -1 * diffX : diffX);
|
|
308
|
+
diffY = Math.floor(diffY < 0 ? -1 * diffY : diffX);
|
|
309
|
+
this.isTouchMoved = diffX > 1 || diffY > 1;
|
|
310
|
+
const isFirefox: boolean = (/Firefox/).test(Browser.userAgent);
|
|
311
|
+
if (isFirefox && point.clientX === 0 && point.clientY === 0 && evt.type === 'mouseup') {
|
|
312
|
+
this.isTouchMoved = false;
|
|
313
|
+
}
|
|
314
|
+
this.endPoint = point;
|
|
315
|
+
this.calcPoints(evt);
|
|
316
|
+
const swipeArgs: SwipeEventArgs = {
|
|
317
|
+
originalEvent: evt,
|
|
318
|
+
startEvents: this.startEventData,
|
|
319
|
+
startX: this.startPoint.clientX,
|
|
320
|
+
startY: this.startPoint.clientY,
|
|
321
|
+
distanceX: this.distanceX, distanceY:
|
|
322
|
+
this.distanceY, swipeDirection: this.movedDirection,
|
|
323
|
+
velocity: this.getVelocity(point)
|
|
324
|
+
};
|
|
325
|
+
if (this.isTouchMoved) {
|
|
326
|
+
let eSwipeArgs: Object;
|
|
327
|
+
const tDistance: number = this.swipeSettings.swipeThresholdDistance;
|
|
328
|
+
// eslint-disable-next-line
|
|
329
|
+
eSwipeArgs = extend(eSwipeArgs, this.defaultArgs, swipeArgs);
|
|
330
|
+
let canTrigger: boolean = false;
|
|
331
|
+
const ele: HTMLElement = this.element;
|
|
332
|
+
const scrollBool: boolean = this.isScrollable(ele);
|
|
333
|
+
const moved: boolean = swipeRegex.test(this.movedDirection);
|
|
334
|
+
if ((tDistance < this.distanceX && !moved) || (tDistance < this.distanceY && moved)) {
|
|
335
|
+
if (!scrollBool) {
|
|
336
|
+
canTrigger = true;
|
|
337
|
+
} else {
|
|
338
|
+
canTrigger = this.checkSwipe(ele, moved);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (canTrigger) {
|
|
342
|
+
this.trigger('swipe', eSwipeArgs);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
this.modeclear();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
private modeclear: Function = (): void => {
|
|
349
|
+
this.modeClear = setTimeout(
|
|
350
|
+
() => {
|
|
351
|
+
this.touchAction = true;
|
|
352
|
+
},
|
|
353
|
+
(typeof this.tap !== 'function' ? 0 : 20));
|
|
354
|
+
this.lastTapTime = new Date().getTime();
|
|
355
|
+
EventHandler.remove(this.element, Browser.touchMoveEvent, this.moveEvent);
|
|
356
|
+
EventHandler.remove(this.element, Browser.touchEndEvent, this.endEvent);
|
|
357
|
+
EventHandler.remove(this.element, Browser.touchCancelEvent, this.cancelEvent);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private calcPoints(evt: MouseEventArgs | TouchEventArgs): void {
|
|
361
|
+
const point: MouseEventArgs | TouchEventArgs = this.updateChangeTouches(evt);
|
|
362
|
+
this.defaultArgs = { originalEvent: evt };
|
|
363
|
+
this.distanceX = Math.abs((Math.abs(point.clientX) - Math.abs(this.startPoint.clientX)));
|
|
364
|
+
this.distanceY = Math.abs((Math.abs(point.clientY) - Math.abs(this.startPoint.clientY)));
|
|
365
|
+
if (this.distanceX > this.distanceY) {
|
|
366
|
+
this.movedDirection = (point.clientX > this.startPoint.clientX) ? 'Right' : 'Left';
|
|
367
|
+
} else {
|
|
368
|
+
this.movedDirection = (point.clientY < this.startPoint.clientY) ? 'Up' : 'Down';
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private calcScrollPoints(evt: MouseEventArgs | TouchEventArgs): void {
|
|
373
|
+
const point: MouseEventArgs | TouchEventArgs = this.updateChangeTouches(evt);
|
|
374
|
+
this.defaultArgs = { originalEvent: evt };
|
|
375
|
+
this.distanceX = Math.abs((Math.abs(point.clientX) - Math.abs(this.lastMovedPoint.clientX)));
|
|
376
|
+
this.distanceY = Math.abs((Math.abs(point.clientY) - Math.abs(this.lastMovedPoint.clientY)));
|
|
377
|
+
if ((this.distanceX > this.distanceY || this.hScrollLocked === true) && this.vScrollLocked === false) {
|
|
378
|
+
this.scrollDirection = (point.clientX > this.lastMovedPoint.clientX) ? 'Right' : 'Left';
|
|
379
|
+
this.hScrollLocked = true;
|
|
380
|
+
} else {
|
|
381
|
+
this.scrollDirection = (point.clientY < this.lastMovedPoint.clientY) ? 'Up' : 'Down';
|
|
382
|
+
this.vScrollLocked = true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
private getVelocity(pnt: MouseEventArgs | TouchEventArgs): number {
|
|
387
|
+
const newX: number = pnt.clientX;
|
|
388
|
+
const newY: number = pnt.clientY;
|
|
389
|
+
const newT: number = Date.now();
|
|
390
|
+
const xDist: number = newX - this.startPoint.clientX;
|
|
391
|
+
const yDist: number = newY - this.startPoint.clientX;
|
|
392
|
+
const interval: number = newT - this.tStampStart;
|
|
393
|
+
return Math.sqrt(xDist * xDist + yDist * yDist) / interval;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// eslint-disable-next-line
|
|
397
|
+
private checkSwipe(ele: any, flag: boolean): boolean {
|
|
398
|
+
const keys: string[] = ['scroll', 'offset'];
|
|
399
|
+
const temp: string[] = flag ? ['Height', 'Top'] : ['Width', 'Left'];
|
|
400
|
+
if ((ele[keys[0] + temp[0]] <= ele[keys[1] + temp[0]])) {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
return (ele[keys[0] + temp[1]] === 0) ||
|
|
404
|
+
(ele[keys[1] + temp[0]] + ele[keys[0] + temp[1]] >= ele[keys[0] + temp[0]]);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private updateChangeTouches(evt: MouseEventArgs | TouchEventArgs): MouseEventArgs | TouchEventArgs {
|
|
408
|
+
const point: MouseEventArgs | TouchEventArgs = evt.changedTouches && evt.changedTouches.length !== 0 ? evt.changedTouches[0] : evt;
|
|
409
|
+
return point;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface Points {
|
|
414
|
+
clientX: number;
|
|
415
|
+
clientY: number;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* The argument type of `Tap` Event
|
|
420
|
+
*/
|
|
421
|
+
export interface TapEventArgs extends BaseEventArgs {
|
|
422
|
+
/**
|
|
423
|
+
* Original native event Object.
|
|
424
|
+
*/
|
|
425
|
+
originalEvent: TouchEventArgs | MouseEventArgs;
|
|
426
|
+
/**
|
|
427
|
+
* Tap Count.
|
|
428
|
+
*/
|
|
429
|
+
tapCount?: number;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* The argument type of `Scroll` Event
|
|
434
|
+
*/
|
|
435
|
+
export interface ScrollEventArgs extends BaseEventArgs {
|
|
436
|
+
/**
|
|
437
|
+
* Event argument for start event.
|
|
438
|
+
*/
|
|
439
|
+
startEvents: TouchEventArgs | MouseEventArgs;
|
|
440
|
+
/**
|
|
441
|
+
* Original native event object for scroll.
|
|
442
|
+
*/
|
|
443
|
+
originalEvent: TouchEventArgs | MouseEventArgs;
|
|
444
|
+
/**
|
|
445
|
+
* X position when scroll started.
|
|
446
|
+
*/
|
|
447
|
+
startX: number;
|
|
448
|
+
/**
|
|
449
|
+
* Y position when scroll started.
|
|
450
|
+
*/
|
|
451
|
+
startY: number;
|
|
452
|
+
/**
|
|
453
|
+
* The direction scroll.
|
|
454
|
+
*/
|
|
455
|
+
scrollDirection: string;
|
|
456
|
+
/**
|
|
457
|
+
* The total traveled distance from X position
|
|
458
|
+
*/
|
|
459
|
+
distanceX: number;
|
|
460
|
+
/**
|
|
461
|
+
* The total traveled distance from Y position
|
|
462
|
+
*/
|
|
463
|
+
distanceY: number;
|
|
464
|
+
/**
|
|
465
|
+
* The velocity of scroll.
|
|
466
|
+
*/
|
|
467
|
+
velocity: number;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* The argument type of `Swipe` Event
|
|
472
|
+
*/
|
|
473
|
+
export interface SwipeEventArgs extends BaseEventArgs {
|
|
474
|
+
/**
|
|
475
|
+
* Event argument for start event.
|
|
476
|
+
*/
|
|
477
|
+
startEvents: TouchEventArgs | MouseEventArgs;
|
|
478
|
+
/**
|
|
479
|
+
* Original native event object for swipe.
|
|
480
|
+
*/
|
|
481
|
+
originalEvent: TouchEventArgs | MouseEventArgs;
|
|
482
|
+
/**
|
|
483
|
+
* X position when swipe started.
|
|
484
|
+
*/
|
|
485
|
+
startX: number;
|
|
486
|
+
/**
|
|
487
|
+
* Y position when swipe started.
|
|
488
|
+
*/
|
|
489
|
+
startY: number;
|
|
490
|
+
/**
|
|
491
|
+
* The direction swipe.
|
|
492
|
+
*/
|
|
493
|
+
swipeDirection: string;
|
|
494
|
+
/**
|
|
495
|
+
* The total traveled distance from X position
|
|
496
|
+
*/
|
|
497
|
+
distanceX: number;
|
|
498
|
+
/**
|
|
499
|
+
* The total traveled distance from Y position
|
|
500
|
+
*/
|
|
501
|
+
distanceY: number;
|
|
502
|
+
/**
|
|
503
|
+
* The velocity of swipe.
|
|
504
|
+
*/
|
|
505
|
+
velocity: number;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export interface TouchEventArgs extends MouseEvent {
|
|
509
|
+
/**
|
|
510
|
+
* A TouchList with touched points.
|
|
511
|
+
*/
|
|
512
|
+
changedTouches: MouseEventArgs[] | TouchEventArgs[];
|
|
513
|
+
/**
|
|
514
|
+
* Cancel the default action.
|
|
515
|
+
*/
|
|
516
|
+
preventDefault(): void;
|
|
517
|
+
/**
|
|
518
|
+
* The horizontal coordinate point of client area.
|
|
519
|
+
*/
|
|
520
|
+
clientX: number;
|
|
521
|
+
/**
|
|
522
|
+
* The vertical coordinate point of client area.
|
|
523
|
+
*/
|
|
524
|
+
clientY: number;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export interface MouseEventArgs extends MouseEvent {
|
|
528
|
+
/**
|
|
529
|
+
* A TouchList with touched points.
|
|
530
|
+
*/
|
|
531
|
+
changedTouches: MouseEventArgs[] | TouchEventArgs[];
|
|
532
|
+
/**
|
|
533
|
+
* Cancel the default action.
|
|
534
|
+
*/
|
|
535
|
+
preventDefault(): void;
|
|
536
|
+
/**
|
|
537
|
+
* The horizontal coordinate point of client area.
|
|
538
|
+
*/
|
|
539
|
+
clientX: number;
|
|
540
|
+
/**
|
|
541
|
+
* The vertical coordinate point of client area.
|
|
542
|
+
*/
|
|
543
|
+
clientY: number;
|
|
544
|
+
}
|