MCPcopy Create free account
hub / github.com/ampproject/amphtml / handleClick_

Method handleClick_

src/service/navigation.js:348–375  ·  view source on GitHub ↗

* @param {!Element} element * @param {!Event} e * @private

(element, e)

Source from the content-addressed store, hash-verified

346 * @private
347 */
348 handleClick_(element, e) {
349 this.expandVarsForAnchor_(element);
350
351 let toLocation = this.parseUrl_(element.href);
352
353 // Handle AMP-to-AMP navigation and early-outs, if rel=amphtml.
354 if (this.handleA2AClick_(e, element, toLocation)) {
355 return;
356 }
357
358 // Handle navigating to custom protocol and early-outs, if applicable.
359 if (this.handleCustomProtocolClick_(e, element, toLocation)) {
360 return;
361 }
362
363 const fromLocation = this.getLocation_();
364 // Only apply anchor mutator if this is an external navigation.
365 // Note that anchor mutators may theoretically change the navigation
366 // from external to internal, so we re-parse the new targetLocation
367 // in handleNavigation_().
368 if (getHrefMinusHash(toLocation) != getHrefMinusHash(fromLocation)) {
369 this.applyAnchorMutators_(element, e);
370 toLocation = this.parseUrl_(element.href);
371 }
372
373 // Finally, handle normal click-navigation behavior.
374 this.handleNavigation_(e, element, toLocation, fromLocation);
375 }
376
377 /**
378 * Handles "contextmenu" event e.g. right mouse button click.

Callers 1

handle_Method · 0.95

Calls 8

expandVarsForAnchor_Method · 0.95
parseUrl_Method · 0.95
handleA2AClick_Method · 0.95
getLocation_Method · 0.95
applyAnchorMutators_Method · 0.95
handleNavigation_Method · 0.95
getHrefMinusHashFunction · 0.85

Tested by

no test coverage detected