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

Method constructor

src/utils/close-watcher-impl.js:20–66  ·  view source on GitHub ↗

* @param {!../service/ampdoc-impl.AmpDoc} ampdoc * @param {function()} handler

(ampdoc, handler)

Source from the content-addressed store, hash-verified

18 * @param {function()} handler
19 */
20 constructor(ampdoc, handler) {
21 const {win} = ampdoc;
22
23 /** @private @const */
24 this.win_ = win;
25
26 /** @private @const */
27 this.handler_ = handler;
28
29 /** @private {?CloseWatcher} */
30 this.watcher_ = null;
31
32 /** @private {?../service/history-impl.History} */
33 this.history_ = null;
34
35 /** @private {number} */
36 this.historyId_ = -1;
37
38 /** @private {?function()} */
39 this.boundCloseOnEscape_ = null;
40
41 if (typeof win.CloseWatcher === 'function') {
42 try {
43 this.watcher_ = new win.CloseWatcher();
44 } catch (e) {
45 dev().error(TAG, 'CloseWatcher failed:', e);
46 }
47 }
48 if (this.watcher_) {
49 this.watcher_.onclose = () => {
50 handler();
51 this.destroy();
52 };
53 } else {
54 this.history_ = Services.historyForDoc(ampdoc);
55 this.history_
56 .push(() => handler())
57 .then((historyId) => {
58 this.historyId_ = historyId;
59 });
60 this.boundCloseOnEscape_ = this.closeOnEscape_.bind(this);
61 win.document.documentElement.addEventListener(
62 'keydown',
63 this.boundCloseOnEscape_
64 );
65 }
66 }
67
68 /**
69 * Signals to the close watcher to close the modal.

Callers

nothing calls this directly

Calls 7

destroyMethod · 0.95
devFunction · 0.90
handlerFunction · 0.50
errorMethod · 0.45
thenMethod · 0.45
pushMethod · 0.45
addEventListenerMethod · 0.45

Tested by

no test coverage detected