2025-11-26 10:19:31 -08:00
|
|
|
/**
|
|
|
|
|
* This script is loaded in testing environments to set up the
|
|
|
|
|
* document based on URL parameters.
|
|
|
|
|
*
|
|
|
|
|
* Test pages (e.g., `chip/test/basic/index.html`) are set to use
|
|
|
|
|
* URL query parameters.
|
|
|
|
|
*
|
|
|
|
|
* Playwright test environments (e.g., `chip/test/basic/chip.e2e.ts`)
|
|
|
|
|
* are set based on whether `setContent` or `goto` has been used:
|
|
|
|
|
* - `setContent` uses URL hash parameters. Tests will break if
|
|
|
|
|
* query parameters are used.
|
|
|
|
|
* - `goto` uses URL query parameters.
|
|
|
|
|
*
|
|
|
|
|
* The following URL parameters are supported:
|
|
|
|
|
* - `rtl`: Set to `true` to enable right-to-left directionality.
|
|
|
|
|
* - `ionic:_testing`: Set to `true` to identify testing environments.
|
|
|
|
|
* - `ionic:mode`: Set to `ios` or `md` to load a specific mode.
|
|
|
|
|
* Defaults to `md`.
|
|
|
|
|
* - `palette`: Set to `light`, `dark`, `high-contrast`, or
|
|
|
|
|
* `high-contrast-dark` to load a specific palette. Defaults to `light`.
|
|
|
|
|
*/
|
2019-01-08 15:06:23 -06:00
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
2025-11-26 10:19:31 -08:00
|
|
|
/**
|
|
|
|
|
* The `rtl` param is used to set the directionality of the
|
|
|
|
|
* document. This can be `true` or `false`.
|
|
|
|
|
*/
|
|
|
|
|
const isRTL = window.location.search.indexOf('rtl=true') > -1 || window.location.hash.indexOf('rtl=true') > -1;
|
|
|
|
|
|
|
|
|
|
if (isRTL) {
|
2019-01-08 15:06:23 -06:00
|
|
|
document.documentElement.setAttribute('dir', 'rtl');
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 10:19:31 -08:00
|
|
|
/**
|
|
|
|
|
* The `ionic:_testing` param is used to identify testing
|
|
|
|
|
* environments.
|
|
|
|
|
*/
|
|
|
|
|
const isTestEnv = window.location.search.indexOf('ionic:_testing=true') > -1 || window.location.hash.indexOf('ionic:_testing=true') > -1;
|
|
|
|
|
|
|
|
|
|
if (isTestEnv) {
|
2019-09-25 18:12:57 +02:00
|
|
|
const style = document.createElement('style');
|
|
|
|
|
style.innerHTML = `
|
2025-11-26 10:19:31 -08:00
|
|
|
* {
|
|
|
|
|
caret-color: transparent !important;
|
|
|
|
|
}
|
|
|
|
|
`;
|
2019-09-25 18:12:57 +02:00
|
|
|
document.head.appendChild(style);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-19 11:48:29 -07:00
|
|
|
/**
|
2025-11-26 10:19:31 -08:00
|
|
|
* The `palette` param is used to load a specific palette
|
|
|
|
|
* for the theme.
|
|
|
|
|
* The dark class will load the dark palette automatically
|
|
|
|
|
* if no palette is specified through the URL.
|
|
|
|
|
*
|
|
|
|
|
* Values can be `light`, `dark`, `high-contrast`,
|
|
|
|
|
* or `high-contrast-dark`. Default to `light` for tests.
|
2024-04-19 11:48:29 -07:00
|
|
|
*/
|
2025-12-08 12:23:53 -08:00
|
|
|
const validPalettes = ['light', 'dark', 'high-contrast', 'high-contrast-dark'];
|
|
|
|
|
const paletteQuery = window.location.search.match(/palette=([a-z-]+)/);
|
|
|
|
|
const paletteHash = window.location.hash.match(/palette=([a-z-]+)/);
|
2025-11-26 10:19:31 -08:00
|
|
|
const darkClass = document.body?.classList.contains('ion-palette-dark') ? 'dark' : null;
|
2025-12-08 12:23:53 -08:00
|
|
|
const highContrastClass = document.body?.classList.contains('ion-palette-high-contrast') ? 'high-contrast' : null;
|
|
|
|
|
const highContrastDarkClass = darkClass && highContrastClass ? 'high-contrast-dark' : null;
|
2025-11-26 10:19:31 -08:00
|
|
|
|
2025-12-08 12:23:53 -08:00
|
|
|
let paletteName = paletteQuery?.[1] || paletteHash?.[1] || highContrastDarkClass || darkClass || highContrastClass || 'light';
|
|
|
|
|
|
|
|
|
|
if (!validPalettes.includes(paletteName)) {
|
|
|
|
|
console.warn(`Invalid palette name: '${paletteName}'. Falling back to 'light' palette.`);
|
|
|
|
|
paletteName = 'light';
|
|
|
|
|
}
|
2025-11-26 10:19:31 -08:00
|
|
|
|
|
|
|
|
if (paletteName !== 'light') {
|
2024-04-19 11:48:29 -07:00
|
|
|
const linkTag = document.createElement('link');
|
|
|
|
|
linkTag.setAttribute('rel', 'stylesheet');
|
|
|
|
|
linkTag.setAttribute('type', 'text/css');
|
2025-11-26 10:19:31 -08:00
|
|
|
linkTag.setAttribute('href', `/css/palettes/${paletteName}.always.css`);
|
2024-04-19 11:48:29 -07:00
|
|
|
document.head.appendChild(linkTag);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 14:50:56 -05:00
|
|
|
window.Ionic = window.Ionic || {};
|
|
|
|
|
window.Ionic.config = window.Ionic.config || {};
|
|
|
|
|
|
2022-04-04 13:34:22 -04:00
|
|
|
window.addEventListener('appload', () => {
|
|
|
|
|
window.testAppLoaded = true;
|
|
|
|
|
})
|
2022-03-31 11:23:21 -04:00
|
|
|
})();
|