The-M-Project icon indicating copy to clipboard operation
The-M-Project copied to clipboard

Mobile / tablet dectection

Open rochejul opened this issue 13 years ago • 0 comments

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

rochejul avatar Oct 03 '12 16:10 rochejul