The-M-Project
The-M-Project copied to clipboard
Mobile / tablet dectection
Hi,
A fancy enhancement will to include a detection of the device and put it into M.Environment.
We could have: isDeviceMobile or isDeviceTablet.
Here the following code:
M.Environment = M.Object.extend(
{
isDeviceMobile: function() {
if(window.matchMedia("(orientation:landscape)").matches){
return window.matchMedia("(max-height:640px)").matches;
}
return window.matchMedia("(max-width:640px)").matches;
},
isDeviceTablet: function() {
return !this.isDeviceMobile();
}
}
);
Cheers