summary refs log tree commit diff
path: root/src/librustdoc/html/static/js/settings.js
AgeCommit message (Collapse)AuthorLines
2023-04-21rustdoc: remove unneeded handleKey from settings.jsMichael Howell-18/+1
This code was added in 9dc5dfb97504c538bc72f367a77bb9f714c30097 and 704050da2334c465784954d81c8990c4bc7a92c5 because the browser- native checkbox was `display: none`, breaking native keyboard accessibility. The native checkbox is now merely `appearance: none`, which does not turn off [behavior semantics], so JavaScript to reimplement it isn't needed any more. [behavior semantics]: https://w3c.github.io/csswg-drafts/css-ui/#appearance-semantics
2023-04-06rustdoc: clean up JSMichael Howell-6/+2
* Stop checking `func` in `onEach`. It's always hard-coded right at the call site, so there's no point. * Use the ternary operator in a few spots where it makes sense. * No point in making `onEach` store `arr.length` in a variable if it's only used once anyway.
2023-01-30Rollup merge of #107177 - thanatos:fix-doc-errant-light-theme, r=notriddleMatthias Krüger-2/+2
Keep all theme-updating logic together Prior to this PR, if the page is restored from the browser bfcache¹, we call `switchToSavedTheme`. But `switchToSavedTheme` never looks at the `use-system-theme` preference. Further, if it can't find a saved theme, it will fall back to the default of "light". For a user with cookies disabled² whose preferred color scheme is dark, this means the theme will wobble back and forth between dark and light. The sequence that occurs is, 1. The page is loaded. During a page load, we consult `use-system-theme`: as cookies are disabled, this preference is unset. The default is true. Because the default is true, we look at the preferred color scheme: for our example user, that's "dark". **The page theme is set to dark.** We'll attempt to store these preferences in localStorage, but fail due to cookies being disabled. 2. The user navigates through the docs. Subsequent page loads happen, and the same process in step 1 recurs. Previous pages are (potentially) put into the bfcache. 3. The user navigates backwards/forwards, causing a page in bfcache to be pulled out of cache. The `pageShow` event handler is triggered. However, this calls `switchToSavedTheme`: this doesn't consider the system theme, as noted above. Instead, it only looks for a saved theme. However, with cookies disabled, there is none. It defaults to light. **The page theme is set to light!** The user wonders why the dark theme is lost. There are effectively two functions trying to determine and apply the correct theme: `updateSystemTheme` and `switchToSavedTheme`. Thus, we merge them into just one: `updateTheme`. This function contains all the logic for determining the correct theme, and is called in all circumstances where we need to set the theme: * The initial page load * If the browser preferred color scheme (i.e., light/dark mode) is changed * If the page is restored from bfcache * If the user updates the theme preferences (i.e., in `settings.js`) Fixes https://github.com/rust-lang/rust/issues/94250. ¹bfcache: https://web.dev/bfcache/ The bfcache is used to sleep a page, if the user navigates away from it, and to restore it from cache if the user returns to it. ²Note that the browser preference that enables/disables cookies really controls many forms of storage. The same preference thus also affects localStorage. (This is so a normal browser user doesn't need to understand the distinction between "cookies" and "localStorage".)
2023-01-30Keep all theme-updating logic togetherRoy Wellington Ⅳ-2/+2
Prior to this PR, if the page is restored from the browser bfcache¹, we call `switchToSavedTheme`. But `switchToSavedTheme` never looks at the `use-system-theme` preference. Further, if it can't find a saved theme, it will fall back to the default of "light". For a user with cookies disabled² whose preferred color scheme is dark, this means the theme will wobble back and forth between dark and light. The sequence that occurs is, 1. The page is loaded. During a page load, we consult `use-system-theme`: as cookies are disabled, this preference is unset. The default is true. Because the default is true, we look at the preferred color scheme: for our example user, that's "dark". **The page theme is set to dark.** We'll attempt to store these preferences in localStorage, but fail due to cookies being disabled. 2. The user navigates through the docs. Subsequent page loads happen, and the same process in step 1 recurs. Previous pages are (potentially) put into the bfcache. 3. The user navigates backwards/forwards, causing a page in bfcache to be pulled out of cache. The `pageShow` event handler is triggered. However, this calls `switchToSavedTheme`: this doesn't consider the system theme, as noted above. Instead, it only looks for a saved theme. However, with cookies disabled, there is none. It defaults to light. **The page theme is set to light!** The user wonders why the dark theme is lost. There are effectively two functions trying to determine and apply the correct theme: `updateSystemTheme` and `switchToSavedTheme`. Thus, we merge them into just one: `updateTheme`. This function contains all the logic for determining the correct theme, and is called in all circumstances where we need to set the theme: * The initial page load * If the browser preferred color scheme (i.e., light/dark mode) is changed * If the page is restored from bfcache * If the user updates the theme preferences (i.e., in `settings.js`) Fixes #94250. ¹bfcache: https://web.dev/bfcache/ The bfcache is used to sleep a page, if the user navigates away from it, and to restore it from cache if the user returns to it. ²Note that the browser preference that enables/disables cookies really controls many forms of storage. The same preference thus also affects localStorage. (This is so a normal browser user doesn't need to understand the distinction between "cookies" and "localStorage".)
2023-01-23rustdoc: remove dead settings JS for obsolete select-wrapperMichael Howell-11/+0
2023-01-23rustdoc: simplify settings popover DOMMichael Howell-19/+21
* Changes the class names so that they all start with `setting-`. That should make it harder to accidentally use a setting class outside the settings popover, where loading the CSS might accidentally change the styles of something unrelated. * Get rid of an unnecessary wrapper DIV around the radio button line. * Simplify CSS selectors by making the DOM easier and more intuitive to target.
2023-01-17rustdoc: instead of `.setting-name { width: 100% }`, use default div CSSMichael Howell-1/+1
2023-01-13rustdoc: rename CSS rustdoc-toggle -> toggle and toggle -> settings-toggleMichael Howell-2/+2
This swaps things around so that the class that gets used more often has the shorter name.
2022-11-26rustdoc: improve popover focus handling JSMichael Howell-1/+1
This commit fixes a few inconsistencies and erratic behavior from the notable traits, settings, and sidebar popups: * It makes it so that pressing Escape closes the mobile sidebar. This is a bit difficult to do on iPhone, but on other setups like desktop tiling window managers, it's easy and makes sense. * It makes sure that pressing escape while a notable trait popover is open focuses the popover's toggle button, instead of leaving nothing focused, since that makes more sense with keyboard navigation. Clicking the settings, help, or sidebar buttons, however, will not focus the notable trait popover toggle button. * It ensures that notable trait and settings popovers are exclusive with the mobile sidebar. Nothing should ever overlap a popover, and there should never be more than one popover open at once.
2022-11-13Simplify settings UI by merging system theme with the theme choicesGuillaume Gomez-24/+36
2022-11-10rustdoc: use checkbox instead of switch for settings togglesMichael Howell-3/+1
The switch is designed to give the application a "physical" feel, but nothing else in here really followed through. They didn't support the "flick" gesture that real iOS switches support, and the radio buttons that were also used in Rustdoc Settings were a more "classic" form element anyway. Also, while "switches" are the exclusive toggle design on iOS (since [Apple HIG] reserves checkboxes for Mac only), the [Google Material] guidelines say that lists of switches are bad, and you should just use check boxes. [Apple HIG]: https://developer.apple.com/design/human-interface-guidelines/components/selection-and-input/toggles [Google Material]: https://m3.material.io/components/checkbox/guidelines#6902f23d-ceba-4b19-ae3b-b78b9b01d185
2022-10-29rustdoc: add hash to filename of toolchain filesJacob Hoffman-Andrews-4/+6
All static files used by rustdoc are now stored in static.files/ and include a hash of their contents. They no longer include the contents of the --resource-suffix flag. This clarifies caching semantics. Anything in static.files can use Cache-Control: immutable because any updates will show up as a new URL. Invocation-specific files like crates-NN.js, search-index-NN.js, and sidebar-items-NN.js still get the resource suffix. The --disable-minification flag is removed because it would vary the output of static files based on invocation flags. Instead, for rustdoc development purposes it's preferable to symlink static files to a non-minified copy for quick iteration.
2022-10-15Fix display of settings pageGuillaume Gomez-1/+3
2022-09-21rustdoc: dynamically show-hide line numbers on code examplesMichael Howell-0/+7
2022-06-23Merge all popover hide functions into oneGuillaume Gomez-7/+5
2022-06-23Move help popup into a pocket menu as wellGuillaume Gomez-22/+8
2022-05-30Improve display of settings radio buttonsGuillaume Gomez-1/+1
2022-05-26Rollup merge of #97394 - GuillaumeGomez:more-eslint-rules, r=notriddleGuillaume Gomez-1/+1
Add more eslint rules This PR adds more eslint rules. Here are the explanations for each of them: * [space-infix-ops](https://eslint.org/docs/rules/space-infix-ops) * [space-before-function-paren](https://eslint.org/docs/rules/space-before-function-paren) * [space-before-blocks](https://eslint.org/docs/rules/space-before-blocks) * [comma-dangle](https://eslint.org/docs/rules/comma-dangle) * [comma-style](https://eslint.org/docs/rules/comma-style) * [max-len](https://eslint.org/docs/rules/max-len) * [eol-last](https://eslint.org/docs/rules/eol-last) r? `@notriddle`
2022-05-25Add new eslint rule "space-before-function-paren"Guillaume Gomez-1/+1
2022-05-24Allow to click on toggle text to update itGuillaume Gomez-6/+5
2022-05-18Move some DOM generation into the HTML settings file directlyGuillaume Gomez-16/+2
2022-05-15Add new eslint rule about brace styleGuillaume Gomez-2/+2
2022-05-14Improve settings menu displayGuillaume Gomez-25/+57
2022-05-07Enforce quote rule for JS source codeGuillaume Gomez-5/+4
2022-05-07Change eslint rules from configuration comments to configuration filesFolyd-4/+0
2022-05-05Rollup merge of #96741 - GuillaumeGomez:improve-settings-loading-strategy, ↵Michael Goulet-4/+1
r=jsha Improve settings loading strategy I learned about this thanks to ```@jsha``` who suggested this approach: It improves the settings loading strategy by loading CSS and JS at the same time to prevent the style to be applied afterwards on slow connections. r? ```@jsha```
2022-05-05Rollup merge of #96704 - GuillaumeGomez:rotation-animation, r=jshaMichael Goulet-0/+1
Add rotation animation on settings button when loading As discussed, I added an animation when the settings JS file is loading (I voluntarily made the timeout at the end of the `settings.js` super long so we can see what the animation looks like): https://user-images.githubusercontent.com/3050060/166693243-816a08b7-5e39-4142-acd3-686ad9950d8e.mp4 r? ````@jsha````
2022-05-05Improve settings loading strategy by loading CSS and JS at the same time to ↵Guillaume Gomez-4/+1
prevent the style to be applied afterwards on slow connections
2022-05-05Add rotation animation on settings button when loadingGuillaume Gomez-0/+1
2022-05-05Use "strict" mode in JS scriptsGuillaume Gomez-0/+2
2022-05-04Move callback to the () => {} syntax.Folyd-6/+7
Fix lint Fix main.js Restore anonymous functions Fix Fix more
2022-05-01* Add documentation for settings page rendering functions.Guillaume Gomez-49/+59
* Improve code. * Fix some documentation argument types. * Make settings order the same as before this PR. * Change timeout to 0 so that browser will render it as fast as possible.
2022-04-30Move settings into full JSGuillaume Gomez-9/+174
2022-04-26Small JS code improvementsGuillaume Gomez-1/+1
2022-04-24Update settings.js to ES6Guillaume Gomez-6/+9
2022-02-02Unify storage getter and setter functionsGuillaume Gomez-1/+1
2022-01-23rustdoc settings: use radio buttons for themeJacob Hoffman-Andrews-10/+19
This reduces the number of clicks required to change theme. Also, simplify the UI a bit (remove setting grouping), and add a "Back" link close to the settings icon.
2022-01-14Add support for "always theme" in settingJacob Hoffman-Andrews-0/+28
2021-07-07Clean up rustdoc static filesGuillaume Gomez-0/+60