]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/swfdetect/swfdetect.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / swfdetect / swfdetect.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('swfdetect', function(Y) {
9
10 /**
11  * Utility for Flash version detection
12  * @module swfdetect
13  */
14
15 // shortcuts
16 var version = 0,
17         uA = Y.UA,
18         lG = Y.Lang,
19         sF = "ShockwaveFlash",
20         mF, eP, vS, ax6, ax;
21
22 function makeInt(n) {
23         return parseInt(n, 10);
24 }
25
26 function parseFlashVersion (flashVer) {
27         if (lG.isNumber(makeInt(flashVer[0]))) {
28                 uA.flashMajor = flashVer[0];
29         }
30         
31         if (lG.isNumber(makeInt(flashVer[1]))) {
32                 uA.flashMinor = flashVer[1];
33         }
34         
35         if (lG.isNumber(makeInt(flashVer[2]))) {
36                 uA.flashRev = flashVer[2];
37         }
38 }
39
40 if (uA.gecko || uA.webkit || uA.opera) {
41    if ((mF = navigator.mimeTypes['application/x-shockwave-flash'])) {
42       if ((eP = mF.enabledPlugin)) {
43          vS = eP.description.replace(/\s[rd]/g, '.').replace(/[A-Za-z\s]+/g, '').split('.');
44                  parseFlashVersion(vS);
45       }
46    }
47 }
48 else if(uA.ie) {
49     try
50     {
51         ax6 = new ActiveXObject(sF + "." + sF + ".6");
52         ax6.AllowScriptAccess = "always";
53     }
54     catch (e)
55     {
56         if(ax6 !== null)
57         {
58             version = 6.0;
59         }
60     }
61     if (version === 0) {
62     try
63     {
64         ax = new ActiveXObject(sF + "." + sF);
65         vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
66         parseFlashVersion(vS);
67     } catch (e2) {}
68     }
69 }
70
71                 
72 Y.SWFDetect = {
73
74         /**
75          * Returns the version of either the Flash Player plugin (in Mozilla/WebKit/Opera browsers),
76          * or the Flash Player ActiveX control (in IE), as a String of the form "MM.mm.rr", where
77          * MM is the major version, mm is the minor version, and rr is the revision.
78          * @method getFlashVersion
79          */     
80         
81         getFlashVersion : function () {
82                 return (String(uA.flashMajor) + "." + String(uA.flashMinor) + "." + String(uA.flashRev));
83         },
84
85         /**
86          * Checks whether the version of the Flash player installed on the user's machine is greater
87          * than or equal to the one specified. If it is, this method returns true; it is false otherwise.
88          * @method isFlashVersionAtLeast
89          * @return {Boolean} Whether the Flash player version is greater than or equal to the one specified.
90          * @param flashMajor {int} The Major version of the Flash player to compare against.
91          * @param flashMinor {int} The Minor version of the Flash player to compare against.
92          * @param flashRev {int} The Revision version of the Flash player to compare against.
93          */     
94         isFlashVersionAtLeast : function (flashMajor, flashMinor, flashRev) {
95                 var uaMajor    = makeInt(uA.flashMajor),
96                         uaMinor    = makeInt(uA.flashMinor),
97                         uaRev      = makeInt(uA.flashRev);
98                         
99                 flashMajor = makeInt(flashMajor || 0);
100                 flashMinor = makeInt(flashMinor || 0);
101                 flashRev   = makeInt(flashRev || 0);
102
103                 if (flashMajor === uaMajor) {
104                         if (flashMinor === uaMinor) {
105                                 return flashRev <= uaRev;
106                         }
107                         return flashMinor < uaMinor;
108                 }
109                 return flashMajor < uaMajor;
110         }                       
111 };
112
113
114 }, '3.3.0' );