From 6f8a70834b72d678cd9d171d7bb0a3a2cfb4134d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 7 Mar 2018 13:25:15 +0100 Subject: Add onSelectedVersion callback so it can be handled in any way the caller wishes --- packages/website/ts/components/top_bar/top_bar.tsx | 2 ++ packages/website/ts/pages/documentation/doc_page.tsx | 14 ++++++++++++++ packages/website/ts/utils/utils.ts | 6 ++++++ 3 files changed, 22 insertions(+) (limited to 'packages/website/ts') diff --git a/packages/website/ts/components/top_bar/top_bar.tsx b/packages/website/ts/components/top_bar/top_bar.tsx index 2d6f2b235..29c68524c 100644 --- a/packages/website/ts/components/top_bar/top_bar.tsx +++ b/packages/website/ts/components/top_bar/top_bar.tsx @@ -38,6 +38,7 @@ interface TopBarProps { docsInfo?: DocsInfo; style?: React.CSSProperties; isNightVersion?: boolean; + onVersionSelected?: (semver: string) => void; } interface TopBarState { @@ -320,6 +321,7 @@ export class TopBar extends React.Component { onMenuItemClick={this._onMenuButtonClick.bind(this)} selectedVersion={this.props.docsVersion} versions={this.props.availableDocVersions} + onVersionSelected={this.props.onVersionSelected} /> ); diff --git a/packages/website/ts/pages/documentation/doc_page.tsx b/packages/website/ts/pages/documentation/doc_page.tsx index e0d7b272d..1281219c6 100644 --- a/packages/website/ts/pages/documentation/doc_page.tsx +++ b/packages/website/ts/pages/documentation/doc_page.tsx @@ -13,6 +13,7 @@ import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; import { docUtils } from 'ts/utils/doc_utils'; import { Translate } from 'ts/utils/translate'; +import { utils } from 'ts/utils/utils'; const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4'; @@ -80,6 +81,7 @@ export class DocPage extends React.Component { menuSubsectionsBySection={menuSubsectionsBySection} docsInfo={this.props.docsInfo} translate={this.props.translate} + onVersionSelected={this._onVersionSelected.bind(this)} /> { sidebarHeader={} sourceUrl={sourceUrl} topBarHeight={60} + onVersionSelected={this._onVersionSelected.bind(this)} /> ); @@ -141,4 +144,15 @@ export class DocPage extends React.Component { const sourceUrl = `${url}/blob/${tagPrefix}%40${this.props.docsVersion}/packages${pkg}`; return sourceUrl; } + private _onVersionSelected(semver: string) { + let path = window.location.pathname; + const lastChar = path[path.length - 1]; + if (_.isFinite(_.parseInt(lastChar))) { + const pathSections = path.split('/'); + pathSections.pop(); + path = pathSections.join('/'); + } + const baseUrl = utils.getCurrentBaseUrl(); + window.location.href = `${baseUrl}${path}/${semver}${window.location.hash}`; + } } diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index d35f77e94..308b4bb5c 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -270,4 +270,10 @@ export const utils = { window.onload = () => resolve(); }); }, + getCurrentBaseUrl() { + const port = window.location.port; + const hasPort = !_.isUndefined(port); + const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`; + return baseUrl; + }, }; -- cgit v1.2.3