Skip to content

Commit

Permalink
Enable forcing a specific tab with query parameters (#11681)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Feb 6, 2025
1 parent 7f1a604 commit a8b3d5e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 4 additions & 4 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@
{ "source": "/to/integrate-android-archive", "destination": "/add-to-app/android/project-setup", "type": 301 },
{ "source": "/to/integration-test-on-web", "destination": "/testing/integration-tests#test-in-a-web-browser", "type": 301 },
{ "source": "/to/integration-testing", "destination": "/cookbook/testing/integration/introduction", "type": 301 },
{ "source": "/to/intellij-setup", "destination": "/get-started/editor?tab=androidstudio", "type": 301 },
{ "source": "/to/intellij-setup", "destination": "/get-started/editor/?tab-save-vs-code-vs-intellij=android-studio-and-intellij", "type": 301 },
{ "source": "/to/internationalization", "destination": "/ui/accessibility-and-internationalization/internationalization", "type": 301 },
{ "source": "/to/ios-app-signing", "destination": "/deployment/ios#review-xcode-project-settings", "type": 301 },
{ "source": "/to/ios-create-flutter-engine", "destination": "/add-to-app/ios/add-flutter-screen#create-a-flutterengine", "type": 301 },
Expand Down Expand Up @@ -751,9 +751,9 @@
{ "source": "/to/troubleshoot-devices", "destination": "/get-started/install", "type": 301 },
{ "source": "/to/unbounded-constraints", "destination": "/ui/layout/constraints#unbounded", "type": 301 },
{ "source": "/to/unit-testing", "destination": "/cookbook/testing/unit/introduction", "type": 301 },
{ "source": "/to/update-linux-path", "destination": "/get-started/install/linux/android?tab=download#add-flutter-to-your-path", "type": 301 },
{ "source": "/to/update-macos-path", "destination": "/get-started/install/macos/mobile-ios?tab=download#add-flutter-to-your-path", "type": 301 },
{ "source": "/to/update-windows-path", "destination": "/get-started/install/windows/mobile?tab=download#update-your-windows-path-variable", "type": 301 },
{ "source": "/to/update-linux-path", "destination": "/get-started/install/linux/android?tab-save-vs-code-or-download=download-and-install#add-flutter-to-your-path", "type": 301 },
{ "source": "/to/update-macos-path", "destination": "/get-started/install/macos/mobile-ios?tab-save-vs-code-or-download=download-and-install#add-flutter-to-your-path", "type": 301 },
{ "source": "/to/update-windows-path", "destination": "/get-started/install/windows/mobile?tab-save-vs-code-or-download=download-and-install#update-your-windows-path-variable", "type": 301 },
{ "source": "/to/use-mirror-site", "destination": "/community/china#configure-your-machine-to-use-a-mirror-site", "type": 301 },
{ "source": "/to/use-profile-mode", "destination": "/perf/ui-performance#run-in-profile-mode", "type": 301 },
{ "source": "/to/wasm", "destination": "/platform-integration/web/wasm", "type": 301 },
Expand Down
23 changes: 20 additions & 3 deletions src/content/assets/js/tabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Set up interactivity of tabs created with the `{% tabs %}` shortcode.
*/
/** Set up interactivity of tabs created with the `{% tabs %}` shortcode. */
function setupTabs() {
_applyFromQueryParameters();

const tabsWrappers = document.querySelectorAll('.tabs-wrapper');

tabsWrappers.forEach(function (tabWrapper) {
Expand Down Expand Up @@ -48,6 +48,23 @@ function setupTabs() {
});
}

/** Apply force overrides from query parameters to saved tabs. */
function _applyFromQueryParameters() {
const currentUrl = new URL(window.location.href);
const searchParams = currentUrl.searchParams;
const paramsToDelete = [];

searchParams.forEach((value, key) => {
if (key.startsWith('tab-save-')) {
localStorage.setItem(key, value);
paramsToDelete.push(key);
}
});

paramsToDelete.forEach(key => searchParams.delete(key));
window.history.replaceState({}, '', currentUrl.toString());
}

function _clearActiveTabs(tabs) {
tabs.forEach(function (tab) {
tab.classList.remove('active');
Expand Down
2 changes: 1 addition & 1 deletion src/content/get-started/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ to [Write your first Flutter app][].

[Write your first Flutter app]: /get-started/codelab

{% tabs %}
{% tabs "vs-code-vs-intellij" %}
{% tab "Visual Studio Code" %}

## Install VS Code
Expand Down

0 comments on commit a8b3d5e

Please sign in to comment.