Prechádzať zdrojové kódy

Doc: Don't move selection highlight when focusing nodes.

Previous behavior was consistent with HTML Help's tree view, but kind of
abnormal for a web page.
Jordan Russell 1 mesiac pred
rodič
commit
b84c956484
3 zmenil súbory, kde vykonal 16 pridanie a 59 odobranie
  1. 1 1
      ISHelp/Staging/contents.css
  2. 14 56
      ISHelp/Staging/contents.js
  3. 1 2
      ISHelp/isetup.xml

+ 1 - 1
ISHelp/Staging/contents.css

@@ -91,7 +91,7 @@ INPUT {
 			color: var(--link-hover-fg-color);
 			text-decoration: underline;
 		}
-		&.selectedlink, &.focusedlink {
+		&[aria-selected="true"] {
 			color: inherit;
 			text-decoration: none;
 

+ 14 - 56
ISHelp/Staging/contents.js

@@ -101,37 +101,20 @@ function init_contents(toggleNode)
 	} else {
 		toggle_node(toggleNode);
 	}
-
-	var elements = document.getElementById("tabbody-contents").getElementsByTagName("a");
-	for (i = 0; i < elements.length; i++) {
-		elements[i].onfocus = node_focused;
-		elements[i].onblur = node_blurred;
-	}
 }
 
 var curSelectedNode = null;
-var curFocusedNode = null;
-
-function update_selected_node_class()
-{
-	if (curSelectedNode) {
-		var newClass = (curFocusedNode == curSelectedNode) ? "focusedlink" : "selectedlink";
-		if (curSelectedNode.className != newClass) {
-			curSelectedNode.className = newClass;
-		}
-	}
-}
 
 function set_selected_node(newSel)
 {
 	if (curSelectedNode == newSel) return;
 
 	if (curSelectedNode) {
-		curSelectedNode.className = "";
+		curSelectedNode.removeAttribute("aria-selected");
 	}
 	curSelectedNode = newSel;
 	if (curSelectedNode) {
-		update_selected_node_class();
+		curSelectedNode.setAttribute("aria-selected", true);
 
 		// Expand parent nodes (may scroll)
 		let p = curSelectedNode;
@@ -143,25 +126,17 @@ function set_selected_node(newSel)
 
 		// Then scroll the node's A element into view
 		ensure_elements_visible(curSelectedNode, curSelectedNode);
-	}
-}
 
-function node_focused(evt)
-{
-	curFocusedNode = evt ? evt.target : event.srcElement;
-	if (curFocusedNode == curSelectedNode) {
-		update_selected_node_class();
-	} else {
-		set_selected_node(curFocusedNode);
+		// If the focus is currently inside the Contents tab panel (and not inside the
+		// topic body frame), then ensure the new selected node is focused. This matters
+		// when Back is clicked in the browser; we want the selection and the focus
+		// rectangle to both move back to the previous node.
+		if (document.getElementById("tabbody-contents").contains(document.activeElement)) {
+			curSelectedNode.focus();
+		}
 	}
 }
 
-function node_blurred(evt)
-{
-	curFocusedNode = null;
-	update_selected_node_class();
-}
-
 var topic_name_regexp = /(?:^|[/\\])topic_([a-z0-9_\-]+)\.htm$/;
 
 function topic_name_from_path(path)
@@ -172,29 +147,12 @@ function topic_name_from_path(path)
 
 function sync_contents(bodyTopic)
 {
-	if (bodyTopic == "") return;
+	if (!bodyTopic) return;
 
-	// If the currently selected node already points to bodyTopic, just return.
-	// This check is needed to keep the selection from jumping to "[Run] section"
-	// when "[UninstallRun] section" is clicked (both have the same target topic).
-	if (curSelectedNode && topic_name_from_path(curSelectedNode.getAttribute("href")) == bodyTopic) {
-		return;
-	}
-
-	var elements = document.getElementById("tabbody-contents").getElementsByTagName("a");
-	var i;
-	for (i = 0; i < elements.length; i++) {
-		if (topic_name_from_path(elements[i].getAttribute("href")) == bodyTopic) {
-			if (curSelectedNode != elements[i]) {
-				// If we're changing the selection while a node is currently
-				// focused -- which can happen if Back is pressed after
-				// clicking/selecting a node -- we need to move the focus.
-				// Otherwise, the focus rectangle would stay where it is,
-				// while the highlight moved to a different node.
-
-				if (curFocusedNode) elements[i].focus();
-				set_selected_node(elements[i]);
-			}
+	const elements = document.getElementById("tabbody-contents").getElementsByTagName("a");
+	for (let i = 0; i < elements.length; i++) {
+		if (topic_name_from_path(elements[i].getAttribute("href")) === bodyTopic) {
+			set_selected_node(elements[i]);
 			break;
 		}
 	}

+ 1 - 2
ISHelp/isetup.xml

@@ -36,9 +36,8 @@
     <contentstopic title="[CustomMessages] section" topic="custommessagessection" />
     <contentstopic title="[LangOptions] section" topic="langoptionssection" />
     <contentstopic title="[Registry] section" topic="registrysection" />
-    <contentstopic title="[Run] section" topic="runsection" />
+    <contentstopic title="[Run] &amp; [UninstallRun] sections" topic="runsection" />
     <contentstopic title="[UninstallDelete] section" topic="uninstalldeletesection" />
-    <contentstopic title="[UninstallRun] section" topic="runsection" />
     <contentstopic title="[ISSigKeys] section" topic="issigkeyssection" />
   </contentsheading>
   <contentsheading title="Pascal Scripting">