mui.detect.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * $.os
  3. * @param {type} $
  4. * @returns {undefined}
  5. */
  6. (function($, window) {
  7. function detect(ua) {
  8. this.os = {};
  9. var funcs = [
  10. function() { //wechat
  11. var wechat = ua.match(/(MicroMessenger)\/([\d\.]+)/i);
  12. if (wechat) { //wechat
  13. this.os.wechat = {
  14. version: wechat[2].replace(/_/g, '.')
  15. };
  16. }
  17. return false;
  18. },
  19. function() { //android
  20. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  21. if (android) {
  22. this.os.android = true;
  23. this.os.version = android[2];
  24. this.os.isBadAndroid = !(/Chrome\/\d/.test(window.navigator.appVersion));
  25. }
  26. return this.os.android === true;
  27. },
  28. function() { //ios
  29. var iphone = ua.match(/(iPhone\sOS)\s([\d_]+)/);
  30. if (iphone) { //iphone
  31. this.os.ios = this.os.iphone = true;
  32. this.os.version = iphone[2].replace(/_/g, '.');
  33. } else {
  34. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  35. if (ipad) { //ipad
  36. this.os.ios = this.os.ipad = true;
  37. this.os.version = ipad[2].replace(/_/g, '.');
  38. }
  39. }
  40. return this.os.ios === true;
  41. }
  42. ];
  43. [].every.call(funcs, function(func) {
  44. return !func.call($);
  45. });
  46. }
  47. detect.call($, navigator.userAgent);
  48. })(mui, window);