This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathsyntax.js
554 lines (473 loc) · 14 KB
/
syntax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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
// Copyright 2011 Google Inc. All rights reserved.
/**
*
* @fileoverview Defines and documents the various lexical components
* that make up the different aspects of the jsaction syntax.
*
* NOTE(user): Yep, the things defined here are lexical, but their
* grouping and documentation is what defines the jsaction syntax.
*/
goog.provide('jsaction.A11y');
goog.provide('jsaction.Attribute');
goog.provide('jsaction.Branch');
goog.provide('jsaction.Char');
goog.provide('jsaction.EventType');
goog.provide('jsaction.KeyCodes');
goog.provide('jsaction.Name');
goog.provide('jsaction.Property');
goog.provide('jsaction.TagName');
goog.provide('jsaction.Tick');
goog.provide('jsaction.UrlParam');
/**
* Defines special EventInfo and Event properties used when
* A11Y_SUPPORT_IN_DISPATCHER is enabled.
* @const
*/
jsaction.A11y = {
/**
* An event-type set when the event contract detects a KEYDOWN event but
* doesn't know if the key press can be treated like a click. The dispatcher
* will use this event-type to parse the keypress and handle it accordingly.
*/
MAYBE_CLICK_EVENT_TYPE: 'maybe_click',
/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property for non-global dispatches before it retriggers the event and it
* signifies that the event contract should not dispatch this event globally.
*/
SKIP_GLOBAL_DISPATCH: 'a11ysgd',
/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property before it retriggers the event and it signifies that the event
* contract should not look at CLICK actions for KEYDOWN events.
*/
SKIP_A11Y_CHECK: 'a11ysc',
};
/**
* All attributes used by jsaction.
* @enum {string}
*/
jsaction.Attribute = {
/**
* The jsaction attribute defines a mapping of a DOM event to a
* generic event (aka jsaction), to which the actual event handlers
* that implement the behavior of the application are bound. The
* value is a semicolon separated list of colon separated pairs of
* an optional DOM event name and a jsaction name. If the optional
* DOM event name is omitted, 'click' is assumed. The jsaction names
* are dot separated pairs of a namespace and a simple jsaction
* name. If the namespace is absent, it is taken from the closest
* ancestor element with a jsnamespace attribute, if there is
* any. If there is no ancestor with a jsnamespace attribute, the
* simple name is assumed to be the jsaction name.
*
* Used by EventContract.
*/
JSACTION: 'jsaction',
/**
* The jsnamespace attribute provides the namespace part of the
* jaction names occurring in the jsaction attribute where it's
* missing.
*
* Used by EventContract.
*/
JSNAMESPACE: 'jsnamespace',
/**
* The oi attribute is a log impression tag for impression logging
* and action tracking. For an element that carries a jsaction
* attribute, the element is identified for the purpose of
* impression logging and click tracking by the dot separated path
* of all oi attributes in the chain of ancestors of the element.
*
* Used by ActionFlow.
*/
OI: 'oi',
/**
* The ved attribute is an encoded ClickTrackingCGI proto to track
* visual elements.
*
* Used by ActionFlow.
*/
VED: 'ved',
/**
* The vet attribute is the visual element type used to identify tracked
* visual elements.
*/
VET: 'vet',
/**
* Support for iteration on reprocessing.
*
* Used by ActionFlow.
*/
JSINSTANCE: 'jsinstance',
/**
* All click jsactions that happen on the element that carries this
* attribute or its descendants are automatically logged.
* Impressions of jsactions on these elements are tracked too, if
* requested by the impression() method of ActionFlow.
*
* Used by ActionFlow.
*/
JSTRACK: 'jstrack'
};
/**
* Special ActionFlow branch names defined by jsaction.
* @enum {string}
*/
jsaction.Branch = {
/**
* The main branch, i.e. the branch the action flow instance starts
* right at construction.
*/
MAIN: 'main-actionflow-branch'
};
/**
* All special characters used by jsaction.
* @const
*/
jsaction.Char = {
/**
* The separator between the namespace and the action name in the
* jsaction attribute value.
*/
NAMESPACE_ACTION_SEPARATOR: '.',
/**
* The separator between the event name and action in the jsaction
* attribute value.
*/
EVENT_ACTION_SEPARATOR: ':',
/**
* The separator between the logged oi attribute values in the &oi=
* URL parameter value.
*/
OI_SEPARATOR: '.',
/**
* The separator between the key and the value pairs in the &cad=
* URL parameter value.
*/
CAD_KEY_VALUE_SEPARATOR: ':',
/**
* The separator between the key-value pairs in the &cad= URL
* parameter value.
*/
CAD_SEPARATOR: ','
};
/**
* Names of events that are special to jsaction. These are not all
* event types that are legal to use in either HTML or the addEvent()
* API, but these are the ones that are treated specially. All other
* DOM events can be used in either addEvent() or in the value of the
* jsaction attribute. Beware of browser specific events or events
* that don't bubble though: If they are not mentioned here, then
* event contract doesn't work around their peculiarities.
* @enum {string}
*/
jsaction.EventType = {
/**
* Mouse middle click, introduced in Chrome 55 and not yet supported on
* other browsers.
*/
AUXCLICK: 'auxclick',
/**
* The change event fired by browsers when the `value` attribute of input,
* select, and textarea elements are changed.
*/
CHANGE: 'change',
/**
* The click event. In addEvent() refers to all click events, in the
* jsaction attribute it refers to the unmodified click and Enter/Space
* keypress events. In the latter case, a jsaction click will be triggered,
* for accessibility reasons. See clickmod and clickonly, below.
*/
CLICK: 'click',
/**
* Specifies the jsaction for a modified click event (i.e. a mouse
* click with the modifier key Cmd/Ctrl pressed). This event isn't
* separately enabled in addEvent(), because in the DOM, it's just a
* click event.
*/
CLICKMOD: 'clickmod',
/**
* Specifies the jsaction for a click-only event. Click-only doesn't take
* into account the case where an element with focus receives an Enter/Space
* keypress. This event isn't separately enabled in addEvent().
*/
CLICKONLY: 'clickonly',
/**
* The dblclick event.
*/
DBLCLICK: 'dblclick',
/**
* Focus doesn't bubble, but you can use it in addEvent() and
* jsaction anyway. EventContract does the right thing under the
* hood.
*/
FOCUS: 'focus',
/**
* This event only exists in IE. For addEvent() and jsaction, use
* focus instead; EventContract does the right thing even though
* focus doesn't bubble.
*/
FOCUSIN: 'focusin',
/**
* Analog to focus.
*/
BLUR: 'blur',
/**
* Analog to focusin.
*/
FOCUSOUT: 'focusout',
/**
* Submit doesn't bubble, so it cannot be used with event
* contract. However, the browser helpfully fires a click event on
* the submit button of a form (even if the form is not submitted by
* a click on the submit button). So you should handle click on the
* submit button instead.
*/
SUBMIT: 'submit',
/**
* The keydown event. In addEvent() and non-click jsaction it represents the
* regular DOM keydown event. It represents click actions in non-Gecko
* browsers.
*/
KEYDOWN: 'keydown',
/**
* The keypress event. In addEvent() and non-click jsaction it represents the
* regular DOM keypress event. It represents click actions in Gecko browsers.
*/
KEYPRESS: 'keypress',
/**
* The keyup event. In addEvent() and non-click jsaction it represents the
* regular DOM keyup event. It represents click actions in non-Gecko
* browsers.
*/
KEYUP: 'keyup',
/**
* The mouseup event. Can either be used directly or used implicitly to
* capture mouseup events. In addEvent(), it represents a regular DOM
* mouseup event.
*/
MOUSEUP: 'mouseup',
/**
* The mousedown event. Can either be used directly or used implicitly to
* capture mouseenter events. In addEvent(), it represents a regular DOM
* mouseover event.
*/
MOUSEDOWN: 'mousedown',
/**
* The mouseover event. Can either be used directly or used implicitly to
* capture mouseenter events. In addEvent(), it represents a regular DOM
* mouseover event.
*/
MOUSEOVER: 'mouseover',
/**
* The mouseout event. Can either be used directly or used implicitly to
* capture mouseover events. In addEvent(), it represents a regular DOM
* mouseout event.
*/
MOUSEOUT: 'mouseout',
/**
* The mouseenter event. Does not bubble and fires individually on each
* element being entered within a DOM tree.
*/
MOUSEENTER: 'mouseenter',
/**
* The mouseleave event. Does not bubble and fires individually on each
* element being entered within a DOM tree.
*/
MOUSELEAVE: 'mouseleave',
/**
* The mousemove event.
*/
MOUSEMOVE: 'mousemove',
/**
* The error event. The error event doesn't bubble, but you can use it in
* addEvent() and jsaction anyway. EventContract does the right thing under
* the hood (except in IE8 which does not use error events).
*/
ERROR: 'error',
/**
* The load event. The load event doesn't bubble, but you can use it in
* addEvent() and jsaction anyway. EventContract does the right thing
* under the hood.
*/
LOAD: 'load',
/**
* The unload event.
*/
UNLOAD: 'unload',
/**
* The touchstart event. Bubbles, will only ever fire in browsers with
* touch support.
*/
TOUCHSTART: 'touchstart',
/**
* The touchend event. Bubbles, will only ever fire in browsers with
* touch support.
*/
TOUCHEND: 'touchend',
/**
* The touchmove event. Bubbles, will only ever fire in browsers with
* touch support.
*/
TOUCHMOVE: 'touchmove',
/**
* The input event.
*/
INPUT: 'input',
/**
* The scroll event.
*/
SCROLL: 'scroll',
/**
* A custom event. The actual custom event type is declared as the 'type'
* field in the event details. Supported in Firefox 6+, IE 9+, and all Chrome
* versions.
*
* This is an internal name. Users should use jsaction.fireCustomEvent to
* fire custom events instead of relying on this type to create them.
*/
CUSTOM: '_custom'
};
/**
* Special keycodes used by jsaction for the generic click action.
* @enum {number}
*/
jsaction.KeyCodes = {
/**
* If on a Macintosh with an extended keyboard, the Enter key located in the
* numeric pad has a different ASCII code.
*/
MAC_ENTER: 3,
/**
* The Enter key.
*/
ENTER: 13,
/**
* The Space key.
*/
SPACE: 32
};
/**
* Special tag names used by jsaction for the generic click action.
* @enum {string}
*/
jsaction.TagName = {
/**
* A textarea tag.
*/
TEXTAREA: 'TEXTAREA',
/**
* An input tag.
*/
INPUT: 'INPUT',
/**
* A button tag.
*/
BUTTON: 'BUTTON',
/**
* An anchor tag.
*/
A: 'A'
};
/**
* Special names used by jsaction.
* @enum {string}
*/
jsaction.Name = {
/**
* The start time property of ActionFlow. TODO(user): Maybe a Property?
*/
START: 'start',
/**
* Click additional data.
*/
CAD: 'cad',
/**
* Action data to track duplicate ticks. This is used as a key in
* additionalData map and in the value of the CLICK_ADDITIONAL_DATA
* URL parameter in the reporting request.
*/
DUP: 'dup'
};
/**
* All the CSI ticks issued by jsaction.
* @enum {string}
*/
jsaction.Tick = {
/**
* Tick that indicates that the control flow enters ActionFlow.impression().
*/
IMP0: 'imp0',
/**
* Tick that indicates that the control flow leaves impression().
*/
IMP1: 'imp1'
};
/**
* All properties that are used by jsaction.
* @enum {string}
*/
jsaction.Property = {
/**
* The parsed value of the jsaction attribute is stored in this
* property on the DOM node. The parsed value is an Object. The
* property names of the object are the events; the values are the
* names of the actions. This property is attached even on nodes
* that don't have a jsaction attribute as an optimization, because
* property lookup is faster than attribute access.
*/
JSACTION: '__jsaction',
/**
* The parsed value of the jsnamespace attribute is stored in this
* property on the DOM node.
*/
JSNAMESPACE: '__jsnamespace',
/**
* The value of the oi attribute as a property, for faster access.
*/
OI: '__oi',
/**
* The owner property references an a logical owner for a DOM node. JSAction
* will follow this reference instead of parentNode when traversing the DOM
* to find jsaction attributes. This allows overlaying a logical structure
* over a document where the DOM structure can't reflect that structure.
*/
OWNER: '__owner'
};
jsaction.UrlParam = {
/**
* The type of the click is the name of the jsaction it was mapped to.
*/
CLICK_TYPE: 'ct',
/**
* Click data contains the positional index of the clicked element
* among its sibling as given by the jsinstance attribute value, if
* any.
*/
CLICK_DATA: 'cd',
/**
* Contains more structured data registered during the execution of
* the jsaction handler and registered with the ActionFlow
* instance. Among these data is informaiton about impressions that
* were generated during the handling of the jsaction.
*/
CLICK_ADDITIONAL_DATA: 'cad',
/**
* The event ID of the response that generated the clicked element,
* as obtained from the value of the jstrack attribute.
*/
EVENT_ID: 'ei',
/**
* The visual element data for the clicked element, as obtained from
* the ved attribute.
*/
VISUAL_ELEMENT_CLICK: 'ved',
/**
* The visual element type of the clicked element, as obtained from the vet
* attribute.
*/
VISUAL_ELEMENT_TYPE: 'vet'
};