MCPcopy
hub / github.com/philc/vimium / getLocalHintsForElement

Function getLocalHintsForElement

content_scripts/link_hints.js:1073–1294  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

1071 // one part of element which is clickable (for example, if it's an image); if so, each LocalHint
1072 // represents one of the clickable rectangles of the element.
1073 getLocalHintsForElement(element) {
1074 // Get the tag name. However, `element.tagName` can be an element (not a string, see #2035), so
1075 // we guard against that.
1076 const tagName = element.tagName.toLowerCase?.() || "";
1077 let isClickable = false;
1078 let onlyHasTabIndex = false;
1079 let possibleFalsePositive = false;
1080 const hints = [];
1081 const imageMapAreas = [];
1082 let reason = null;
1083
1084 // Insert area elements that provide click functionality to an img.
1085 if (tagName === "img") {
1086 let mapName = element.getAttribute("usemap");
1087 if (mapName) {
1088 const imgClientRects = element.getClientRects();
1089 mapName = mapName.replace(/^#/, "").replace('"', '\\"');
1090 const map = document.querySelector(`map[name=\"${mapName}\"]`);
1091 if (map && (imgClientRects.length > 0)) {
1092 isClickable = true;
1093 const areas = map.getElementsByTagName("area");
1094 let areasAndRects = DomUtils.getClientRectsForAreas(imgClientRects[0], areas);
1095 // We use this image property when detecting overlapping links.
1096 areasAndRects = areasAndRects.map((o) => Object.assign(o, { image: element }));
1097 imageMapAreas.push(...areasAndRects);
1098 }
1099 }
1100 }
1101
1102 // Check aria properties to see if the element should be ignored.
1103 // Note that we're showing hints for elements with aria-hidden=true. See #3501 for discussion.
1104 const ariaDisabled = element.getAttribute("aria-disabled");
1105 if (ariaDisabled && ["", "true"].includes(ariaDisabled.toLowerCase())) {
1106 return []; // This element should never have a link hint.
1107 }
1108
1109 // Check for AngularJS listeners on the element.
1110 if (!this.checkForAngularJs) {
1111 this.checkForAngularJs = (function () {
1112 const angularElements = document.getElementsByClassName("ng-scope");
1113 if (angularElements.length === 0) {
1114 return () => false;
1115 } else {
1116 const ngAttributes = [];
1117 for (const prefix of ["", "data-", "x-"]) {
1118 for (const separator of ["-", ":", "_"]) {
1119 ngAttributes.push(`${prefix}ng${separator}click`);
1120 }
1121 }
1122 return function (element) {
1123 for (const attribute of ngAttributes) {
1124 if (element.hasAttribute(attribute)) return true;
1125 }
1126 return false;
1127 };
1128 }
1129 })();
1130 }

Callers

nothing calls this directly

Calls 2

windowIsFocusedFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected