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