(e, opt_viewerNavigate)
| 36 | * @visibleForTesting |
| 37 | */ |
| 38 | export 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 &=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 |
no test coverage detected