]> git.lizzy.rs Git - rust.git/commitdiff
Handle blur on theme buttons nicely
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 26 Apr 2018 21:44:25 +0000 (23:44 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 12 May 2018 17:16:37 +0000 (19:16 +0200)
src/librustdoc/html/render.rs

index 7fff981d09094c8855ec34ed69a80566f8660f47..d6ea9b00a4873ff7ebfd87f18e650a4200889dcd 100644 (file)
@@ -789,7 +789,8 @@ fn write_shared(cx: &Context,
           format!(
 r#"var themes = document.getElementById("theme-choices");
 var themePicker = document.getElementById("theme-picker");
-themePicker.onclick = function() {{
+
+function switchThemeButtonState() {{
     if (themes.style.display === "block") {{
         themes.style.display = "none";
         themePicker.style.borderBottomRightRadius = "3px";
@@ -800,12 +801,29 @@ fn write_shared(cx: &Context,
         themePicker.style.borderBottomLeftRadius = "0";
     }}
 }};
+
+function handleThemeButtonsBlur(e) {{
+    var active = document.activeElement;
+    var related = e.relatedTarget;
+
+    if (active.id !== "themePicker" &&
+        (!active.parentNode || active.parentNode.id !== "theme-choices") &&
+        (!related ||
+         (related.id !== "themePicker" &&
+          (!related.parentNode || related.parentNode.id !== "theme-choices")))) {{
+        switchThemeButtonState();
+    }}
+}}
+
+themePicker.onclick = switchThemeButtonState;
+themePicker.onblur = handleThemeButtonsBlur;
 [{}].forEach(function(item) {{
     var but = document.createElement('button');
     but.innerHTML = item;
     but.onclick = function(el) {{
         switchTheme(currentTheme, mainTheme, item);
     }};
+    but.onblur = handleThemeButtonsBlur;
     themes.appendChild(but);
 }});"#,
                  themes.iter()