uicore-ts 1.0.1
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/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/uicore.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/compiledScripts/UIActionIndicator.d.ts +12 -0
- package/compiledScripts/UIActionIndicator.js +54 -0
- package/compiledScripts/UIActionIndicator.js.map +1 -0
- package/compiledScripts/UIBaseButton.d.ts +52 -0
- package/compiledScripts/UIBaseButton.js +268 -0
- package/compiledScripts/UIBaseButton.js.map +1 -0
- package/compiledScripts/UIButton.d.ts +54 -0
- package/compiledScripts/UIButton.js +247 -0
- package/compiledScripts/UIButton.js.map +1 -0
- package/compiledScripts/UIColor.d.ts +41 -0
- package/compiledScripts/UIColor.js +286 -0
- package/compiledScripts/UIColor.js.map +1 -0
- package/compiledScripts/UICore.d.ts +27 -0
- package/compiledScripts/UICore.js +105 -0
- package/compiledScripts/UICore.js.map +1 -0
- package/compiledScripts/UICoreExtensions.d.ts +60 -0
- package/compiledScripts/UICoreExtensions.js +527 -0
- package/compiledScripts/UICoreExtensions.js.map +1 -0
- package/compiledScripts/UIDateTimeInput.d.ts +40 -0
- package/compiledScripts/UIDateTimeInput.js +38 -0
- package/compiledScripts/UIDateTimeInput.js.map +1 -0
- package/compiledScripts/UIDialogView.d.ts +23 -0
- package/compiledScripts/UIDialogView.js +118 -0
- package/compiledScripts/UIDialogView.js.map +1 -0
- package/compiledScripts/UIImageView.d.ts +36 -0
- package/compiledScripts/UIImageView.js +170 -0
- package/compiledScripts/UIImageView.js.map +1 -0
- package/compiledScripts/UIKeyValueStringFilter.d.ts +21 -0
- package/compiledScripts/UIKeyValueStringFilter.js +98 -0
- package/compiledScripts/UIKeyValueStringFilter.js.map +1 -0
- package/compiledScripts/UIKeyValueStringSorter.d.ts +38 -0
- package/compiledScripts/UIKeyValueStringSorter.js +117 -0
- package/compiledScripts/UIKeyValueStringSorter.js.map +1 -0
- package/compiledScripts/UILayoutGrid.d.ts +8 -0
- package/compiledScripts/UILayoutGrid.js +22 -0
- package/compiledScripts/UILayoutGrid.js.map +1 -0
- package/compiledScripts/UILink.d.ts +25 -0
- package/compiledScripts/UILink.js +81 -0
- package/compiledScripts/UILink.js.map +1 -0
- package/compiledScripts/UILinkButton.d.ts +18 -0
- package/compiledScripts/UILinkButton.js +60 -0
- package/compiledScripts/UILinkButton.js.map +1 -0
- package/compiledScripts/UINativeScrollView.d.ts +20 -0
- package/compiledScripts/UINativeScrollView.js +121 -0
- package/compiledScripts/UINativeScrollView.js.map +1 -0
- package/compiledScripts/UIObject.d.ts +69 -0
- package/compiledScripts/UIObject.js +442 -0
- package/compiledScripts/UIObject.js.map +1 -0
- package/compiledScripts/UIPoint.d.ts +18 -0
- package/compiledScripts/UIPoint.js +68 -0
- package/compiledScripts/UIPoint.js.map +1 -0
- package/compiledScripts/UIRectangle.d.ts +61 -0
- package/compiledScripts/UIRectangle.js +421 -0
- package/compiledScripts/UIRectangle.js.map +1 -0
- package/compiledScripts/UIRoute.d.ts +39 -0
- package/compiledScripts/UIRoute.js +202 -0
- package/compiledScripts/UIRoute.js.map +1 -0
- package/compiledScripts/UIScrollView.d.ts +19 -0
- package/compiledScripts/UIScrollView.js +121 -0
- package/compiledScripts/UIScrollView.js.map +1 -0
- package/compiledScripts/UISlideScrollerView.d.ts +40 -0
- package/compiledScripts/UISlideScrollerView.js +242 -0
- package/compiledScripts/UISlideScrollerView.js.map +1 -0
- package/compiledScripts/UIStringFilter.d.ts +26 -0
- package/compiledScripts/UIStringFilter.js +107 -0
- package/compiledScripts/UIStringFilter.js.map +1 -0
- package/compiledScripts/UITableView.d.ts +61 -0
- package/compiledScripts/UITableView.js +383 -0
- package/compiledScripts/UITableView.js.map +1 -0
- package/compiledScripts/UITextArea.d.ts +7 -0
- package/compiledScripts/UITextArea.js +27 -0
- package/compiledScripts/UITextArea.js.map +1 -0
- package/compiledScripts/UITextField.d.ts +44 -0
- package/compiledScripts/UITextField.js +83 -0
- package/compiledScripts/UITextField.js.map +1 -0
- package/compiledScripts/UITextView.d.ts +89 -0
- package/compiledScripts/UITextView.js +237 -0
- package/compiledScripts/UITextView.js.map +1 -0
- package/compiledScripts/UITimer.d.ts +13 -0
- package/compiledScripts/UITimer.js +45 -0
- package/compiledScripts/UITimer.js.map +1 -0
- package/compiledScripts/UIView.d.ts +330 -0
- package/compiledScripts/UIView.js +1533 -0
- package/compiledScripts/UIView.js.map +1 -0
- package/compiledScripts/UIViewController.d.ts +38 -0
- package/compiledScripts/UIViewController.js +153 -0
- package/compiledScripts/UIViewController.js.map +1 -0
- package/compiledScripts/index.d.ts +29 -0
- package/compiledScripts/index.js +46 -0
- package/compiledScripts/index.js.map +1 -0
- package/package.json +36 -0
- package/scripts/UIActionIndicator.ts +139 -0
- package/scripts/UIBaseButton.ts +563 -0
- package/scripts/UIButton.ts +552 -0
- package/scripts/UIColor.ts +427 -0
- package/scripts/UICore.ts +223 -0
- package/scripts/UICoreExtensions.ts +949 -0
- package/scripts/UIDateTimeInput.ts +109 -0
- package/scripts/UIDialogView.ts +297 -0
- package/scripts/UIImageView.ts +366 -0
- package/scripts/UIKeyValueStringFilter.ts +260 -0
- package/scripts/UIKeyValueStringSorter.ts +337 -0
- package/scripts/UILayoutGrid.ts +83 -0
- package/scripts/UILink.ts +292 -0
- package/scripts/UILinkButton.ts +238 -0
- package/scripts/UINativeScrollView.ts +254 -0
- package/scripts/UIObject.ts +827 -0
- package/scripts/UIPoint.ts +123 -0
- package/scripts/UIRectangle.ts +730 -0
- package/scripts/UIRoute.ts +391 -0
- package/scripts/UIScrollView.ts +290 -0
- package/scripts/UISlideScrollerView.ts +530 -0
- package/scripts/UIStringFilter.ts +293 -0
- package/scripts/UITableView.ts +790 -0
- package/scripts/UITextArea.ts +91 -0
- package/scripts/UITextField.ts +218 -0
- package/scripts/UITextView.ts +561 -0
- package/scripts/UITimer.ts +107 -0
- package/scripts/UIView.ts +2789 -0
- package/scripts/UIViewController.ts +304 -0
- package/scripts/index.ts +36 -0
- package/tsconfig.json +59 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { UIButton } from "./UIButton"
|
|
2
|
+
import { UIColor } from "./UIColor"
|
|
3
|
+
import { IS, nil, NO, YES } from "./UIObject"
|
|
4
|
+
import { UIView, UIViewBroadcastEvent } from "./UIView"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export class UIBaseButton extends UIView {
|
|
11
|
+
|
|
12
|
+
_selected: boolean = NO
|
|
13
|
+
_highlighted: boolean = NO
|
|
14
|
+
|
|
15
|
+
_isPointerInside: boolean
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_isToggleable: boolean = NO
|
|
19
|
+
_hovered: boolean
|
|
20
|
+
_focused: boolean
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
constructor(elementID: string, elementType?: string, initViewData?: any) {
|
|
27
|
+
|
|
28
|
+
super(elementID, nil, elementType, initViewData)
|
|
29
|
+
|
|
30
|
+
this._class = UIButton
|
|
31
|
+
this.superclass = UIView
|
|
32
|
+
|
|
33
|
+
this.initViewStateControl()
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
initViewStateControl() {
|
|
42
|
+
|
|
43
|
+
this.class.superclass = UIView
|
|
44
|
+
|
|
45
|
+
// Instance variables
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
this._isPointerInside = NO
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const setHovered = function () {
|
|
52
|
+
this.hovered = YES
|
|
53
|
+
}.bind(this)
|
|
54
|
+
this.addTargetForControlEvent(UIView.controlEvent.PointerHover, setHovered)
|
|
55
|
+
|
|
56
|
+
const setNotHovered = function () {
|
|
57
|
+
|
|
58
|
+
this.hovered = NO
|
|
59
|
+
|
|
60
|
+
}.bind(this)
|
|
61
|
+
|
|
62
|
+
this.addTargetForControlEvents([
|
|
63
|
+
UIView.controlEvent.PointerLeave, UIView.controlEvent.PointerCancel, UIView.controlEvent.MultipleTouches
|
|
64
|
+
], setNotHovered)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
var highlightingTime
|
|
68
|
+
const setHighlighted = function () {
|
|
69
|
+
this.highlighted = YES
|
|
70
|
+
highlightingTime = Date.now()
|
|
71
|
+
}.bind(this)
|
|
72
|
+
this.addTargetForControlEvent(UIView.controlEvent.PointerDown, setHighlighted)
|
|
73
|
+
this.addTargetForControlEvent(UIView.controlEvent.PointerEnter, setHighlighted)
|
|
74
|
+
|
|
75
|
+
const setNotHighlighted = function () {
|
|
76
|
+
this.highlighted = NO
|
|
77
|
+
}.bind(this)
|
|
78
|
+
const setNotHighlightedWithMinimumDuration = function () {
|
|
79
|
+
const minimumDurationInMilliseconds = 50
|
|
80
|
+
const elapsedTime = Date.now() - highlightingTime
|
|
81
|
+
if (minimumDurationInMilliseconds < elapsedTime) {
|
|
82
|
+
this.highlighted = NO
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
setTimeout(function () {
|
|
86
|
+
this.highlighted = NO
|
|
87
|
+
}.bind(this), minimumDurationInMilliseconds - elapsedTime)
|
|
88
|
+
}
|
|
89
|
+
}.bind(this)
|
|
90
|
+
this.addTargetForControlEvents([
|
|
91
|
+
UIView.controlEvent.PointerLeave, UIView.controlEvent.PointerCancel, UIView.controlEvent.MultipleTouches
|
|
92
|
+
], setNotHighlighted)
|
|
93
|
+
this.addTargetForControlEvent(UIView.controlEvent.PointerUp, setNotHighlightedWithMinimumDuration)
|
|
94
|
+
|
|
95
|
+
// Handle enter key press
|
|
96
|
+
this.addTargetForControlEvent(UIView.controlEvent.EnterDown, function () {
|
|
97
|
+
|
|
98
|
+
setHighlighted()
|
|
99
|
+
setNotHighlightedWithMinimumDuration()
|
|
100
|
+
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
this.addTargetForControlEvent(
|
|
105
|
+
UIView.controlEvent.Focus,
|
|
106
|
+
function (this: UIBaseButton, sender: UIView, event: Event) {
|
|
107
|
+
|
|
108
|
+
this.focused = YES
|
|
109
|
+
|
|
110
|
+
}.bind(this)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
this.addTargetForControlEvent(
|
|
114
|
+
UIView.controlEvent.Blur,
|
|
115
|
+
function (this: UIBaseButton, sender: UIView, event: Event) {
|
|
116
|
+
|
|
117
|
+
this.focused = NO
|
|
118
|
+
|
|
119
|
+
}.bind(this)
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
this.updateContentForCurrentState()
|
|
124
|
+
|
|
125
|
+
this.pausesPointerEvents = YES
|
|
126
|
+
this.tabIndex = 1
|
|
127
|
+
|
|
128
|
+
this.style.cursor = "pointer"
|
|
129
|
+
|
|
130
|
+
//this.style.outline = "none";
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
this.nativeSelectionEnabled = NO
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
this.addTargetForControlEvents([
|
|
137
|
+
UIView.controlEvent.EnterDown, UIView.controlEvent.PointerUpInside
|
|
138
|
+
], function (this: UIBaseButton, sender, event) {
|
|
139
|
+
|
|
140
|
+
if (this.isToggleable) {
|
|
141
|
+
|
|
142
|
+
this.toggleSelectedState()
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
}.bind(this))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
public set hovered(hovered: boolean) {
|
|
156
|
+
this._hovered = hovered
|
|
157
|
+
this.updateContentForCurrentState()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public get hovered(): boolean {
|
|
161
|
+
return this._hovered
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public set highlighted(highlighted: boolean) {
|
|
165
|
+
this._highlighted = highlighted
|
|
166
|
+
this.updateContentForCurrentState()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public get highlighted(): boolean {
|
|
170
|
+
return this._highlighted
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public set focused(focused: boolean) {
|
|
174
|
+
this._focused = focused
|
|
175
|
+
if (focused) {
|
|
176
|
+
this.focus()
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.blur()
|
|
180
|
+
}
|
|
181
|
+
this.updateContentForCurrentState()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public get focused(): boolean {
|
|
185
|
+
return this._focused
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public set selected(selected: boolean) {
|
|
189
|
+
this._selected = selected
|
|
190
|
+
this.updateContentForCurrentState()
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public get selected(): boolean {
|
|
194
|
+
return this._selected
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
updateContentForCurrentState() {
|
|
202
|
+
|
|
203
|
+
var updateFunction: Function = this.updateContentForNormalState
|
|
204
|
+
if (this.selected && this.highlighted) {
|
|
205
|
+
updateFunction = this.updateContentForSelectedAndHighlightedState
|
|
206
|
+
}
|
|
207
|
+
else if (this.selected) {
|
|
208
|
+
updateFunction = this.updateContentForSelectedState
|
|
209
|
+
}
|
|
210
|
+
else if (this.focused) {
|
|
211
|
+
updateFunction = this.updateContentForFocusedState
|
|
212
|
+
}
|
|
213
|
+
else if (this.highlighted) {
|
|
214
|
+
updateFunction = this.updateContentForHighlightedState
|
|
215
|
+
}
|
|
216
|
+
else if (this.hovered) {
|
|
217
|
+
updateFunction = this.updateContentForHoveredState
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (!IS(updateFunction)) {
|
|
221
|
+
this.backgroundColor = UIColor.nilColor
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
updateFunction.call(this)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
updateContentForNormalState() {
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
updateContentForHoveredState() {
|
|
236
|
+
|
|
237
|
+
this.updateContentForNormalState()
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
updateContentForFocusedState() {
|
|
242
|
+
|
|
243
|
+
this.updateContentForHoveredState()
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
updateContentForHighlightedState() {
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
updateContentForSelectedState() {
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
updateContentForSelectedAndHighlightedState() {
|
|
260
|
+
|
|
261
|
+
this.updateContentForSelectedState()
|
|
262
|
+
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
set enabled(enabled: boolean) {
|
|
267
|
+
|
|
268
|
+
super.enabled = enabled
|
|
269
|
+
|
|
270
|
+
this.updateContentForCurrentEnabledState()
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
get enabled() {
|
|
275
|
+
|
|
276
|
+
return super.enabled
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
updateContentForCurrentEnabledState() {
|
|
281
|
+
|
|
282
|
+
if (this.enabled) {
|
|
283
|
+
this.alpha = 1
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
this.alpha = 0.5
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
this.userInteractionEnabled = this.enabled
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
addStyleClass(styleClassName: string) {
|
|
296
|
+
|
|
297
|
+
super.addStyleClass(styleClassName)
|
|
298
|
+
|
|
299
|
+
if (this.styleClassName != styleClassName) {
|
|
300
|
+
|
|
301
|
+
this.updateContentForCurrentState.call(this)
|
|
302
|
+
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
didReceiveBroadcastEvent(event: UIViewBroadcastEvent) {
|
|
312
|
+
|
|
313
|
+
super.didReceiveBroadcastEvent(event)
|
|
314
|
+
|
|
315
|
+
if (event.name == UIView.broadcastEventName.PageDidScroll || event.name ==
|
|
316
|
+
UIView.broadcastEventName.AddedToViewTree) {
|
|
317
|
+
|
|
318
|
+
this.hovered = NO
|
|
319
|
+
|
|
320
|
+
this.highlighted = NO
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
toggleSelectedState() {
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
this.selected = !this.selected
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
set isToggleable(isToggleable: boolean) {
|
|
341
|
+
|
|
342
|
+
this._isToggleable = isToggleable
|
|
343
|
+
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
get isToggleable() {
|
|
347
|
+
|
|
348
|
+
return this._isToggleable
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
layoutSubviews() {
|
|
356
|
+
|
|
357
|
+
super.layoutSubviews()
|
|
358
|
+
|
|
359
|
+
const bounds = this.bounds
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
sendControlEventForKey(eventKey: string, nativeEvent: Event) {
|
|
371
|
+
|
|
372
|
+
if (eventKey == UIView.controlEvent.PointerUpInside && !this.highlighted) {
|
|
373
|
+
|
|
374
|
+
// Do not send the event in this case
|
|
375
|
+
//super.sendControlEventForKey(eventKey, nativeEvent);
|
|
376
|
+
|
|
377
|
+
const asd = 1
|
|
378
|
+
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
|
|
382
|
+
super.sendControlEventForKey(eventKey, nativeEvent)
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
static getEventCoordinatesInDocument(touchOrMouseEvent) {
|
|
393
|
+
// http://www.quirksmode.org/js/events_properties.html
|
|
394
|
+
var posx = 0
|
|
395
|
+
var posy = 0
|
|
396
|
+
var e = touchOrMouseEvent
|
|
397
|
+
if (!e) {
|
|
398
|
+
e = window.event
|
|
399
|
+
}
|
|
400
|
+
if (e.pageX || e.pageY) {
|
|
401
|
+
posx = e.pageX
|
|
402
|
+
posy = e.pageY
|
|
403
|
+
}
|
|
404
|
+
else if (e.clientX || e.clientY) {
|
|
405
|
+
posx = e.clientX + document.body.scrollLeft
|
|
406
|
+
+ document.documentElement.scrollLeft
|
|
407
|
+
posy = e.clientY + document.body.scrollTop
|
|
408
|
+
+ document.documentElement.scrollTop
|
|
409
|
+
}
|
|
410
|
+
// posx and posy contain the mouse position relative to the document
|
|
411
|
+
|
|
412
|
+
const coordinates = { "x": posx, "y": posy }
|
|
413
|
+
|
|
414
|
+
return coordinates
|
|
415
|
+
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
static getElementPositionInDocument(el) {
|
|
421
|
+
//https://www.kirupa.com/html5/getting_mouse_click_position.htm
|
|
422
|
+
var xPosition = 0
|
|
423
|
+
var yPosition = 0
|
|
424
|
+
|
|
425
|
+
while (el) {
|
|
426
|
+
if (el.tagName == "BODY") {
|
|
427
|
+
|
|
428
|
+
// Coordinates in document are coordinates in body, therefore subtracting the scroll position of the body is not needed
|
|
429
|
+
|
|
430
|
+
// // deal with browser quirks with body/window/document and page scroll
|
|
431
|
+
// var xScrollPos = el.scrollLeft || document.documentElement.scrollLeft;
|
|
432
|
+
// var yScrollPos = el.scrollTop || document.documentElement.scrollTop;
|
|
433
|
+
//
|
|
434
|
+
// xPosition += (el.offsetLeft - xScrollPos + el.clientLeft);
|
|
435
|
+
// yPosition += (el.offsetTop - yScrollPos + el.clientTop);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
xPosition += (el.offsetLeft - el.scrollLeft + el.clientLeft)
|
|
439
|
+
yPosition += (el.offsetTop - el.scrollTop + el.clientTop)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
el = el.offsetParent
|
|
443
|
+
}
|
|
444
|
+
return {
|
|
445
|
+
x: xPosition,
|
|
446
|
+
y: yPosition
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
static convertCoordinatesFromDocumentToElement(x, y, element) {
|
|
451
|
+
const elementPositionInDocument = this.getElementPositionInDocument(element)
|
|
452
|
+
const coordinatesInElement = { "x": x - elementPositionInDocument.x, "y": y - elementPositionInDocument.y }
|
|
453
|
+
return coordinatesInElement
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
static getEventCoordinatesInElement(touchOrMouseEvent, element) {
|
|
457
|
+
const coordinatesInDocument = this.getEventCoordinatesInDocument(touchOrMouseEvent)
|
|
458
|
+
const coordinatesInElement = this.convertCoordinatesFromDocumentToElement(
|
|
459
|
+
coordinatesInDocument.x,
|
|
460
|
+
coordinatesInDocument.y,
|
|
461
|
+
element
|
|
462
|
+
)
|
|
463
|
+
return coordinatesInElement
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|