1 | var _layersByHostId = {};
|
2 | var _defaultHostSelector;
|
3 | /**
|
4 | * Register a layer for a given host id
|
5 | * @param hostId Id of the layer host
|
6 | * @param layer Layer instance
|
7 | */
|
8 | export function registerLayer(hostId, callback) {
|
9 | if (!_layersByHostId[hostId]) {
|
10 | _layersByHostId[hostId] = [];
|
11 | }
|
12 | _layersByHostId[hostId].push(callback);
|
13 | }
|
14 | /**
|
15 | * Unregister a layer for a given host id
|
16 | * @param hostId Id of the layer host
|
17 | * @param layer Layer instance
|
18 | */
|
19 | export function unregisterLayer(hostId, callback) {
|
20 | if (_layersByHostId[hostId]) {
|
21 | var idx = _layersByHostId[hostId].indexOf(callback);
|
22 | if (idx >= 0) {
|
23 | _layersByHostId[hostId].splice(idx, 1);
|
24 | if (_layersByHostId[hostId].length === 0) {
|
25 | delete _layersByHostId[hostId];
|
26 | }
|
27 | }
|
28 | }
|
29 | }
|
30 | /**
|
31 | * Used for notifying applicable Layers that a host is available/unavailable and to re-evaluate Layers that
|
32 | * care about the specific host.
|
33 | */
|
34 | export function notifyHostChanged(id) {
|
35 | if (_layersByHostId[id]) {
|
36 | _layersByHostId[id].forEach(function (callback) { return callback(); });
|
37 | }
|
38 | }
|
39 | /**
|
40 | * Sets the default target selector to use when determining the host in which
|
41 | * Layered content will be injected into. If not provided, an element will be
|
42 | * created at the end of the document body.
|
43 | *
|
44 | * Passing in a falsey value will clear the default target and reset back to
|
45 | * using a created element at the end of document body.
|
46 | */
|
47 | export function setDefaultTarget(selector) {
|
48 | _defaultHostSelector = selector;
|
49 | }
|
50 | /**
|
51 | * Get the default target selector when determining a host
|
52 | */
|
53 | export function getDefaultTarget() {
|
54 | return _defaultHostSelector;
|
55 | }
|
56 | //# sourceMappingURL=Layer.notification.js.map |
\ | No newline at end of file |