MCPcopy
hub / github.com/ampproject/amphtml / constructor

Method constructor

src/focus-history.js:17–57  ·  view source on GitHub ↗

* @param {!Window} win * @param {number} purgeTimeout

(win, purgeTimeout)

Source from the content-addressed store, hash-verified

15 * @param {number} purgeTimeout
16 */
17 constructor(win, purgeTimeout) {
18 /** @const {!Window} */
19 this.win = win;
20
21 /** @private @const {number} */
22 this.purgeTimeout_ = purgeTimeout;
23
24 /** @private @const {!Array<!{el: !Element, time: time}>} */
25 this.history_ = [];
26
27 /** @private @const {!Observable<!Element>} */
28 this.observeFocus_ = new Observable();
29
30 /**
31 * @private
32 * @param {!Event} e
33 */
34 this.captureFocus_ = (e) => {
35 // Hack (#15079) due to Firefox firing focus events on the entire page
36 if (isElement(e.target)) {
37 this.pushFocus_(dev().assertElement(e.target));
38 }
39 };
40
41 /**
42 * @private
43 * @param {*} unusedE
44 */
45 this.captureBlur_ = (unusedE) => {
46 // IFrame elements do not receive `focus` event. An alternative way is
47 // implemented here. We wait for a blur to arrive on the main window
48 // and after a short time check which element is active.
49 Services.timerFor(win).delay(() => {
50 if (this.win.document.activeElement) {
51 this.pushFocus_(this.win.document.activeElement);
52 }
53 }, 500);
54 };
55 this.win.document.addEventListener('focus', this.captureFocus_, true);
56 this.win.addEventListener('blur', this.captureBlur_);
57 }
58
59 /** @visibleForTesting */
60 cleanup_() {

Callers

nothing calls this directly

Calls 6

pushFocus_Method · 0.95
isElementFunction · 0.90
devFunction · 0.90
assertElementMethod · 0.80
delayMethod · 0.80
addEventListenerMethod · 0.45

Tested by

no test coverage detected