Created
August 18, 2012 20:49
-
-
Save rajeshsegu/3389800 to your computer and use it in GitHub Desktop.
jQuery plugin to detect platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jQuery plugin to detect browser platform */ | |
//Idea is extend this to support various browser related environment variables. | |
(function($) { | |
var BrowserEnvironment = { | |
//init browser environment | |
init: function () { | |
//Find platform | |
this.platform = this.detect(this.osData); | |
}, | |
//Detects and populates the environment | |
detect: function(data){ | |
var env = {}, prop, | |
length = data.length; | |
for(var i=0; i< data.length; i++ ){ | |
prop = data[i]; | |
env[prop.attribute] = ( prop.property.indexOf(prop.subString) != -1 ) | |
} | |
return env; | |
}, | |
//Populate as we need | |
osData : [ | |
{ | |
property: navigator.platform, | |
subString: "Win", | |
attribute: "isWindows" | |
}, | |
{ | |
property: navigator.platform, | |
subString: "Mac", | |
attribute: "isMac" | |
}, | |
{ | |
property: navigator.platform, | |
subString: "Linux", | |
attribute: "isLinux" | |
}, | |
{ | |
property: navigator.platform, | |
subString: "iPad", | |
attribute: "isiPad" | |
} | |
] | |
}; | |
//Start browser environment detection | |
BrowserEnvironment.init(); | |
//Make platform accessible via jQuery | |
$.platform = BrowserEnvironment.platform; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is first paragraph.
This is second paragraph.
This is third paragraph.