|
6 | 6 | fluid.defaults("gamepad.focusOverlay.pointer", {
|
7 | 7 | gradeNames: ["gamepad.templateRenderer"],
|
8 | 8 | markup: {
|
9 |
| - container: "<div class='gamepad-navigator-focus-overlay-pointer' hidden></div>" |
| 9 | + container: "<div class='gamepad-navigator-focus-overlay-pointer'></div>" |
10 | 10 | },
|
11 |
| - model: { |
12 |
| - focusOverlayElement: false, |
13 |
| - hideFocusOverlay: true |
14 |
| - }, |
15 |
| - modelListeners: { |
16 |
| - focusOverlayElement: { |
17 |
| - excludeSource: "init", |
18 |
| - funcName: "gamepad.focusOverlay.pointer.trackFocusOverlayElement", |
| 11 | + listeners: { |
| 12 | + "onCreate.listenForWindowFocusEvents": { |
| 13 | + funcName: "gamepad.focusOverlay.pointer.listenForWindowFocusEvents", |
19 | 14 | args: ["{that}"]
|
20 | 15 | }
|
21 | 16 | },
|
22 |
| - modelRelay: { |
23 |
| - hideFocusOverlay: { |
24 |
| - source: "{that}.model.hideFocusOverlay", |
25 |
| - target: "{that}.model.dom.container.attr.hidden" |
| 17 | + invokers: { |
| 18 | + handleFocusin: { |
| 19 | + funcName: "gamepad.focusOverlay.pointer.handleFocusin", |
| 20 | + args: ["{that}", "{arguments}.0"] // event |
| 21 | + } |
| 22 | + }, |
| 23 | + modelListeners: { |
| 24 | + modalManagerShadowElement: { |
| 25 | + funcName: "gamepad.focusOverlay.pointer.listenForModalFocusEvents", |
| 26 | + args: ["{that}"] |
26 | 27 | }
|
27 | 28 | }
|
28 | 29 | });
|
29 | 30 |
|
30 |
| - gamepad.focusOverlay.pointer.trackFocusOverlayElement = function (that) { |
| 31 | + gamepad.focusOverlay.pointer.listenForWindowFocusEvents = function (that) { |
| 32 | + window.addEventListener("focusin", that.handleFocusin); |
| 33 | + }; |
| 34 | + |
| 35 | + gamepad.focusOverlay.pointer.listenForModalFocusEvents = function (that) { |
| 36 | + var modalManagerShadowElement = fluid.get(that, "model.modalManagerShadowElement"); |
| 37 | + if (modalManagerShadowElement) { |
| 38 | + modalManagerShadowElement.addEventListener("focusin", that.handleFocusin); |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + gamepad.focusOverlay.pointer.handleFocusin = function (that) { |
31 | 43 | var containerDomElement = that.container[0];
|
32 |
| - if (that.model.focusOverlayElement) { |
33 |
| - var clientRect = that.model.focusOverlayElement.getBoundingClientRect(); |
34 | 44 |
|
35 |
| - // Our outline is three pixels, so we adjust everything accordingly. |
36 |
| - containerDomElement.style.left = (clientRect.x + window.scrollX - 3) + "px"; |
37 |
| - containerDomElement.style.top = (clientRect.y + window.scrollY - 3) + "px"; |
38 |
| - containerDomElement.style.height = (clientRect.height) + "px"; |
39 |
| - containerDomElement.style.width = (clientRect.width) + "px"; |
| 45 | + var activeElement = fluid.get(that.model, "modalManagerShadowElement.activeElement") || document.activeElement; |
40 | 46 |
|
41 |
| - var elementStyles = getComputedStyle(that.model.focusOverlayElement); |
42 |
| - var borderRadiusValue = elementStyles.getPropertyValue("border-radius"); |
43 |
| - if (borderRadiusValue.length) { |
44 |
| - containerDomElement.style.borderRadius = borderRadiusValue; |
45 |
| - } |
46 |
| - else { |
47 |
| - containerDomElement.style.borderRadius = 0; |
48 |
| - } |
| 47 | + var clientRect = activeElement.getBoundingClientRect(); |
| 48 | + |
| 49 | + // Our outline is three pixels, so we adjust everything accordingly. |
| 50 | + containerDomElement.style.left = (clientRect.x + window.scrollX - 3) + "px"; |
| 51 | + containerDomElement.style.top = (clientRect.y + window.scrollY - 3) + "px"; |
| 52 | + containerDomElement.style.height = (clientRect.height) + "px"; |
| 53 | + containerDomElement.style.width = (clientRect.width) + "px"; |
| 54 | + |
| 55 | + var elementStyles = getComputedStyle(activeElement); |
| 56 | + var borderRadiusValue = elementStyles.getPropertyValue("border-radius"); |
| 57 | + if (borderRadiusValue.length) { |
| 58 | + containerDomElement.style.borderRadius = borderRadiusValue; |
49 | 59 | }
|
50 | 60 | else {
|
51 |
| - containerDomElement.style.height = 0; |
52 |
| - containerDomElement.style.width = 0; |
53 | 61 | containerDomElement.style.borderRadius = 0;
|
54 | 62 | }
|
55 | 63 | };
|
|
60 | 68 | container: "<div class='gamepad-navigator-focus-overlay'></div>"
|
61 | 69 | },
|
62 | 70 | model: {
|
63 |
| - activeModal: false, |
64 | 71 | shadowElement: false,
|
65 | 72 |
|
66 |
| - focusOverlayElement: "{gamepad.focusOverlay}.model.focusOverlayElement", |
| 73 | + modalManagerShadowElement: false, |
| 74 | + |
67 | 75 | prefs: {},
|
68 | 76 | hideFocusOverlay: true
|
69 | 77 | },
|
| 78 | + modelRelay: { |
| 79 | + hideFocusOverlay: { |
| 80 | + source: "{that}.model.hideFocusOverlay", |
| 81 | + target: "{that}.model.dom.container.attr.hidden" |
| 82 | + } |
| 83 | + }, |
70 | 84 | components: {
|
71 | 85 | pointer: {
|
72 | 86 | container: "{that}.model.shadowElement",
|
73 | 87 | type: "gamepad.focusOverlay.pointer",
|
74 | 88 | createOnEvent: "onShadowReady",
|
75 | 89 | options: {
|
76 | 90 | model: {
|
77 |
| - focusOverlayElement: "{gamepad.focusOverlay}.model.focusOverlayElement", |
78 |
| - hideFocusOverlay: "{gamepad.focusOverlay}.model.hideFocusOverlay" |
| 91 | + modalManagerShadowElement: "{gamepad.focusOverlay}.model.modalManagerShadowElement" |
79 | 92 | }
|
80 | 93 | }
|
81 | 94 | }
|
|
86 | 99 | funcName: "gamepad.focusOverlay.shouldDisplayOverlay",
|
87 | 100 | args: ["{that}"]
|
88 | 101 | },
|
89 |
| - focusOverlayElement: { |
90 |
| - excludeSource: "init", |
91 |
| - funcName: "gamepad.focusOverlay.shouldDisplayOverlay", |
| 102 | + modalManagerShadowElement: { |
| 103 | + funcName: "gamepad.focusOverlay.listenForModalFocusEvents", |
92 | 104 | args: ["{that}"]
|
93 |
| - }, |
94 |
| - activeModal: { |
95 |
| - excludeSource: "init", |
96 |
| - funcName: "gamepad.focusOverlay.shouldDisplayOverlay", |
| 105 | + } |
| 106 | + }, |
| 107 | + listeners: { |
| 108 | + "onCreate.listenForWindowFocusEvents": { |
| 109 | + funcName: "gamepad.focusOverlay.listenForWindowFocusEvents", |
97 | 110 | args: ["{that}"]
|
98 | 111 | }
|
| 112 | + }, |
| 113 | + invokers: { |
| 114 | + shouldDisplayOverlay: { |
| 115 | + funcName: "gamepad.focusOverlay.shouldDisplayOverlay", |
| 116 | + args: ["{that}", "{arguments}.0"] // event |
| 117 | + } |
99 | 118 | }
|
100 | 119 | });
|
101 | 120 |
|
102 | 121 | gamepad.focusOverlay.shouldDisplayOverlay = function (that) {
|
| 122 | + var activeElement = fluid.get(that.model, "modalManagerShadowElement.activeElement") || document.activeElement; |
103 | 123 | var fixFocus = fluid.get(that, "model.prefs.fixFocus") ? true : false;
|
104 |
| - var hideFocusOverlay = !fixFocus || !that.model.focusOverlayElement; |
| 124 | + var hideFocusOverlay = !fixFocus || !activeElement; |
105 | 125 | that.applier.change("hideFocusOverlay", hideFocusOverlay);
|
106 | 126 | };
|
| 127 | + |
| 128 | + gamepad.focusOverlay.listenForWindowFocusEvents = function (that) { |
| 129 | + window.addEventListener("focusin", that.shouldDisplayOverlay); |
| 130 | + window.addEventListener("focusout", that.shouldDisplayOverlay); |
| 131 | + }; |
| 132 | + |
| 133 | + gamepad.focusOverlay.listenForModalFocusEvents = function (that) { |
| 134 | + var modalManagerShadowElement = fluid.get(that, "model.modalManagerShadowElement"); |
| 135 | + if (modalManagerShadowElement) { |
| 136 | + modalManagerShadowElement.addEventListener("focusin", that.shouldDisplayOverlay); |
| 137 | + modalManagerShadowElement.addEventListener("focusout", that.shouldDisplayOverlay); |
| 138 | + } |
| 139 | + }; |
107 | 140 | })(fluid);
|
0 commit comments