Skip to content

Instantly share code, notes, and snippets.

@nicinabox
Created September 14, 2012 16:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicinabox/3722932 to your computer and use it in GitHub Desktop.
Save nicinabox/3722932 to your computer and use it in GitHub Desktop.
Basic device properties for use when checking screen size or mobile.
/*
Author: Nic Aitch - @nicinabox
Version: 1.1
Description: Basic device properties for use when checking screen size or mobile.
License: MIT
*/
(function(window, document, undefined) {
var device = {};
// Browser type
device.browser = {
msie: (function() {
return (/msie/i).test(navigator.userAgent);
})()
};
// Screen size
device.screen = window.screen;
// Browser size
device.viewport = {
height: window.innerHeight,
width: window.innerWidth
};
// Mobile device
device.mobile = (/mobile/i).test(navigator.userAgent);
// Make it available
window.device = device;
if (window.addEventListener) {
window.on = window.addEventListener;
} else {
window.on = window.attachEvent;
}
window.on('resize', function(e) {
setTimeout(function() {
device.viewport = {
height: window.innerHeight,
width: window.innerWidth
};
}, 100);
});
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment