| 31 | changeDetection: ChangeDetectionStrategy.Eager, |
| 32 | }) |
| 33 | export class VersionPicker { |
| 34 | private readonly _versions = httpResource<VersionInfo[]>(() => versionUrl); |
| 35 | |
| 36 | /** The currently running version of Material. */ |
| 37 | materialVersion = normalizedMaterialVersion; |
| 38 | /** The possible versions of the doc site. Empty if they couldn't be loaded. */ |
| 39 | readonly docVersions = computed(() => (this._versions.hasValue() ? this._versions.value() : [])); |
| 40 | |
| 41 | /** |
| 42 | * Updates the window location if the selected version is a different version. |
| 43 | * @param version data for use in navigating to the version's path |
| 44 | */ |
| 45 | onVersionChanged(version: VersionInfo) { |
| 46 | if (!version.url.startsWith(window.location.origin)) { |
| 47 | window.location.assign( |
| 48 | window.location.pathname |
| 49 | ? version.url + window.location.pathname + window.location.hash |
| 50 | : version.url, |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 | } |