mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
fix platform detection
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import * as util from 'ionic/util'
|
||||
import * as util from '../util/util';
|
||||
|
||||
|
||||
let registry = {};
|
||||
@ -7,6 +7,11 @@ let activePlatform;
|
||||
|
||||
class PlatformController {
|
||||
|
||||
constructor(platformQuerystring, userAgent) {
|
||||
this.pqs = platformQuerystring;
|
||||
this.ua = userAgent;
|
||||
}
|
||||
|
||||
get() {
|
||||
if (util.isUndefined(activePlatform)) {
|
||||
this.set(this.detect());
|
||||
@ -45,8 +50,8 @@ class PlatformController {
|
||||
|
||||
detect() {
|
||||
for (let name in registry) {
|
||||
if (registry[name].isMatch()) {
|
||||
return registry[name]
|
||||
if (registry[name].isMatch(this.pqs, this.ua)) {
|
||||
return registry[name];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -57,31 +62,31 @@ class PlatformController {
|
||||
return;
|
||||
}
|
||||
|
||||
util.dom.raf(() => {
|
||||
document.body.classList.add('platform-' + activePlatform.name);
|
||||
});
|
||||
document.body.classList.add('platform-' + activePlatform.name);
|
||||
}
|
||||
}
|
||||
|
||||
export let Platform = new PlatformController();
|
||||
|
||||
|
||||
const ua = window.navigator.userAgent;
|
||||
const queryPlatform = (util.getQuerystring('ionicplatform')).toLowerCase()
|
||||
export let Platform = new PlatformController((util.getQuerystring('ionicplatform')).toLowerCase(), window.navigator.userAgent);
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'android',
|
||||
mode: 'md',
|
||||
isMatch() {
|
||||
return queryPlatform == 'android' || /android/i.test(ua)
|
||||
isMatch(platformQuerystring, userAgent) {
|
||||
if (platformQuerystring) {
|
||||
return platformQuerystring == 'android';
|
||||
}
|
||||
return /android/i.test(userAgent);
|
||||
}
|
||||
});
|
||||
|
||||
Platform.register({
|
||||
name: 'ios',
|
||||
isMatch() {
|
||||
return queryPlatform === 'ios' || /ipad|iphone|ipod/i.test(ua)
|
||||
isMatch(platformQuerystring, userAgent) {
|
||||
if (platformQuerystring) {
|
||||
return platformQuerystring == 'ios';
|
||||
}
|
||||
return /ipad|iphone|ipod/i.test(userAgent);
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user