Made the function definition related to UA environment, matchMedia check only happened once.
Merge pull request #1034 from swaydeng/pr_mq

Code refactoring, made the function definition related to UA env