|
1 | 1 |
|
2 | 2 | export type Platforms = keyof typeof PLATFORMS_MAP;
|
3 | 3 |
|
4 |
| -export const getPlatforms = (win: any) => setupPlatforms(win); |
| 4 | +interface IsPlatformSignature { |
| 5 | + (plt: Platforms): boolean; |
| 6 | + (win: Window, plt: Platforms): boolean; |
| 7 | +} |
5 | 8 |
|
6 |
| -export const isPlatform = (win: Window, platform: Platforms) => |
7 |
| - getPlatforms(win).indexOf(platform) > -1; |
| 9 | +export const getPlatforms = (win?: any) => setupPlatforms(win); |
8 | 10 |
|
9 |
| -export const setupPlatforms = (win: any) => { |
| 11 | +export const isPlatform: IsPlatformSignature = (winOrPlatform: Window | Platforms | undefined, platform?: Platforms) => { |
| 12 | + if (typeof winOrPlatform === 'string') { |
| 13 | + platform = winOrPlatform; |
| 14 | + winOrPlatform = undefined; |
| 15 | + } |
| 16 | + return getPlatforms(winOrPlatform).includes(platform!); |
| 17 | +}; |
| 18 | + |
| 19 | +export const setupPlatforms = (win: any = window) => { |
10 | 20 | win.Ionic = win.Ionic || {};
|
11 | 21 |
|
12 |
| - let platforms: string[] | undefined | null = win.Ionic.platforms; |
| 22 | + let platforms: Platforms[] | undefined | null = win.Ionic.platforms; |
13 | 23 | if (platforms == null) {
|
14 | 24 | platforms = win.Ionic.platforms = detectPlatforms(win);
|
15 | 25 | platforms.forEach(p => win.document.documentElement.classList.add(`plt-${p}`));
|
16 | 26 | }
|
17 | 27 | return platforms;
|
18 | 28 | };
|
19 | 29 |
|
| 30 | +const detectPlatforms = (win: Window) => |
| 31 | + (Object.keys(PLATFORMS_MAP) as Platforms[]).filter(p => PLATFORMS_MAP[p](win)); |
| 32 | + |
20 | 33 | const isMobileWeb = (win: Window): boolean =>
|
21 | 34 | isMobile(win) && !isHybrid(win);
|
22 | 35 |
|
23 |
| -const detectPlatforms = (win: Window): string[] => |
24 |
| - Object.keys(PLATFORMS_MAP).filter(p => (PLATFORMS_MAP as any)[p](win)); |
25 |
| - |
26 | 36 | const isIpad = (win: Window) =>
|
27 | 37 | testUserAgent(win, /iPad/i);
|
28 | 38 |
|
|
0 commit comments