parent
bdbb11b96a
commit
99a595108b
4 changed files with 66 additions and 3 deletions
@ -0,0 +1,38 @@ |
|||||||
|
export default class Platform { |
||||||
|
static currentPlatform = ""; |
||||||
|
|
||||||
|
static asChanged() { |
||||||
|
let result = Platform.currentPlatform != Platform.detect(); |
||||||
|
Platform.currentPlatform = Platform.detect(); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
static detect() { |
||||||
|
if(window.innerWidth < 640) return "mobile"; |
||||||
|
else if (window.innerWidth < 1150) return "tablet"; |
||||||
|
else if(window.innerWidth < 1450) return "laptop"; |
||||||
|
else return "desktop"; |
||||||
|
} |
||||||
|
|
||||||
|
static getLower(platform) { |
||||||
|
switch(platform) { |
||||||
|
case "mobile": return "mobile"; |
||||||
|
case "tablet": return "mobile"; |
||||||
|
case "laptop": return "tablet"; |
||||||
|
case "desktop": return "laptop";
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static superiorTo(platform) { |
||||||
|
let pf = Platform.detect(); |
||||||
|
while(Platform.asLower(pf)) { |
||||||
|
pf = Platform.getLower(pf); |
||||||
|
if(platform == pf) return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
static asLower(platform) { |
||||||
|
return platform != "mobile"; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in New Issue