@microsoft/applicationinsights-core-js 3.0.0-beta.2303-03 → 3.0.0-beta.2303-05
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 +2 -2
- 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 +113 -206
- package/dist/applicationinsights-core-js.api.md +11 -14
- package/dist/applicationinsights-core-js.d.ts +15 -13
- package/dist/applicationinsights-core-js.js +2 -2
- 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 +15 -13
- package/dist-esm/Config/ConfigDefaultHelpers.js +1 -1
- package/dist-esm/Config/ConfigDefaults.js +1 -1
- package/dist-esm/Config/DynamicConfig.js +1 -1
- package/dist-esm/Config/DynamicProperty.js +1 -1
- package/dist-esm/Config/DynamicState.js +1 -1
- package/dist-esm/Config/DynamicSupport.js +1 -1
- package/dist-esm/Config/IConfigDefaults.js +1 -1
- package/dist-esm/Config/IDynamicConfigHandler.js +1 -1
- package/dist-esm/Config/IDynamicPropertyHandler.js +1 -1
- package/dist-esm/Config/IDynamicWatcher.js +1 -1
- package/dist-esm/Config/_IDynamicConfigHandlerState.js +1 -1
- package/dist-esm/JavaScriptSDK/AggregationError.js +1 -1
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHookContainer.js +1 -1
- package/dist-esm/JavaScriptSDK/W3cTraceParent.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
- 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/IDistributedTraceContext.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 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
- package/dist-esm/__DynamicConstants.js +1 -1
- package/dist-esm/applicationinsights-core-js.js +1 -1
- package/package.json +1 -1
- package/types/JavaScriptSDK/AppInsightsCore.d.ts +5 -6
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +9 -6
- package/src/JavaScriptSDK/AggregationError.ts +0 -36
- package/src/JavaScriptSDK/AppInsightsCore.ts +0 -1322
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +0 -343
- package/src/JavaScriptSDK/Constants.ts +0 -4
- package/src/JavaScriptSDK/CookieMgr.ts +0 -449
- package/src/JavaScriptSDK/CoreUtils.ts +0 -58
- package/src/JavaScriptSDK/DataCacheHelper.ts +0 -107
- package/src/JavaScriptSDK/DbgExtensionUtils.ts +0 -56
- package/src/JavaScriptSDK/DiagnosticLogger.ts +0 -380
- package/src/JavaScriptSDK/EnvUtils.ts +0 -312
- package/src/JavaScriptSDK/EventHelpers.ts +0 -550
- package/src/JavaScriptSDK/HelperFuncs.ts +0 -351
- package/src/JavaScriptSDK/InstrumentHooks.ts +0 -280
- package/src/JavaScriptSDK/InternalConstants.ts +0 -31
- package/src/JavaScriptSDK/NotificationManager.ts +0 -165
- package/src/JavaScriptSDK/PerfManager.ts +0 -288
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +0 -674
- package/src/JavaScriptSDK/RandomHelper.ts +0 -145
- package/src/JavaScriptSDK/TelemetryHelpers.ts +0 -184
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -112
- package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -45
- package/src/JavaScriptSDK/UnloadHookContainer.ts +0 -52
- package/src/JavaScriptSDK/W3cTraceParent.ts +0 -197
- package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +0 -24
- package/src/JavaScriptSDK.Enums/EventsDiscardedReason.ts +0 -71
- package/src/JavaScriptSDK.Enums/LoggingEnums.ts +0 -121
- package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -56
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
- package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +0 -216
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +0 -46
- package/src/JavaScriptSDK.Interfaces/IConfiguration.ts +0 -176
- package/src/JavaScriptSDK.Interfaces/ICookieMgr.ts +0 -116
- package/src/JavaScriptSDK.Interfaces/IDbgExtension.ts +0 -14
- package/src/JavaScriptSDK.Interfaces/IDiagnosticLogger.ts +0 -75
- package/src/JavaScriptSDK.Interfaces/IDistributedTraceContext.ts +0 -54
- package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +0 -100
- package/src/JavaScriptSDK.Interfaces/INotificationListener.ts +0 -39
- package/src/JavaScriptSDK.Interfaces/INotificationManager.ts +0 -52
- package/src/JavaScriptSDK.Interfaces/IPerfEvent.ts +0 -69
- package/src/JavaScriptSDK.Interfaces/IPerfManager.ts +0 -53
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +0 -157
- package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -17
- package/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts +0 -62
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +0 -94
- package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +0 -30
- package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
- package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -44
- package/src/JavaScriptSDK.Interfaces/ITraceParent.ts +0 -38
- package/src/JavaScriptSDK.Interfaces/IUnloadHook.ts +0 -22
- package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { arrForEach, arrIndexOf, getDocument, getWindow, isArray, objForEachKey, objKeys } from "@nevware21/ts-utils";
|
|
4
|
-
import { createElmNodeData, createUniqueNamespace } from "./DataCacheHelper";
|
|
5
|
-
import { STR_EMPTY } from "./InternalConstants";
|
|
6
|
-
|
|
7
|
-
// Added to help with minfication
|
|
8
|
-
const strOnPrefix = "on";
|
|
9
|
-
const strAttachEvent = "attachEvent";
|
|
10
|
-
const strAddEventHelper = "addEventListener";
|
|
11
|
-
const strDetachEvent = "detachEvent";
|
|
12
|
-
const strRemoveEventListener = "removeEventListener";
|
|
13
|
-
const strEvents = "events"
|
|
14
|
-
const strVisibilityChangeEvt: string = "visibilitychange";
|
|
15
|
-
const strPageHide: string = "pagehide";
|
|
16
|
-
const strPageShow: string = "pageshow";
|
|
17
|
-
const strUnload: string = "unload";
|
|
18
|
-
const strBeforeUnload: string = "beforeunload";
|
|
19
|
-
|
|
20
|
-
const strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
|
|
21
|
-
const strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
|
|
22
|
-
|
|
23
|
-
const rRemoveEmptyNs = /\.[\.]+/g;
|
|
24
|
-
const rRemoveTrailingEmptyNs = /[\.]+$/;
|
|
25
|
-
|
|
26
|
-
let _guid = 1;
|
|
27
|
-
|
|
28
|
-
interface IEventDetails {
|
|
29
|
-
type: string,
|
|
30
|
-
ns: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface IRegisteredEvent {
|
|
34
|
-
guid: number;
|
|
35
|
-
evtName: IEventDetails;
|
|
36
|
-
handler: any,
|
|
37
|
-
capture: boolean
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface IAiEvents {
|
|
41
|
-
[name: string]: IRegisteredEvent[]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const elmNodeData = createElmNodeData("events");
|
|
45
|
-
const eventNamespace = /^([^.]*)(?:\.(.+)|)/
|
|
46
|
-
|
|
47
|
-
function _normalizeNamespace(name: string) {
|
|
48
|
-
if (name && name.replace) {
|
|
49
|
-
return name.replace(/^[\s\.]+|(?=[\s\.])[\.\s]+$/g, STR_EMPTY);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return name;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function _getEvtNamespace(eventName: string | undefined, evtNamespace?: string | string[] | null): IEventDetails {
|
|
56
|
-
if (evtNamespace) {
|
|
57
|
-
let theNamespace: string = STR_EMPTY;
|
|
58
|
-
if (isArray(evtNamespace)) {
|
|
59
|
-
theNamespace = STR_EMPTY;
|
|
60
|
-
arrForEach(evtNamespace, (name) => {
|
|
61
|
-
name = _normalizeNamespace(name);
|
|
62
|
-
if (name) {
|
|
63
|
-
if (name[0] !== ".") {
|
|
64
|
-
name = "." + name;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
theNamespace += name;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
theNamespace = _normalizeNamespace(evtNamespace);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (theNamespace) {
|
|
75
|
-
if (theNamespace[0] !== ".") {
|
|
76
|
-
theNamespace = "." + theNamespace;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// We may only have the namespace and not an eventName
|
|
80
|
-
eventName = (eventName || STR_EMPTY) + theNamespace;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let parsedEvent: any[] = (eventNamespace.exec(eventName || STR_EMPTY) || []);
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
type: parsedEvent[1],
|
|
88
|
-
ns: ((parsedEvent[2] || STR_EMPTY).replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, STR_EMPTY).split(".").sort()).join(".")
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export interface _IRegisteredEvents {
|
|
94
|
-
name: string;
|
|
95
|
-
handler: any;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by
|
|
100
|
-
* applications to remove their own events
|
|
101
|
-
* @param target - The EventTarget that has registered events
|
|
102
|
-
* @param eventName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
|
|
103
|
-
* @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
|
|
104
|
-
* if the eventName also includes a namespace the namespace(s) are merged into a single namespace
|
|
105
|
-
*/
|
|
106
|
-
export function __getRegisteredEvents(target: any, eventName?: string, evtNamespace?: string | string[]): _IRegisteredEvents[] {
|
|
107
|
-
let theEvents: _IRegisteredEvents[] = [];
|
|
108
|
-
let eventCache = elmNodeData.get<IAiEvents>(target, strEvents, {}, false);
|
|
109
|
-
let evtName = _getEvtNamespace(eventName, evtNamespace);
|
|
110
|
-
|
|
111
|
-
objForEachKey(eventCache, (evtType, registeredEvents) => {
|
|
112
|
-
arrForEach(registeredEvents, (value) => {
|
|
113
|
-
if (!evtName.type || evtName.type === value.evtName.type) {
|
|
114
|
-
if (!evtName.ns || evtName.ns === evtName.ns) {
|
|
115
|
-
theEvents.push({
|
|
116
|
-
name: value.evtName.type + (value.evtName.ns ? "." + value.evtName.ns : STR_EMPTY),
|
|
117
|
-
handler: value.handler
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
return theEvents;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Exported for internal unit testing only
|
|
128
|
-
function _getRegisteredEvents(target: any, evtName: string, addDefault: boolean = true): IRegisteredEvent[] {
|
|
129
|
-
let aiEvts = elmNodeData.get<IAiEvents>(target, strEvents, {}, addDefault);
|
|
130
|
-
let registeredEvents = aiEvts[evtName];
|
|
131
|
-
if (!registeredEvents) {
|
|
132
|
-
registeredEvents = aiEvts[evtName] = [];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return registeredEvents;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function _doDetach(obj: any, evtName: IEventDetails, handlerRef: any, useCapture: boolean) {
|
|
139
|
-
if (obj && evtName && evtName.type) {
|
|
140
|
-
if (obj[strRemoveEventListener]) {
|
|
141
|
-
obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
|
|
142
|
-
} else if (obj[strDetachEvent]) {
|
|
143
|
-
obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function _doAttach(obj: any, evtName: IEventDetails, handlerRef: any, useCapture: boolean): boolean {
|
|
149
|
-
let result = false;
|
|
150
|
-
|
|
151
|
-
if (obj && evtName && evtName.type && handlerRef) {
|
|
152
|
-
if (obj[strAddEventHelper]) {
|
|
153
|
-
// all browsers except IE before version 9
|
|
154
|
-
obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
|
|
155
|
-
result = true;
|
|
156
|
-
} else if (obj[strAttachEvent]) {
|
|
157
|
-
// IE before version 9
|
|
158
|
-
obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
|
|
159
|
-
result = true;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function _doUnregister(target: any, events: IRegisteredEvent[], evtName: IEventDetails, unRegFn: (regEvent: IRegisteredEvent) => boolean) {
|
|
167
|
-
let idx = events.length;
|
|
168
|
-
while(idx--) {
|
|
169
|
-
let theEvent: IRegisteredEvent = events[idx];
|
|
170
|
-
if (theEvent) {
|
|
171
|
-
if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
|
|
172
|
-
if (!unRegFn || unRegFn(theEvent)) {
|
|
173
|
-
_doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
|
|
174
|
-
// Remove the registered event
|
|
175
|
-
events.splice(idx, 1);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function _unregisterEvents(target: any, evtName: IEventDetails, unRegFn: (regEvent: IRegisteredEvent) => boolean) {
|
|
183
|
-
if (evtName.type) {
|
|
184
|
-
_doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
|
|
185
|
-
} else {
|
|
186
|
-
let eventCache = elmNodeData.get<IAiEvents>(target, strEvents, {});
|
|
187
|
-
objForEachKey(eventCache, (evtType, events) => {
|
|
188
|
-
_doUnregister(target, events, evtName, unRegFn);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// Cleanup
|
|
192
|
-
if (objKeys(eventCache).length === 0) {
|
|
193
|
-
elmNodeData.kill(target, strEvents);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function mergeEvtNamespace(theNamespace: string, namespaces?: string | string[] | null): string | string[] {
|
|
199
|
-
let newNamespaces: string | string[];
|
|
200
|
-
|
|
201
|
-
if (namespaces) {
|
|
202
|
-
if (isArray(namespaces)) {
|
|
203
|
-
newNamespaces = [theNamespace].concat(namespaces);
|
|
204
|
-
} else {
|
|
205
|
-
newNamespaces = [ theNamespace, namespaces ];
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// resort the namespaces so they are always in order
|
|
209
|
-
newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
|
|
210
|
-
} else {
|
|
211
|
-
newNamespaces = theNamespace;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return newNamespaces;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Binds the specified function to an event, so that the function gets called whenever the event fires on the object
|
|
219
|
-
* @param obj - Object to add the event too.
|
|
220
|
-
* @param eventName - String that specifies any of the standard DHTML Events without "on" prefix, if may also include an optional (dot "." prefixed)
|
|
221
|
-
* namespaces "click" "click.mynamespace" in addition to specific namespaces.
|
|
222
|
-
* @param handlerRef - Pointer that specifies the function to call when event fires
|
|
223
|
-
* @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
|
|
224
|
-
* if the eventName also includes a namespace the namespace(s) are merged into a single namespace
|
|
225
|
-
* @param useCapture - [Optional] Defaults to false
|
|
226
|
-
* @returns True if the function was bound successfully to the event, otherwise false
|
|
227
|
-
*/
|
|
228
|
-
export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture: boolean = false) {
|
|
229
|
-
let result = false;
|
|
230
|
-
|
|
231
|
-
if (target) {
|
|
232
|
-
try {
|
|
233
|
-
let evtName = _getEvtNamespace(eventName, evtNamespace);
|
|
234
|
-
result = _doAttach(target, evtName, handlerRef, useCapture);
|
|
235
|
-
|
|
236
|
-
if (result && elmNodeData.accept(target)) {
|
|
237
|
-
let registeredEvent: IRegisteredEvent = {
|
|
238
|
-
guid: _guid++,
|
|
239
|
-
evtName: evtName,
|
|
240
|
-
handler: handlerRef,
|
|
241
|
-
capture: useCapture
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
_getRegisteredEvents(target, evtName.type).push(registeredEvent);
|
|
245
|
-
}
|
|
246
|
-
} catch (e) {
|
|
247
|
-
// Just Ignore any error so that we don't break any execution path
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Removes an event handler for the specified event
|
|
256
|
-
* @param Object - to remove the event from
|
|
257
|
-
* @param eventName - {string} - The name of the event, with optional namespaces or just the namespaces,
|
|
258
|
-
* such as "click", "click.mynamespace" or ".mynamespace"
|
|
259
|
-
* @param handlerRef - {any} - The callback function that needs to be removed from the given event, when using a
|
|
260
|
-
* namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
|
|
261
|
-
* otherwise this will only remove events with this specific handler.
|
|
262
|
-
* @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
|
|
263
|
-
* if the eventName also includes a namespace the namespace(s) are merged into a single namespace
|
|
264
|
-
* @param useCapture - [Optional] Defaults to false
|
|
265
|
-
*/
|
|
266
|
-
export function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture: boolean = false) {
|
|
267
|
-
if (target) {
|
|
268
|
-
try {
|
|
269
|
-
let evtName = _getEvtNamespace(eventName, evtNamespace);
|
|
270
|
-
let found = false;
|
|
271
|
-
_unregisterEvents(target, evtName, (regEvent) => {
|
|
272
|
-
if ((evtName.ns && !handlerRef) || regEvent.handler === handlerRef) {
|
|
273
|
-
found = true;
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return false;
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
if (!found) {
|
|
281
|
-
// fallback to try and remove as requested
|
|
282
|
-
_doDetach(target, evtName, handlerRef, useCapture);
|
|
283
|
-
}
|
|
284
|
-
} catch (e) {
|
|
285
|
-
// Just Ignore any error so that we don't break any execution path
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Binds the specified function to an event, so that the function gets called whenever the event fires on the object
|
|
293
|
-
* @param obj - Object to add the event too.
|
|
294
|
-
* @param eventNameWithoutOn - String that specifies any of the standard DHTML Events without "on" prefix and optional (dot "." prefixed) namespaces "click" "click.mynamespace".
|
|
295
|
-
* @param handlerRef - Pointer that specifies the function to call when event fires
|
|
296
|
-
* @param useCapture - [Optional] Defaults to false
|
|
297
|
-
* @returns True if the function was bound successfully to the event, otherwise false
|
|
298
|
-
*/
|
|
299
|
-
export function attachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture: boolean = false) {
|
|
300
|
-
return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Removes an event handler for the specified event
|
|
305
|
-
* @param Object - to remove the event from
|
|
306
|
-
* @param eventNameWithoutOn - {string} - The name of the event, with optional namespaces or just the namespaces,
|
|
307
|
-
* such as "click", "click.mynamespace" or ".mynamespace"
|
|
308
|
-
* @param handlerRef - {any} - The callback function that needs to be removed from the given event, when using a
|
|
309
|
-
* namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
|
|
310
|
-
* otherwise this will only remove events with this specific handler.
|
|
311
|
-
* @param useCapture - [Optional] Defaults to false
|
|
312
|
-
*/
|
|
313
|
-
export function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture: boolean = false) {
|
|
314
|
-
eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Trys to add an event handler for the specified event to the window, body and document
|
|
319
|
-
* @param eventName - {string} - The name of the event
|
|
320
|
-
* @param callback - {any} - The callback function that needs to be executed for the given event
|
|
321
|
-
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
322
|
-
* @return {boolean} - true if the handler was successfully added
|
|
323
|
-
*/
|
|
324
|
-
export function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): boolean {
|
|
325
|
-
let result = false;
|
|
326
|
-
let w = getWindow();
|
|
327
|
-
if (w) {
|
|
328
|
-
result = eventOn(w, eventName, callback, evtNamespace);
|
|
329
|
-
result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
let doc = getDocument();
|
|
333
|
-
if (doc) {
|
|
334
|
-
result = eventOn(doc, eventName, callback, evtNamespace) || result;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return result;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Trys to remove event handler(s) for the specified event/namespace to the window, body and document
|
|
342
|
-
* @param eventName - {string} - The name of the event, with optional namespaces or just the namespaces,
|
|
343
|
-
* such as "click", "click.mynamespace" or ".mynamespace"
|
|
344
|
-
* @param callback - {any} - - The callback function that needs to be removed from the given event, when using a
|
|
345
|
-
* namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
|
|
346
|
-
* otherwise this will only remove events with this specific handler.
|
|
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 removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null) {
|
|
350
|
-
let w = getWindow();
|
|
351
|
-
if (w) {
|
|
352
|
-
eventOff(w, eventName, callback, evtNamespace);
|
|
353
|
-
eventOff(w["body"], eventName, callback, evtNamespace);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
let doc = getDocument();
|
|
357
|
-
if (doc) {
|
|
358
|
-
eventOff(doc, eventName, callback, evtNamespace);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Bind the listener to the array of events
|
|
364
|
-
* @param events - An string array of event names to bind the listener to
|
|
365
|
-
* @param listener - The event callback to call when the event is triggered
|
|
366
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
367
|
-
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
368
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
369
|
-
*/
|
|
370
|
-
function _addEventListeners(events: string[], listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
|
|
371
|
-
let added = false;
|
|
372
|
-
|
|
373
|
-
if (listener && events && events.length > 0) {
|
|
374
|
-
arrForEach(events, (name) => {
|
|
375
|
-
if (name) {
|
|
376
|
-
if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
|
|
377
|
-
added = addEventHandler(name, listener, evtNamespace) || added;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return added;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Bind the listener to the array of events
|
|
388
|
-
* @param events - An string array of event names to bind the listener to
|
|
389
|
-
* @param listener - The event callback to call when the 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] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
392
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
393
|
-
*/
|
|
394
|
-
export function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean {
|
|
395
|
-
let added = false;
|
|
396
|
-
|
|
397
|
-
if (listener && events && isArray(events)) {
|
|
398
|
-
added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
|
|
399
|
-
|
|
400
|
-
if (!added && excludeEvents && excludeEvents.length > 0) {
|
|
401
|
-
// Failed to add any listeners and we excluded some, so just attempt to add the excluded events
|
|
402
|
-
added = _addEventListeners(events, listener, null, evtNamespace);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return added;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Remove the listener from the array of events
|
|
411
|
-
* @param events - An string array of event names to bind the listener to
|
|
412
|
-
* @param listener - The event callback to call when the event is triggered
|
|
413
|
-
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
414
|
-
*/
|
|
415
|
-
export function removeEventListeners(events: string[], listener: any, evtNamespace?: string | string[]) {
|
|
416
|
-
if (events && isArray(events)) {
|
|
417
|
-
arrForEach(events, (name) => {
|
|
418
|
-
if (name) {
|
|
419
|
-
removeEventHandler(name, listener, evtNamespace);
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
|
|
427
|
-
* this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden
|
|
428
|
-
* it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is
|
|
429
|
-
* just navigating to a different Tab and may come back (without unloading the page). As such you may also
|
|
430
|
-
* need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
|
|
431
|
-
* @param listener - The event callback to call when a page unload event is triggered
|
|
432
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.
|
|
433
|
-
* @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
|
|
434
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
435
|
-
*/
|
|
436
|
-
export function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean {
|
|
437
|
-
// Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
|
|
438
|
-
// As just hooking the window does not always fire (on chrome) for page navigation's.
|
|
439
|
-
return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* Remove any matching 'beforeunload', 'unload' and 'pagehide' events that may have been added via addEventListener,
|
|
444
|
-
* addEventListeners, addPageUnloadEventListener or addPageHideEventListener.
|
|
445
|
-
* @param listener - The specific event callback to to be removed
|
|
446
|
-
* @param evtNamespace - [Optional] Namespace(s) uniquely identified and removed based on this namespace.
|
|
447
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
448
|
-
*/
|
|
449
|
-
export function removePageUnloadEventListener(listener: any, evtNamespace?: string | string[]) {
|
|
450
|
-
removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Listen to the pagehide and visibility changing to 'hidden' events, because the 'visibilitychange' uses
|
|
455
|
-
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
|
|
456
|
-
* removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
457
|
-
* @param listener - The event callback to call when a page hide event is triggered
|
|
458
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
459
|
-
* @param evtNamespace - [Optional] A Namespace to append to the event listeners so they can be uniquely identified and removed
|
|
460
|
-
* based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
|
|
461
|
-
* so that only the matching "removePageHideEventListener" can remove these events.
|
|
462
|
-
* Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
|
|
463
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
464
|
-
*/
|
|
465
|
-
export function addPageHideEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
|
|
466
|
-
|
|
467
|
-
function _handlePageVisibility(evt: any) {
|
|
468
|
-
let doc = getDocument();
|
|
469
|
-
if (listener && doc && doc.visibilityState === "hidden") {
|
|
470
|
-
listener(evt);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// add the unique page show namespace to any provided namespace so we can only remove the ones added by "pagehide"
|
|
475
|
-
let newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
|
|
476
|
-
let pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
|
|
477
|
-
|
|
478
|
-
if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
|
|
479
|
-
pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (!pageUnloadAdded && excludeEvents) {
|
|
483
|
-
// Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything
|
|
484
|
-
pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
return pageUnloadAdded;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Removes the pageHide event listeners added by addPageHideEventListener, because the 'visibilitychange' uses
|
|
492
|
-
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageHideEventListener
|
|
493
|
-
* as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
494
|
-
* @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
|
|
495
|
-
* @param evtNamespace - The unique namespace used when calling addPageShowEventListener
|
|
496
|
-
*/
|
|
497
|
-
|
|
498
|
-
export function removePageHideEventListener(listener: any, evtNamespace?: string | string[] | null) {
|
|
499
|
-
// add the unique page show namespace to any provided namespace so we only remove the ones added by "pagehide"
|
|
500
|
-
let newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
|
|
501
|
-
removeEventListeners([strPageHide], listener, newNamespaces);
|
|
502
|
-
removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Listen to the pageshow and visibility changing to 'visible' events, because the 'visibilitychange' uses
|
|
507
|
-
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
|
|
508
|
-
* removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
509
|
-
* @param listener - The event callback to call when a page is show event is triggered
|
|
510
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
511
|
-
* @param evtNamespace - [Optional/Recommended] A Namespace to append to the event listeners so they can be uniquely
|
|
512
|
-
* identified and removed based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
|
|
513
|
-
* so that only the matching "removePageShowEventListener" can remove these events.
|
|
514
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
515
|
-
*/
|
|
516
|
-
export function addPageShowEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
|
|
517
|
-
|
|
518
|
-
function _handlePageVisibility(evt: any) {
|
|
519
|
-
let doc = getDocument();
|
|
520
|
-
if (listener && doc && doc.visibilityState === "visible") {
|
|
521
|
-
listener(evt);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// add the unique page show namespace to any provided namespace so we can only remove the ones added by "pageshow"
|
|
526
|
-
let newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
|
|
527
|
-
let pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
|
|
528
|
-
pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
|
|
529
|
-
|
|
530
|
-
if (!pageShowAdded && excludeEvents) {
|
|
531
|
-
// Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything
|
|
532
|
-
pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return pageShowAdded;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Removes the pageShow event listeners added by addPageShowEventListener, because the 'visibilitychange' uses
|
|
540
|
-
* an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageShowEventListener
|
|
541
|
-
* as the remove ignores the listener argument for the 'visibilitychange' event.
|
|
542
|
-
* @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
|
|
543
|
-
* @param evtNamespace - The unique namespace used when calling addPageShowEventListener
|
|
544
|
-
*/
|
|
545
|
-
export function removePageShowEventListener(listener: any, evtNamespace?: string | string[] | null) {
|
|
546
|
-
// add the unique page show namespace to any provided namespace so we only remove the ones added by "pageshow"
|
|
547
|
-
let newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
|
|
548
|
-
removeEventListeners([strPageShow], listener, newNamespaces);
|
|
549
|
-
removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
|
|
550
|
-
}
|