一起来HTML5吧!

 

 

搜索
一起HTML5 论坛 LimeJS LimeJS教程 LimeJS教会了你什么1——客户端认证
查看: 1961|回复: 0
go

LimeJS教会了你什么1——客户端认证

Rank: 9Rank: 9Rank: 9

发表于 2011-4-21 17:35 |显示全部帖子
  1. goog.provide('lime.userAgent');

  2. goog.require('goog.userAgent');


  3. (function() {


  4. var ua = goog.userAgent.getUserAgentString();

  5. /**
  6. * Whether the user agent is running on iOS device
  7. * @type boolean
  8. */
  9. lime.userAgent.IOS = goog.userAgent.WEBKIT && goog.userAgent.MOBILE &&
  10.     (/(ipod|iphone|ipad)/i).test(ua);


  11. /**
  12. * Whether the user agent is running on Android device
  13. * @type boolean
  14. */
  15. lime.userAgent.ANDROID = goog.userAgent.WEBKIT && goog.userAgent.MOBILE &&
  16.     (/(android)/i).test(ua);


  17. /**
  18. * Whether the user agent is running on iPad
  19. * @type boolean
  20. */
  21. lime.userAgent.IPAD = lime.userAgent.IOS && (/(ipad)/i).test(ua);


  22. /**
  23. * Whether the user agent is running on iPhone 4
  24. * @type boolean
  25. */
  26. lime.userAgent.IPHONE4 = lime.userAgent.IOS &&
  27.     goog.global['devicePixelRatio'] >= 2;


  28. /**
  29. * Whether the user agent is running on touch based device
  30. * @type boolean
  31. */
  32. lime.userAgent.SUPPORTS_TOUCH = goog.isDef(document['ontouchmove']);


  33. })();
复制代码

浏览器内核的判定,以及是否为移动设备平台,这两点的判断closure都帮LimeJS做了。剩下的小技巧从上面的代码里发掘,再直白不过了。


该贴已经同步到 stefan的微博
扣腚——一个永恒的话题!
你需要登录后才可以回帖 登录 | 注册
验证码 换一个

Archiver|一起HTML5 ( 京ICP备08008764号-2 )

GMT+8, 2012-5-20 12:17 , Processed in 0.055051 second(s), 13 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.