MCPcopy Index your code
hub / github.com/ampproject/amphtml / handleClick

Function handleClick

ads/alp/handler.js:38–89  ·  view source on GitHub ↗
(e, opt_viewerNavigate)

Source from the content-addressed store, hash-verified

36 * @visibleForTesting
37 */
38export function handleClick(e, opt_viewerNavigate) {
39 if (e.defaultPrevented) {
40 return;
41 }
42 // Only handle simple clicks with the left mouse button/touch and without
43 // modifier keys.
44 if (e.buttons != 0 && e.buttons != 1) {
45 return;
46 }
47 if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) {
48 return;
49 }
50
51 const link = getLinkInfo(e);
52 if (!link || !link.eventualUrl) {
53 return;
54 }
55 if (e.isTrusted === false) {
56 return;
57 }
58
59 // Tag the original href with &amp=1 and make it a fragment param with
60 // name click.
61 const fragment =
62 'click=' +
63 encodeURIComponent(
64 addParamToUrl(link.a.href, 'amp', '1', /* opt_addToFront */ true)
65 );
66 let destination = link.eventualUrl;
67 if (link.eventualUrl.indexOf('#') == -1) {
68 destination += '#' + fragment;
69 } else {
70 destination += '&' + fragment;
71 }
72 const win = link.a.ownerDocument.defaultView;
73 const ancestors = win.location.ancestorOrigins;
74 if (ancestors && ancestors[ancestors.length - 1] == 'http://localhost:8000') {
75 destination = destination.replace(
76 `${parseUrlDeprecated(link.eventualUrl).host}/c/`,
77 'http://localhost:8000/max/'
78 );
79 }
80 e.preventDefault();
81 if (opt_viewerNavigate) {
82 // TODO: viewer navigate only support navigating top level window to
83 // destination. should we try to open a new window here with target=_blank
84 // here instead of using viewer navigation.
85 opt_viewerNavigate(destination);
86 } else {
87 navigateTo(win, link.a, destination);
88 }
89}
90
91/**
92 * For an event, see if there is an anchor tag in the target

Callers 4

simpleSuccessFunction · 0.90
a2aSuccessFunction · 0.90
noNavigationFunction · 0.90

Calls 5

addParamToUrlFunction · 0.90
parseUrlDeprecatedFunction · 0.90
getLinkInfoFunction · 0.85
navigateToFunction · 0.70
replaceMethod · 0.45

Tested by

no test coverage detected