Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/third_party/closure/goog/events/event.js
4143 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview A base class for event objects.
9
*/
10
11
12
goog.provide('goog.events.Event');
13
14
/**
15
* goog.events.Event no longer depends on goog.Disposable. Keep requiring
16
* goog.Disposable here to not break projects which assume this dependency.
17
* @suppress {extraRequire}
18
*/
19
goog.require('goog.Disposable');
20
goog.require('goog.events.EventId');
21
22
23
/**
24
* A base class for event objects, so that they can support preventDefault and
25
* stopPropagation.
26
*
27
* @param {string|!goog.events.EventId} type Event Type.
28
* @param {Object=} opt_target Reference to the object that is the target of
29
* this event. It has to implement the `EventTarget` interface
30
* declared at {@link http://developer.mozilla.org/en/DOM/EventTarget}.
31
* @constructor
32
*/
33
goog.events.Event = function(type, opt_target) {
34
'use strict';
35
/**
36
* Event type.
37
* @type {string}
38
*/
39
this.type = type instanceof goog.events.EventId ? String(type) : type;
40
41
/**
42
* TODO(tbreisacher): The type should probably be
43
* EventTarget|goog.events.EventTarget.
44
*
45
* Target of the event.
46
* @type {Object|undefined}
47
*/
48
this.target = opt_target;
49
50
/**
51
* Object that had the listener attached.
52
* @type {Object|undefined}
53
*/
54
this.currentTarget = this.target;
55
56
/**
57
* Whether to cancel the event in internal capture/bubble processing for IE.
58
* @type {boolean}
59
* @private
60
*/
61
this.propagationStopped_ = false;
62
63
/**
64
* Whether the default action has been prevented.
65
* This is a property to match the W3C specification at
66
* {@link http://www.w3.org/TR/DOM-Level-3-Events/
67
* #events-event-type-defaultPrevented}.
68
* Must be treated as read-only outside the class.
69
* @type {boolean}
70
*/
71
this.defaultPrevented = false;
72
};
73
74
/**
75
* @return {boolean} true iff internal propagation has been stopped.
76
*/
77
goog.events.Event.prototype.hasPropagationStopped = function() {
78
'use strict';
79
return this.propagationStopped_;
80
};
81
82
/**
83
* Stops event propagation.
84
* @return {void}
85
*/
86
goog.events.Event.prototype.stopPropagation = function() {
87
'use strict';
88
this.propagationStopped_ = true;
89
};
90
91
92
/**
93
* Prevents the default action, for example a link redirecting to a url.
94
* @return {void}
95
*/
96
goog.events.Event.prototype.preventDefault = function() {
97
'use strict';
98
this.defaultPrevented = true;
99
};
100
101
102
/**
103
* Stops the propagation of the event. It is equivalent to
104
* `e.stopPropagation()`, but can be used as the callback argument of
105
* {@link goog.events.listen} without declaring another function.
106
* @param {!goog.events.Event} e An event.
107
* @return {void}
108
*/
109
goog.events.Event.stopPropagation = function(e) {
110
'use strict';
111
e.stopPropagation();
112
};
113
114
115
/**
116
* Prevents the default action. It is equivalent to
117
* `e.preventDefault()`, but can be used as the callback argument of
118
* {@link goog.events.listen} without declaring another function.
119
* @param {!goog.events.Event} e An event.
120
* @return {void}
121
*/
122
goog.events.Event.preventDefault = function(e) {
123
'use strict';
124
e.preventDefault();
125
};
126
127