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