@microsoft/applicationinsights-core-js 2.8.0-beta.2202-06 → 2.8.0-beta.2203-02
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/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +945 -479
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +3904 -877
- package/dist/applicationinsights-core-js.api.md +264 -30
- package/dist/applicationinsights-core-js.d.ts +410 -89
- package/dist/applicationinsights-core-js.js +945 -479
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +410 -89
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +66 -23
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +44 -5
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +105 -73
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +3 -4
- package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +6 -122
- package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +12 -12
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +8 -7
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +472 -0
- package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +32 -59
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
- package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
- package/dist-esm/JavaScriptSDK/NotificationManager.js +8 -11
- package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +184 -110
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +3 -2
- package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +32 -13
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +4 -6
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
- package/dist-esm/applicationinsights-core-js.js +8 -4
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +1 -1
- package/src/JavaScriptSDK/BaseCore.ts +80 -24
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +76 -5
- package/src/JavaScriptSDK/ChannelController.ts +107 -61
- package/src/JavaScriptSDK/CookieMgr.ts +4 -4
- package/src/JavaScriptSDK/CoreUtils.ts +6 -143
- package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
- package/src/JavaScriptSDK/DiagnosticLogger.ts +12 -11
- package/src/JavaScriptSDK/EnvUtils.ts +7 -6
- package/src/JavaScriptSDK/EventHelpers.ts +542 -0
- package/src/JavaScriptSDK/HelperFuncs.ts +35 -54
- package/src/JavaScriptSDK/InternalConstants.ts +26 -0
- package/src/JavaScriptSDK/NotificationManager.ts +7 -11
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +237 -124
- package/src/JavaScriptSDK/RandomHelper.ts +2 -1
- package/src/JavaScriptSDK/TelemetryHelpers.ts +47 -15
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +5 -15
- package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +20 -0
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +9 -2
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +55 -16
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +16 -9
- package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
- package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
- package/types/JavaScriptSDK/BaseCore.d.ts +4 -0
- package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +20 -1
- package/types/JavaScriptSDK/ChannelController.d.ts +4 -0
- package/types/JavaScriptSDK/CoreUtils.d.ts +1 -42
- package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
- package/types/JavaScriptSDK/EventHelpers.d.ts +152 -0
- package/types/JavaScriptSDK/HelperFuncs.d.ts +8 -17
- package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
- package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +10 -3
- package/types/JavaScriptSDK/TelemetryHelpers.d.ts +8 -0
- package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -7
- package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
- package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +9 -0
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +17 -0
- package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +9 -2
- package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +49 -14
- package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +15 -8
- package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
- package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
- package/types/applicationinsights-core-js.d.ts +6 -3
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 2.8.0-beta.2203-02
|
|
3
|
+
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import { createElmNodeData, createUniqueNamespace } from "./DataCacheHelper";
|
|
8
|
+
import { getDocument, getWindow } from "./EnvUtils";
|
|
9
|
+
import { arrForEach, arrIndexOf, isArray, objForEachKey, objKeys } from "./HelperFuncs";
|
|
10
|
+
// Added to help with minfication
|
|
11
|
+
var strOnPrefix = "on";
|
|
12
|
+
var strAttachEvent = "attachEvent";
|
|
13
|
+
var strAddEventHelper = "addEventListener";
|
|
14
|
+
var strDetachEvent = "detachEvent";
|
|
15
|
+
var strRemoveEventListener = "removeEventListener";
|
|
16
|
+
var strEvents = "events";
|
|
17
|
+
var strVisibilityChangeEvt = "visibilitychange";
|
|
18
|
+
var strPageHide = "pagehide";
|
|
19
|
+
var strPageShow = "pageshow";
|
|
20
|
+
var strUnload = "unload";
|
|
21
|
+
var strBeforeUnload = "beforeunload";
|
|
22
|
+
var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
|
|
23
|
+
var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
|
|
24
|
+
var _guid = 1;
|
|
25
|
+
var elmNodeData = createElmNodeData("events");
|
|
26
|
+
var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
|
|
27
|
+
function _normalizeNamespace(name) {
|
|
28
|
+
if (name && name.replace) {
|
|
29
|
+
return name.replace(/^\s*\.*|\.*\s*$/g, "");
|
|
30
|
+
}
|
|
31
|
+
return name;
|
|
32
|
+
}
|
|
33
|
+
function _getEvtNamespace(eventName, namespaces) {
|
|
34
|
+
if (namespaces) {
|
|
35
|
+
var theNamespace_1 = "";
|
|
36
|
+
if (isArray(namespaces)) {
|
|
37
|
+
theNamespace_1 = "";
|
|
38
|
+
arrForEach(namespaces, function (name) {
|
|
39
|
+
name = _normalizeNamespace(name);
|
|
40
|
+
if (name) {
|
|
41
|
+
if (name[0] !== ".") {
|
|
42
|
+
name = "." + name;
|
|
43
|
+
}
|
|
44
|
+
theNamespace_1 += name;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
theNamespace_1 = _normalizeNamespace(namespaces);
|
|
50
|
+
}
|
|
51
|
+
if (theNamespace_1) {
|
|
52
|
+
if (theNamespace_1[0] !== ".") {
|
|
53
|
+
theNamespace_1 = "." + theNamespace_1;
|
|
54
|
+
}
|
|
55
|
+
// We may only have the namespace and not an eventName
|
|
56
|
+
eventName = (eventName || "") + theNamespace_1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var parsedEvent = (eventNamespace.exec(eventName) || []);
|
|
60
|
+
return {
|
|
61
|
+
type: parsedEvent[1],
|
|
62
|
+
ns: ((parsedEvent[2] || "").split(".").sort()).join(".")
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by
|
|
67
|
+
* applications to remove their own events
|
|
68
|
+
* @param target - The EventTarget that has registered events
|
|
69
|
+
* @param evtName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
|
|
70
|
+
*/
|
|
71
|
+
export function __getRegisteredEvents(target, evtName) {
|
|
72
|
+
var theEvents = [];
|
|
73
|
+
var eventCache = elmNodeData.get(target, strEvents, {}, false);
|
|
74
|
+
objForEachKey(eventCache, function (evtType, registeredEvents) {
|
|
75
|
+
arrForEach(registeredEvents, function (value) {
|
|
76
|
+
if (!evtName || evtName === value.evtName.type) {
|
|
77
|
+
theEvents.push({
|
|
78
|
+
name: value.evtName.type + (value.evtName.ns ? "." + value.evtName.ns : ""),
|
|
79
|
+
handler: value.handler
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return theEvents;
|
|
85
|
+
}
|
|
86
|
+
// Exported for internal unit testing only
|
|
87
|
+
function _getRegisteredEvents(target, evtName, addDefault) {
|
|
88
|
+
if (addDefault === void 0) { addDefault = true; }
|
|
89
|
+
var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
|
|
90
|
+
var registeredEvents = aiEvts[evtName];
|
|
91
|
+
if (!registeredEvents) {
|
|
92
|
+
registeredEvents = aiEvts[evtName] = [];
|
|
93
|
+
}
|
|
94
|
+
return registeredEvents;
|
|
95
|
+
}
|
|
96
|
+
function _doDetach(obj, evtName, handlerRef, useCapture) {
|
|
97
|
+
if (obj && evtName && evtName.type) {
|
|
98
|
+
if (obj[strRemoveEventListener]) {
|
|
99
|
+
obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
|
|
100
|
+
}
|
|
101
|
+
else if (obj[strDetachEvent]) {
|
|
102
|
+
obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function _doAttach(obj, evtName, handlerRef, useCapture) {
|
|
107
|
+
var result = false;
|
|
108
|
+
if (obj && evtName && evtName.type && handlerRef) {
|
|
109
|
+
if (obj[strAddEventHelper]) {
|
|
110
|
+
// all browsers except IE before version 9
|
|
111
|
+
obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
|
|
112
|
+
result = true;
|
|
113
|
+
}
|
|
114
|
+
else if (obj[strAttachEvent]) {
|
|
115
|
+
// IE before version 9
|
|
116
|
+
obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
|
|
117
|
+
result = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
function _doUnregister(target, events, evtName, unRegFn) {
|
|
123
|
+
var idx = events.length;
|
|
124
|
+
while (idx--) {
|
|
125
|
+
var theEvent = events[idx];
|
|
126
|
+
if (theEvent) {
|
|
127
|
+
if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
|
|
128
|
+
if (!unRegFn || unRegFn(theEvent)) {
|
|
129
|
+
_doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
|
|
130
|
+
// Remove the registered event
|
|
131
|
+
events.splice(idx, 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function _unregisterEvents(target, evtName, unRegFn) {
|
|
138
|
+
if (evtName.type) {
|
|
139
|
+
_doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
var eventCache = elmNodeData.get(target, strEvents, {});
|
|
143
|
+
objForEachKey(eventCache, function (evtType, events) {
|
|
144
|
+
_doUnregister(target, events, evtName, unRegFn);
|
|
145
|
+
});
|
|
146
|
+
// Cleanup
|
|
147
|
+
if (objKeys(eventCache).length === 0) {
|
|
148
|
+
elmNodeData.kill(target, strEvents);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export function mergeEvtNamespace(theNamespace, namespaces) {
|
|
153
|
+
var newNamespaces;
|
|
154
|
+
if (namespaces) {
|
|
155
|
+
if (isArray(namespaces)) {
|
|
156
|
+
newNamespaces = [theNamespace].concat(namespaces);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
newNamespaces = [theNamespace, namespaces];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
newNamespaces = theNamespace;
|
|
164
|
+
}
|
|
165
|
+
return newNamespaces;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Binds the specified function to an event, so that the function gets called whenever the event fires on the object
|
|
169
|
+
* @param obj Object to add the event too.
|
|
170
|
+
* @param eventName String that specifies any of the standard DHTML Events without "on" prefix, if may also include an optional (dot "." prefixed)
|
|
171
|
+
* namespaces "click" "click.mynamespace" in addition to specific namespaces.
|
|
172
|
+
* @param handlerRef Pointer that specifies the function to call when event fires
|
|
173
|
+
* @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
|
|
174
|
+
* if the eventName also includes a namespace the namespace(s) are merged into a single namespace
|
|
175
|
+
* @param useCapture [Optional] Defaults to false
|
|
176
|
+
* @returns True if the function was bound successfully to the event, otherwise false
|
|
177
|
+
*/
|
|
178
|
+
export function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
|
|
179
|
+
if (useCapture === void 0) { useCapture = false; }
|
|
180
|
+
var result = false;
|
|
181
|
+
if (target) {
|
|
182
|
+
try {
|
|
183
|
+
var evtName = _getEvtNamespace(eventName, evtNamespace);
|
|
184
|
+
result = _doAttach(target, evtName, handlerRef, useCapture);
|
|
185
|
+
if (result && elmNodeData.accept(target)) {
|
|
186
|
+
var registeredEvent = {
|
|
187
|
+
guid: _guid++,
|
|
188
|
+
evtName: evtName,
|
|
189
|
+
handler: handlerRef,
|
|
190
|
+
capture: useCapture
|
|
191
|
+
};
|
|
192
|
+
_getRegisteredEvents(target, evtName.type).push(registeredEvent);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
// Just Ignore any error so that we don't break any execution path
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Removes an event handler for the specified event
|
|
203
|
+
* @param Object to remove the event from
|
|
204
|
+
* @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
|
|
205
|
+
* such as "click", "click.mynamespace" or ".mynamespace"
|
|
206
|
+
* @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
|
|
207
|
+
* namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
|
|
208
|
+
* otherwise this will only remove events with this specific handler.
|
|
209
|
+
* @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
|
|
210
|
+
* if the eventName also includes a namespace the namespace(s) are merged into a single namespace
|
|
211
|
+
* @param useCapture [Optional] Defaults to false
|
|
212
|
+
*/
|
|
213
|
+
export function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
|
|
214
|
+
if (useCapture === void 0) { useCapture = false; }
|
|
215
|
+
if (target) {
|
|
216
|
+
try {
|
|
217
|
+
var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
|
|
218
|
+
var found_1 = false;
|
|
219
|
+
_unregisterEvents(target, evtName_1, function (regEvent) {
|
|
220
|
+
if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
|
|
221
|
+
found_1 = true;
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
});
|
|
226
|
+
if (!found_1) {
|
|
227
|
+
// fallback to try and remove as requested
|
|
228
|
+
_doDetach(target, evtName_1, handlerRef, useCapture);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
// Just Ignore any error so that we don't break any execution path
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Binds the specified function to an event, so that the function gets called whenever the event fires on the object
|
|
238
|
+
* @param obj Object to add the event too.
|
|
239
|
+
* @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix and optional (dot "." prefixed) namespaces "click" "click.mynamespace".
|
|
240
|
+
* @param handlerRef Pointer that specifies the function to call when event fires
|
|
241
|
+
* @param useCapture [Optional] Defaults to false
|
|
242
|
+
* @returns True if the function was bound successfully to the event, otherwise false
|
|
243
|
+
*/
|
|
244
|
+
export function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
|
|
245
|
+
if (useCapture === void 0) { useCapture = false; }
|
|
246
|
+
return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Removes an event handler for the specified event
|
|
250
|
+
* @param Object to remove the event from
|
|
251
|
+
* @param eventNameWithoutOn {string} - The name of the event, with optional namespaces or just the namespaces,
|
|
252
|
+
* such as "click", "click.mynamespace" or ".mynamespace"
|
|
253
|
+
* @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
|
|
254
|
+
* namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
|
|
255
|
+
* otherwise this will only remove events with this specific handler.
|
|
256
|
+
* @param useCapture [Optional] Defaults to false
|
|
257
|
+
*/
|
|
258
|
+
export function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
|
|
259
|
+
if (useCapture === void 0) { useCapture = false; }
|
|
260
|
+
eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Trys to add an event handler for the specified event to the window, body and document
|
|
264
|
+
* @param eventName {string} - The name of the event
|
|
265
|
+
* @param callback {any} - The callback function that needs to be executed for the given event
|
|
266
|
+
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
267
|
+
* @return {boolean} - true if the handler was successfully added
|
|
268
|
+
*/
|
|
269
|
+
export function addEventHandler(eventName, callback, evtNamespace) {
|
|
270
|
+
var result = false;
|
|
271
|
+
var w = getWindow();
|
|
272
|
+
if (w) {
|
|
273
|
+
result = eventOn(w, eventName, callback, evtNamespace);
|
|
274
|
+
result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
|
|
275
|
+
}
|
|
276
|
+
var doc = getDocument();
|
|
277
|
+
if (doc) {
|
|
278
|
+
result = eventOn(doc, eventName, callback, evtNamespace) || result;
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Trys to remove event handler(s) for the specified event/namespace to the window, body and document
|
|
284
|
+
* @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
|
|
285
|
+
* such as "click", "click.mynamespace" or ".mynamespace"
|
|
286
|
+
* @param callback {any} - - The callback function that needs to be removed from the given event, when using a
|
|
287
|
+
* namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
|
|
288
|
+
* otherwise this will only remove events with this specific handler.
|
|
289
|
+
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
290
|
+
*/
|
|
291
|
+
export function removeEventHandler(eventName, callback, evtNamespace) {
|
|
292
|
+
var w = getWindow();
|
|
293
|
+
if (w) {
|
|
294
|
+
eventOff(w, eventName, callback, evtNamespace);
|
|
295
|
+
eventOff(w["body"], eventName, callback, evtNamespace);
|
|
296
|
+
}
|
|
297
|
+
var doc = getDocument();
|
|
298
|
+
if (doc) {
|
|
299
|
+
eventOff(doc, eventName, callback, evtNamespace);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Bind the listener to the array of events
|
|
304
|
+
* @param events An string array of event names to bind the listener to
|
|
305
|
+
* @param listener The event callback to call when the event is triggered
|
|
306
|
+
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
307
|
+
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
308
|
+
* @returns true - when at least one of the events was registered otherwise false
|
|
309
|
+
*/
|
|
310
|
+
function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
|
|
311
|
+
var added = false;
|
|
312
|
+
if (listener && events && events.length > 0) {
|
|
313
|
+
arrForEach(events, function (name) {
|
|
314
|
+
if (name) {
|
|
315
|
+
if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
|
|
316
|
+
added = addEventHandler(name, listener, evtNamespace) || added;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return added;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Bind the listener to the array of events
|
|
325
|
+
* @param events An string array of event names to bind the listener to
|
|
326
|
+
* @param listener The event callback to call when the event is triggered
|
|
327
|
+
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
328
|
+
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
329
|
+
* @returns true - when at least one of the events was registered otherwise false
|
|
330
|
+
*/
|
|
331
|
+
// export function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
|
|
332
|
+
export function addEventListeners(events, listener, excludeEvents, evtNamespace) {
|
|
333
|
+
var added = false;
|
|
334
|
+
if (listener && events && isArray(events)) {
|
|
335
|
+
added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
|
|
336
|
+
if (!added && excludeEvents && excludeEvents.length > 0) {
|
|
337
|
+
// Failed to add any listeners and we excluded some, so just attempt to add the excluded events
|
|
338
|
+
added = _addEventListeners(events, listener, null, evtNamespace);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return added;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Remove the listener from the array of events
|
|
345
|
+
* @param events An string array of event names to bind the listener to
|
|
346
|
+
* @param listener The event callback to call when the event is triggered
|
|
347
|
+
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
348
|
+
*/
|
|
349
|
+
export function removeEventListeners(events, listener, evtNamespace) {
|
|
350
|
+
if (events && isArray(events)) {
|
|
351
|
+
arrForEach(events, function (name) {
|
|
352
|
+
if (name) {
|
|
353
|
+
removeEventHandler(name, listener, evtNamespace);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
|
|
360
|
+
* this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden
|
|
361
|
+
* it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is
|
|
362
|
+
* just navigating to a different Tab and may come back (without unloading the page). As such you may also
|
|
363
|
+
* need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
|
|
364
|
+
* @param listener - The event callback to call when a page unload event is triggered
|
|
365
|
+
* @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.
|
|
366
|
+
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
367
|
+
* @returns true - when at least one of the events was registered otherwise false
|
|
368
|
+
*/
|
|
369
|
+
//export function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
|
|
370
|
+
export function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
|
|
371
|
+
// Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
|
|
372
|
+
// As just hooking the window does not always fire (on chrome) for page navigation's.
|
|
373
|
+
return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Remove any matching 'beforeunload', 'unload' and 'pagehide' events that may have been added via addEventListener,
|
|
377
|
+
* addEventListeners, addPageUnloadEventListener or addPageHideEventListener.
|
|
378
|
+
* @param listener - The specific event callback to to be removed
|
|
379
|
+
* @param evtNamespace - [Optional] Namespace(s) uniquely identified and removed based on this namespace.
|
|
380
|
+
* @returns true - when at least one of the events was registered otherwise false
|
|
381
|
+
*/
|
|
382
|
+
export function removePageUnloadEventListener(listener, evtNamespace) {
|
|
383
|
+
removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Listen to the pagehide and visibility changing to 'hidden' events, because the 'visibilitychange' uses
|
|
387
|
+
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
|
|
388
|
+
* removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
389
|
+
* @param listener - The event callback to call when a page hide event is triggered
|
|
390
|
+
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
391
|
+
* @param evtNamespace - [Optional] A Namespace to append to the event listeners so they can be uniquely identified and removed
|
|
392
|
+
* based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
|
|
393
|
+
* so that only the matching "removePageHideEventListener" can remove these events.
|
|
394
|
+
* Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
|
|
395
|
+
* @returns true - when at least one of the events was registered otherwise false
|
|
396
|
+
*/
|
|
397
|
+
//export function addPageHideEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
|
|
398
|
+
export function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
|
|
399
|
+
function _handlePageVisibility(evt) {
|
|
400
|
+
var doc = getDocument();
|
|
401
|
+
if (listener && doc && doc.visibilityState === "hidden") {
|
|
402
|
+
listener(evt);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
// add the unique page show namespace to any provided namespace so we can only remove the ones added by "pagehide"
|
|
406
|
+
var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
|
|
407
|
+
var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
|
|
408
|
+
if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
|
|
409
|
+
pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
|
|
410
|
+
}
|
|
411
|
+
if (!pageUnloadAdded && excludeEvents) {
|
|
412
|
+
// Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything
|
|
413
|
+
pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
|
|
414
|
+
}
|
|
415
|
+
return pageUnloadAdded;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Removes the pageHide event listeners added by addPageHideEventListener, because the 'visibilitychange' uses
|
|
419
|
+
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageHideEventListener
|
|
420
|
+
* as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
421
|
+
* @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
|
|
422
|
+
* @param evtNamespace - The unique namespace used when calling addPageShowEventListener
|
|
423
|
+
*/
|
|
424
|
+
export function removePageHideEventListener(listener, evtNamespace) {
|
|
425
|
+
// add the unique page show namespace to any provided namespace so we only remove the ones added by "pagehide"
|
|
426
|
+
var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
|
|
427
|
+
removeEventListeners([strPageHide], listener, newNamespaces);
|
|
428
|
+
removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Listen to the pageshow and visibility changing to 'visible' events, because the 'visibilitychange' uses
|
|
432
|
+
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
|
|
433
|
+
* removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
434
|
+
* @param listener - The event callback to call when a page is show event is triggered
|
|
435
|
+
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
436
|
+
* @param evtNamespace - [Optional/Recommended] A Namespace to append to the event listeners so they can be uniquely
|
|
437
|
+
* identified and removed based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
|
|
438
|
+
* so that only the matching "removePageShowEventListener" can remove these events.
|
|
439
|
+
* @returns true - when at least one of the events was registered otherwise false
|
|
440
|
+
*/
|
|
441
|
+
//export function addPageShowEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
|
|
442
|
+
export function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
|
|
443
|
+
function _handlePageVisibility(evt) {
|
|
444
|
+
var doc = getDocument();
|
|
445
|
+
if (listener && doc && doc.visibilityState === "visible") {
|
|
446
|
+
listener(evt);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// add the unique page show namespace to any provided namespace so we can only remove the ones added by "pageshow"
|
|
450
|
+
var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
|
|
451
|
+
var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
|
|
452
|
+
pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
|
|
453
|
+
if (!pageShowAdded && excludeEvents) {
|
|
454
|
+
// Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything
|
|
455
|
+
pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
|
|
456
|
+
}
|
|
457
|
+
return pageShowAdded;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Removes the pageShow event listeners added by addPageShowEventListener, because the 'visibilitychange' uses
|
|
461
|
+
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageShowEventListener
|
|
462
|
+
* as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
463
|
+
* @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
|
|
464
|
+
* @param evtNamespace - The unique namespace used when calling addPageShowEventListener
|
|
465
|
+
*/
|
|
466
|
+
export function removePageShowEventListener(listener, evtNamespace) {
|
|
467
|
+
// add the unique page show namespace to any provided namespace so we only remove the ones added by "pageshow"
|
|
468
|
+
var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
|
|
469
|
+
removeEventListeners([strPageShow], listener, newNamespaces);
|
|
470
|
+
removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
|
|
471
|
+
}
|
|
472
|
+
//# sourceMappingURL=EventHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventHelpers.js.map","sources":["EventHelpers.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { createElmNodeData, createUniqueNamespace } from \"./DataCacheHelper\";\r\nimport { getDocument, getWindow } from \"./EnvUtils\";\r\nimport { arrForEach, arrIndexOf, isArray, objForEachKey, objKeys } from \"./HelperFuncs\";\r\n// Added to help with minfication\r\nvar strOnPrefix = \"on\";\r\nvar strAttachEvent = \"attachEvent\";\r\nvar strAddEventHelper = \"addEventListener\";\r\nvar strDetachEvent = \"detachEvent\";\r\nvar strRemoveEventListener = \"removeEventListener\";\r\nvar strEvents = \"events\";\r\nvar strVisibilityChangeEvt = \"visibilitychange\";\r\nvar strPageHide = \"pagehide\";\r\nvar strPageShow = \"pageshow\";\r\nvar strUnload = \"unload\";\r\nvar strBeforeUnload = \"beforeunload\";\r\nvar strPageHideNamespace = createUniqueNamespace(\"aiEvtPageHide\");\r\nvar strPageShowNamespace = createUniqueNamespace(\"aiEvtPageShow\");\r\nvar _guid = 1;\r\nvar elmNodeData = createElmNodeData(\"events\");\r\nvar eventNamespace = /^([^.]*)(?:\\.(.+)|)/;\r\nfunction _normalizeNamespace(name) {\r\n if (name && name.replace) {\r\n return name.replace(/^\\s*\\.*|\\.*\\s*$/g, \"\");\r\n }\r\n return name;\r\n}\r\nfunction _getEvtNamespace(eventName, namespaces) {\r\n if (namespaces) {\r\n var theNamespace_1 = \"\";\r\n if (isArray(namespaces)) {\r\n theNamespace_1 = \"\";\r\n arrForEach(namespaces, function (name) {\r\n name = _normalizeNamespace(name);\r\n if (name) {\r\n if (name[0] !== \".\") {\r\n name = \".\" + name;\r\n }\r\n theNamespace_1 += name;\r\n }\r\n });\r\n }\r\n else {\r\n theNamespace_1 = _normalizeNamespace(namespaces);\r\n }\r\n if (theNamespace_1) {\r\n if (theNamespace_1[0] !== \".\") {\r\n theNamespace_1 = \".\" + theNamespace_1;\r\n }\r\n // We may only have the namespace and not an eventName\r\n eventName = (eventName || \"\") + theNamespace_1;\r\n }\r\n }\r\n var parsedEvent = (eventNamespace.exec(eventName) || []);\r\n return {\r\n type: parsedEvent[1],\r\n ns: ((parsedEvent[2] || \"\").split(\".\").sort()).join(\".\")\r\n };\r\n}\r\n/**\r\n * Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by\r\n * applications to remove their own events\r\n * @param target - The EventTarget that has registered events\r\n * @param evtName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)\r\n */\r\nexport function __getRegisteredEvents(target, evtName) {\r\n var theEvents = [];\r\n var eventCache = elmNodeData.get(target, strEvents, {}, false);\r\n objForEachKey(eventCache, function (evtType, registeredEvents) {\r\n arrForEach(registeredEvents, function (value) {\r\n if (!evtName || evtName === value.evtName.type) {\r\n theEvents.push({\r\n name: value.evtName.type + (value.evtName.ns ? \".\" + value.evtName.ns : \"\"),\r\n handler: value.handler\r\n });\r\n }\r\n });\r\n });\r\n return theEvents;\r\n}\r\n// Exported for internal unit testing only\r\nfunction _getRegisteredEvents(target, evtName, addDefault) {\r\n if (addDefault === void 0) { addDefault = true; }\r\n var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);\r\n var registeredEvents = aiEvts[evtName];\r\n if (!registeredEvents) {\r\n registeredEvents = aiEvts[evtName] = [];\r\n }\r\n return registeredEvents;\r\n}\r\nfunction _doDetach(obj, evtName, handlerRef, useCapture) {\r\n if (obj && evtName && evtName.type) {\r\n if (obj[strRemoveEventListener]) {\r\n obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);\r\n }\r\n else if (obj[strDetachEvent]) {\r\n obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);\r\n }\r\n }\r\n}\r\nfunction _doAttach(obj, evtName, handlerRef, useCapture) {\r\n var result = false;\r\n if (obj && evtName && evtName.type && handlerRef) {\r\n if (obj[strAddEventHelper]) {\r\n // all browsers except IE before version 9\r\n obj[strAddEventHelper](evtName.type, handlerRef, useCapture);\r\n result = true;\r\n }\r\n else if (obj[strAttachEvent]) {\r\n // IE before version 9\r\n obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);\r\n result = true;\r\n }\r\n }\r\n return result;\r\n}\r\nfunction _doUnregister(target, events, evtName, unRegFn) {\r\n var idx = events.length;\r\n while (idx--) {\r\n var theEvent = events[idx];\r\n if (theEvent) {\r\n if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {\r\n if (!unRegFn || unRegFn(theEvent)) {\r\n _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);\r\n // Remove the registered event\r\n events.splice(idx, 1);\r\n }\r\n }\r\n }\r\n }\r\n}\r\nfunction _unregisterEvents(target, evtName, unRegFn) {\r\n if (evtName.type) {\r\n _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);\r\n }\r\n else {\r\n var eventCache = elmNodeData.get(target, strEvents, {});\r\n objForEachKey(eventCache, function (evtType, events) {\r\n _doUnregister(target, events, evtName, unRegFn);\r\n });\r\n // Cleanup\r\n if (objKeys(eventCache).length === 0) {\r\n elmNodeData.kill(target, strEvents);\r\n }\r\n }\r\n}\r\nexport function mergeEvtNamespace(theNamespace, namespaces) {\r\n var newNamespaces;\r\n if (namespaces) {\r\n if (isArray(namespaces)) {\r\n newNamespaces = [theNamespace].concat(namespaces);\r\n }\r\n else {\r\n newNamespaces = [theNamespace, namespaces];\r\n }\r\n }\r\n else {\r\n newNamespaces = theNamespace;\r\n }\r\n return newNamespaces;\r\n}\r\n/**\r\n * Binds the specified function to an event, so that the function gets called whenever the event fires on the object\r\n * @param obj Object to add the event too.\r\n * @param eventName String that specifies any of the standard DHTML Events without \"on\" prefix, if may also include an optional (dot \".\" prefixed)\r\n * namespaces \"click\" \"click.mynamespace\" in addition to specific namespaces.\r\n * @param handlerRef Pointer that specifies the function to call when event fires\r\n * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,\r\n * if the eventName also includes a namespace the namespace(s) are merged into a single namespace\r\n * @param useCapture [Optional] Defaults to false\r\n * @returns True if the function was bound successfully to the event, otherwise false\r\n */\r\nexport function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {\r\n if (useCapture === void 0) { useCapture = false; }\r\n var result = false;\r\n if (target) {\r\n try {\r\n var evtName = _getEvtNamespace(eventName, evtNamespace);\r\n result = _doAttach(target, evtName, handlerRef, useCapture);\r\n if (result && elmNodeData.accept(target)) {\r\n var registeredEvent = {\r\n guid: _guid++,\r\n evtName: evtName,\r\n handler: handlerRef,\r\n capture: useCapture\r\n };\r\n _getRegisteredEvents(target, evtName.type).push(registeredEvent);\r\n }\r\n }\r\n catch (e) {\r\n // Just Ignore any error so that we don't break any execution path\r\n }\r\n }\r\n return result;\r\n}\r\n/**\r\n * Removes an event handler for the specified event\r\n * @param Object to remove the event from\r\n * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,\r\n * such as \"click\", \"click.mynamespace\" or \".mynamespace\"\r\n * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a\r\n * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers\r\n * otherwise this will only remove events with this specific handler.\r\n * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,\r\n * if the eventName also includes a namespace the namespace(s) are merged into a single namespace\r\n * @param useCapture [Optional] Defaults to false\r\n */\r\nexport function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {\r\n if (useCapture === void 0) { useCapture = false; }\r\n if (target) {\r\n try {\r\n var evtName_1 = _getEvtNamespace(eventName, evtNamespace);\r\n var found_1 = false;\r\n _unregisterEvents(target, evtName_1, function (regEvent) {\r\n if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {\r\n found_1 = true;\r\n return true;\r\n }\r\n return false;\r\n });\r\n if (!found_1) {\r\n // fallback to try and remove as requested\r\n _doDetach(target, evtName_1, handlerRef, useCapture);\r\n }\r\n }\r\n catch (e) {\r\n // Just Ignore any error so that we don't break any execution path\r\n }\r\n }\r\n}\r\n/**\r\n * Binds the specified function to an event, so that the function gets called whenever the event fires on the object\r\n * @param obj Object to add the event too.\r\n * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without \"on\" prefix and optional (dot \".\" prefixed) namespaces \"click\" \"click.mynamespace\".\r\n * @param handlerRef Pointer that specifies the function to call when event fires\r\n * @param useCapture [Optional] Defaults to false\r\n * @returns True if the function was bound successfully to the event, otherwise false\r\n */\r\nexport function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {\r\n if (useCapture === void 0) { useCapture = false; }\r\n return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);\r\n}\r\n/**\r\n * Removes an event handler for the specified event\r\n * @param Object to remove the event from\r\n * @param eventNameWithoutOn {string} - The name of the event, with optional namespaces or just the namespaces,\r\n * such as \"click\", \"click.mynamespace\" or \".mynamespace\"\r\n * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a\r\n * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers\r\n * otherwise this will only remove events with this specific handler.\r\n * @param useCapture [Optional] Defaults to false\r\n */\r\nexport function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {\r\n if (useCapture === void 0) { useCapture = false; }\r\n eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);\r\n}\r\n/**\r\n * Trys to add an event handler for the specified event to the window, body and document\r\n * @param eventName {string} - The name of the event\r\n * @param callback {any} - The callback function that needs to be executed for the given event\r\n * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.\r\n * @return {boolean} - true if the handler was successfully added\r\n */\r\nexport function addEventHandler(eventName, callback, evtNamespace) {\r\n var result = false;\r\n var w = getWindow();\r\n if (w) {\r\n result = eventOn(w, eventName, callback, evtNamespace);\r\n result = eventOn(w[\"body\"], eventName, callback, evtNamespace) || result;\r\n }\r\n var doc = getDocument();\r\n if (doc) {\r\n result = eventOn(doc, eventName, callback, evtNamespace) || result;\r\n }\r\n return result;\r\n}\r\n/**\r\n * Trys to remove event handler(s) for the specified event/namespace to the window, body and document\r\n * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,\r\n * such as \"click\", \"click.mynamespace\" or \".mynamespace\"\r\n * @param callback {any} - - The callback function that needs to be removed from the given event, when using a\r\n * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers\r\n * otherwise this will only remove events with this specific handler.\r\n * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.\r\n */\r\nexport function removeEventHandler(eventName, callback, evtNamespace) {\r\n var w = getWindow();\r\n if (w) {\r\n eventOff(w, eventName, callback, evtNamespace);\r\n eventOff(w[\"body\"], eventName, callback, evtNamespace);\r\n }\r\n var doc = getDocument();\r\n if (doc) {\r\n eventOff(doc, eventName, callback, evtNamespace);\r\n }\r\n}\r\n/**\r\n * Bind the listener to the array of events\r\n * @param events An string array of event names to bind the listener to\r\n * @param listener The event callback to call when the event is triggered\r\n * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.\r\n * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.\r\n * @returns true - when at least one of the events was registered otherwise false\r\n */\r\nfunction _addEventListeners(events, listener, excludeEvents, evtNamespace) {\r\n var added = false;\r\n if (listener && events && events.length > 0) {\r\n arrForEach(events, function (name) {\r\n if (name) {\r\n if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {\r\n added = addEventHandler(name, listener, evtNamespace) || added;\r\n }\r\n }\r\n });\r\n }\r\n return added;\r\n}\r\n/**\r\n * Bind the listener to the array of events\r\n * @param events An string array of event names to bind the listener to\r\n * @param listener The event callback to call when the event is triggered\r\n * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.\r\n * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.\r\n * @returns true - when at least one of the events was registered otherwise false\r\n */\r\n// export function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {\r\nexport function addEventListeners(events, listener, excludeEvents, evtNamespace) {\r\n var added = false;\r\n if (listener && events && isArray(events)) {\r\n added = _addEventListeners(events, listener, excludeEvents, evtNamespace);\r\n if (!added && excludeEvents && excludeEvents.length > 0) {\r\n // Failed to add any listeners and we excluded some, so just attempt to add the excluded events\r\n added = _addEventListeners(events, listener, null, evtNamespace);\r\n }\r\n }\r\n return added;\r\n}\r\n/**\r\n * Remove the listener from the array of events\r\n * @param events An string array of event names to bind the listener to\r\n * @param listener The event callback to call when the event is triggered\r\n * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.\r\n */\r\nexport function removeEventListeners(events, listener, evtNamespace) {\r\n if (events && isArray(events)) {\r\n arrForEach(events, function (name) {\r\n if (name) {\r\n removeEventHandler(name, listener, evtNamespace);\r\n }\r\n });\r\n }\r\n}\r\n/**\r\n * Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,\r\n * this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden\r\n * it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is\r\n * just navigating to a different Tab and may come back (without unloading the page). As such you may also\r\n * need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.\r\n * @param listener - The event callback to call when a page unload event is triggered\r\n * @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.\r\n * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.\r\n * @returns true - when at least one of the events was registered otherwise false\r\n */\r\n//export function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {\r\nexport function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {\r\n // Hook the unload event for the document, window and body to ensure that the client events are flushed to the server\r\n // As just hooking the window does not always fire (on chrome) for page navigation's.\r\n return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);\r\n}\r\n/**\r\n * Remove any matching 'beforeunload', 'unload' and 'pagehide' events that may have been added via addEventListener,\r\n * addEventListeners, addPageUnloadEventListener or addPageHideEventListener.\r\n * @param listener - The specific event callback to to be removed\r\n * @param evtNamespace - [Optional] Namespace(s) uniquely identified and removed based on this namespace.\r\n * @returns true - when at least one of the events was registered otherwise false\r\n */\r\nexport function removePageUnloadEventListener(listener, evtNamespace) {\r\n removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);\r\n}\r\n/**\r\n * Listen to the pagehide and visibility changing to 'hidden' events, because the 'visibilitychange' uses\r\n * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call\r\n * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.\r\n * @param listener - The event callback to call when a page hide event is triggered\r\n * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.\r\n * @param evtNamespace - [Optional] A Namespace to append to the event listeners so they can be uniquely identified and removed\r\n * based on this namespace. This call also adds an additional unique \"pageshow\" namespace to the events\r\n * so that only the matching \"removePageHideEventListener\" can remove these events.\r\n * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide\r\n * @returns true - when at least one of the events was registered otherwise false\r\n */\r\n//export function addPageHideEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {\r\nexport function addPageHideEventListener(listener, excludeEvents, evtNamespace) {\r\n function _handlePageVisibility(evt) {\r\n var doc = getDocument();\r\n if (listener && doc && doc.visibilityState === \"hidden\") {\r\n listener(evt);\r\n }\r\n }\r\n // add the unique page show namespace to any provided namespace so we can only remove the ones added by \"pagehide\"\r\n var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);\r\n var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);\r\n if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {\r\n pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;\r\n }\r\n if (!pageUnloadAdded && excludeEvents) {\r\n // Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything\r\n pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);\r\n }\r\n return pageUnloadAdded;\r\n}\r\n/**\r\n * Removes the pageHide event listeners added by addPageHideEventListener, because the 'visibilitychange' uses\r\n * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageHideEventListener\r\n * as the remove ignores the listener argument for the 'visibilitychange' event.\r\n * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')\r\n * @param evtNamespace - The unique namespace used when calling addPageShowEventListener\r\n */\r\nexport function removePageHideEventListener(listener, evtNamespace) {\r\n // add the unique page show namespace to any provided namespace so we only remove the ones added by \"pagehide\"\r\n var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);\r\n removeEventListeners([strPageHide], listener, newNamespaces);\r\n removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);\r\n}\r\n/**\r\n * Listen to the pageshow and visibility changing to 'visible' events, because the 'visibilitychange' uses\r\n * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call\r\n * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.\r\n * @param listener - The event callback to call when a page is show event is triggered\r\n * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.\r\n * @param evtNamespace - [Optional/Recommended] A Namespace to append to the event listeners so they can be uniquely\r\n * identified and removed based on this namespace. This call also adds an additional unique \"pageshow\" namespace to the events\r\n * so that only the matching \"removePageShowEventListener\" can remove these events.\r\n * @returns true - when at least one of the events was registered otherwise false\r\n */\r\n//export function addPageShowEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {\r\nexport function addPageShowEventListener(listener, excludeEvents, evtNamespace) {\r\n function _handlePageVisibility(evt) {\r\n var doc = getDocument();\r\n if (listener && doc && doc.visibilityState === \"visible\") {\r\n listener(evt);\r\n }\r\n }\r\n // add the unique page show namespace to any provided namespace so we can only remove the ones added by \"pageshow\"\r\n var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);\r\n var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);\r\n pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;\r\n if (!pageShowAdded && excludeEvents) {\r\n // Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything\r\n pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);\r\n }\r\n return pageShowAdded;\r\n}\r\n/**\r\n * Removes the pageShow event listeners added by addPageShowEventListener, because the 'visibilitychange' uses\r\n * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageShowEventListener\r\n * as the remove ignores the listener argument for the 'visibilitychange' event.\r\n * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')\r\n * @param evtNamespace - The unique namespace used when calling addPageShowEventListener\r\n */\r\nexport function removePageShowEventListener(listener, evtNamespace) {\r\n // add the unique page show namespace to any provided namespace so we only remove the ones added by \"pageshow\"\r\n var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);\r\n removeEventListeners([strPageShow], listener, newNamespaces);\r\n removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);\r\n}\r\n//# sourceMappingURL=EventHelpers.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 2.8.0-beta.
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 2.8.0-beta.2203-02
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import { strShimUndefined, strShimObject, strShimFunction, throwTypeError, ObjClass, ObjProto, ObjAssign, ObjHasOwnProperty, ObjDefineProperty, strShimPrototype } from "@microsoft/applicationinsights-shims";
|
|
8
|
+
import { strEmpty } from "./InternalConstants";
|
|
8
9
|
// RESTRICT and AVOID circular dependencies you should not import other contained modules or export the contents of this file directly
|
|
9
10
|
// Added to help with minfication
|
|
10
|
-
var strOnPrefix = "on";
|
|
11
|
-
var strAttachEvent = "attachEvent";
|
|
12
|
-
var strAddEventHelper = "addEventListener";
|
|
13
|
-
var strDetachEvent = "detachEvent";
|
|
14
|
-
var strRemoveEventListener = "removeEventListener";
|
|
15
11
|
var strToISOString = "toISOString";
|
|
16
12
|
var cStrEndsWith = "endsWith";
|
|
17
13
|
var cStrStartsWith = "startsWith";
|
|
@@ -100,58 +96,8 @@ export function isFunction(value) {
|
|
|
100
96
|
// Changing to inline for performance
|
|
101
97
|
return !!(value && typeof value === strShimFunction);
|
|
102
98
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* @param obj Object to add the event too.
|
|
106
|
-
* @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix
|
|
107
|
-
* @param handlerRef Pointer that specifies the function to call when event fires
|
|
108
|
-
* @param useCapture [Optional] Defaults to false
|
|
109
|
-
* @returns True if the function was bound successfully to the event, otherwise false
|
|
110
|
-
*/
|
|
111
|
-
export function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
|
|
112
|
-
if (useCapture === void 0) { useCapture = false; }
|
|
113
|
-
var result = false;
|
|
114
|
-
if (!isNullOrUndefined(obj)) {
|
|
115
|
-
try {
|
|
116
|
-
if (!isNullOrUndefined(obj[strAddEventHelper])) {
|
|
117
|
-
// all browsers except IE before version 9
|
|
118
|
-
obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
|
|
119
|
-
result = true;
|
|
120
|
-
}
|
|
121
|
-
else if (!isNullOrUndefined(obj[strAttachEvent])) {
|
|
122
|
-
// IE before version 9
|
|
123
|
-
obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
|
|
124
|
-
result = true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
// Just Ignore any error so that we don't break any execution path
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Removes an event handler for the specified event
|
|
135
|
-
* @param Object to remove the event from
|
|
136
|
-
* @param eventNameWithoutOn {string} - The name of the event
|
|
137
|
-
* @param handlerRef {any} - The callback function that needs to be executed for the given event
|
|
138
|
-
* @param useCapture [Optional] Defaults to false
|
|
139
|
-
*/
|
|
140
|
-
export function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
|
|
141
|
-
if (useCapture === void 0) { useCapture = false; }
|
|
142
|
-
if (!isNullOrUndefined(obj)) {
|
|
143
|
-
try {
|
|
144
|
-
if (!isNullOrUndefined(obj[strRemoveEventListener])) {
|
|
145
|
-
obj[strRemoveEventListener](eventNameWithoutOn, handlerRef, useCapture);
|
|
146
|
-
}
|
|
147
|
-
else if (!isNullOrUndefined(obj[strDetachEvent])) {
|
|
148
|
-
obj[strDetachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
// Just Ignore any error so that we don't break any execution path
|
|
153
|
-
}
|
|
154
|
-
}
|
|
99
|
+
export function isPromiseLike(value) {
|
|
100
|
+
return value && isFunction(value.then);
|
|
155
101
|
}
|
|
156
102
|
/**
|
|
157
103
|
* Validates that the string name conforms to the JS IdentifierName specification and if not
|
|
@@ -586,6 +532,16 @@ export function objDefineAccessors(target, prop, getProp, setProp) {
|
|
|
586
532
|
function _doNothing(value) {
|
|
587
533
|
return value;
|
|
588
534
|
}
|
|
535
|
+
export function deepFreeze(obj) {
|
|
536
|
+
if (_objFreeze) {
|
|
537
|
+
objForEachKey(obj, function (name, value) {
|
|
538
|
+
if (isArray(value) || isObject(value)) {
|
|
539
|
+
_objFreeze(value);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
return objFreeze(obj);
|
|
544
|
+
}
|
|
589
545
|
export var objFreeze = _objFreeze || _doNothing;
|
|
590
546
|
export var objSeal = _objSeal || _doNothing;
|
|
591
547
|
/**
|
|
@@ -603,7 +559,7 @@ export function getExceptionName(object) {
|
|
|
603
559
|
if (isError(object)) {
|
|
604
560
|
return object.name;
|
|
605
561
|
}
|
|
606
|
-
return
|
|
562
|
+
return strEmpty;
|
|
607
563
|
}
|
|
608
564
|
/**
|
|
609
565
|
* Sets the provided value on the target instance using the field name when the provided chk function returns true, the chk
|
|
@@ -772,6 +728,23 @@ export function createClassFromInterface(defaults) {
|
|
|
772
728
|
return class_1;
|
|
773
729
|
}());
|
|
774
730
|
}
|
|
731
|
+
/**
|
|
732
|
+
* Create an enum style object which has both the key => value and value => key mappings
|
|
733
|
+
* @param values - The values to populate on the new object
|
|
734
|
+
* @returns
|
|
735
|
+
*/
|
|
736
|
+
export function createEnumStyle(values) {
|
|
737
|
+
var enumClass = {};
|
|
738
|
+
objForEachKey(values, function (field, value) {
|
|
739
|
+
enumClass[field] = value;
|
|
740
|
+
// Add Reverse lookup
|
|
741
|
+
if (!isUndefined(enumClass[value])) {
|
|
742
|
+
throwError("Value: [" + value + "] already exists for " + field);
|
|
743
|
+
}
|
|
744
|
+
enumClass[value] = field;
|
|
745
|
+
});
|
|
746
|
+
return objFreeze(enumClass);
|
|
747
|
+
}
|
|
775
748
|
/**
|
|
776
749
|
* A helper function to assist with JIT performance for objects that have properties added / removed dynamically
|
|
777
750
|
* this is primarily for chromium based browsers and has limited effects on Firefox and none of IE. Only call this
|