Skip to content

Instantly share code, notes, and snippets.

@datapimp
Created January 7, 2011 18:33
Show Gist options
  • Save datapimp/769881 to your computer and use it in GitHub Desktop.
Save datapimp/769881 to your computer and use it in GitHub Desktop.
Application = {};
Application.is = {
init : function(navigator) {
var platforms = this.platforms,
ln = platforms.length,
i, platform;
navigator = navigator || window.navigator;
for (i = 0; i < ln; i++) {
platform = platforms[i];
this[platform.identity] = platform.regex.test(navigator[platform.property]);
}
this.Desktop = this.Mac || this.Windows || (this.Linux && !this.Android);
this.Tablet = this.iPad;
this.Phone = !this.Desktop && !this.Tablet;
this.iOS = this.iPhone || this.iPad || this.iPod;
this.Standalone = !!window.navigator.standalone;
},
platforms: [{
property: 'platform',
regex: /iPhone/i,
identity: 'iPhone'
},
{
property: 'platform',
regex: /iPod/i,
identity: 'iPod'
},
{
property: 'userAgent',
regex: /iPad/i,
identity: 'iPad'
},
{
property: 'userAgent',
regex: /Blackberry/i,
identity: 'Blackberry'
},
{
property: 'userAgent',
regex: /Android/i,
identity: 'Android'
},
{
property: 'platform',
regex: /Mac/i,
identity: 'Mac'
},
{
property: 'platform',
regex: /Win/i,
identity: 'Windows'
},
{
property: 'platform',
regex: /Linux/i,
identity: 'Linux'
}]
};
Application.is.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment