Created
September 14, 2012 16:11
-
-
Save nicinabox/3722932 to your computer and use it in GitHub Desktop.
Basic device properties for use when checking screen size or mobile.
This file contains 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
/* | |
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