PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/flash/flash-ua.js

http://kissy.googlecode.com/
JavaScript | 115 lines | 46 code | 12 blank | 57 comment | 13 complexity | f11081e8875bec4fe93745292de7ddf5 MD5 | raw file
  1. /**
  2. * @module Flash UA ??
  3. * @author kingfo<oicuicu@gmail.com>
  4. */
  5. KISSY.add('flash-ua', function(S) {
  6. var UA = S.UA, fpv, fpvF, firstRun = true;
  7. /**
  8. * ?? Flash ???
  9. * ???? [M, S, R] ???????? undefined
  10. */
  11. function getFlashVersion() {
  12. var ver, SF = 'ShockwaveFlash';
  13. // for NPAPI see: http://en.wikipedia.org/wiki/NPAPI
  14. if (navigator.plugins && navigator.mimeTypes.length) {
  15. ver = (navigator.plugins['Shockwave Flash'] || 0).description;
  16. }
  17. // for ActiveX see: http://en.wikipedia.org/wiki/ActiveX
  18. else if (window.ActiveXObject) {
  19. try {
  20. ver = new ActiveXObject(SF + '.' + SF)['GetVariable']('$version');
  21. } catch(ex) {
  22. //S.log('getFlashVersion failed via ActiveXObject');
  23. // nothing to do, just return undefined
  24. }
  25. }
  26. // ???????????ver ? undefined
  27. if(!ver) return;
  28. // ????????ver ? "Shockwave Flash 10.1 r53" or "WIN 10,1,53,64"
  29. return arrify(ver);
  30. }
  31. /**
  32. * arrify("10.1.r53") => ["10", "1", "53"]
  33. */
  34. function arrify(ver) {
  35. return ver.match(/(\d)+/g).splice(0,3);
  36. }
  37. /**
  38. * ???????Major.????Minor(????3???3?)?????Revision(?????4??8???5?)
  39. * ver ??????????? 0
  40. * numerify("10.1 r53") => 10.00100053
  41. * numerify(["10", "1", "53"]) => 10.00100053
  42. * numerify(12.2) => 12.2
  43. */
  44. function numerify(ver) {
  45. var arr = S.isString(ver) ? arrify(ver) : ver, ret = ver;
  46. if (S.isArray(arr)) {
  47. ret = parseFloat(arr[0] + '.' + pad(arr[1], 3) + pad(arr[2], 5));
  48. }
  49. return ret || 0;
  50. }
  51. /**
  52. * pad(12, 5) => "00012"
  53. * ref: http://lifesinger.org/blog/2009/08/the-harm-of-tricky-code/
  54. */
  55. function pad(num, n) {
  56. var len = (num + '').length;
  57. while (len++ < n) {
  58. num = '0' + num;
  59. }
  60. return num;
  61. }
  62. /**
  63. * ???? [M, S, R] ???????? undefined
  64. * fpv ??? flash player version
  65. */
  66. UA.fpv = function(force) {
  67. // ?? new ActiveX ? try catch ? ?????????????????
  68. if(force || firstRun) {
  69. firstRun = false;
  70. fpv = getFlashVersion();
  71. fpvF = numerify(fpv);
  72. }
  73. return fpv;
  74. };
  75. /**
  76. * Checks fpv is greater than or equal the specific version.
  77. * ??? flash ???????????
  78. * @param ver eg. "10.1.53"
  79. * <code>
  80. * if(S.UA.fpvGEQ('9.9.2')) { ... }
  81. * </code>
  82. */
  83. UA.fpvGEQ = function(ver, force) {
  84. if(firstRun) UA.fpv(force);
  85. return !!fpvF && (fpvF >= numerify(ver));
  86. };
  87. }, { host: 'flash' });
  88. /**
  89. * NOTES:
  90. *
  91. - ActiveXObject JS ??
  92. - newObj = new ActiveXObject(ProgID:String[, location:String])
  93. - newObj ?? ???? ActiveXObject ???
  94. - ProgID ?? ??? "serverName.typeName" ????
  95. - serverName ?? ?????????????
  96. - typeName ?? ??????????
  97. - location ?? ??????????????
  98. - Google Chrome ?????
  99. - ??????? flashplay ?? ????? Flashplayer
  100. - ref: http://googlechromereleases.blogspot.com/2010/03/dev-channel-update_30.html
  101. *
  102. */