Merge branch 'MDL-32509' of git://github.com/danpoltawski/moodle
[moodle.git] / lib / yui / 3.5.0 / build / swfdetect / swfdetect.js
blob118a70475556d38a6bfe4d9e2e621ed7884df719
1 /*
2 YUI 3.5.0 (build 5089)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('swfdetect', function(Y) {
9 /**
10  * Utility for Flash version detection
11  * @module swfdetect
12  */
14 // Shortcuts and helper methods
15 var version = 0,
16     uA = Y.UA,
17     lG = Y.Lang,
18     sF = "ShockwaveFlash",
19     mF, eP, vS, ax6, ax;
21 function makeInt(n) {
22     return parseInt(n, 10);
25 function parseFlashVersion (flashVer) {
26     if (lG.isNumber(makeInt(flashVer[0]))) {
27         uA.flashMajor = flashVer[0];
28     }
29     
30     if (lG.isNumber(makeInt(flashVer[1]))) {
31         uA.flashMinor = flashVer[1];
32     }
33     
34     if (lG.isNumber(makeInt(flashVer[2]))) {
35         uA.flashRev = flashVer[2];
36     }
39 if (uA.gecko || uA.webkit || uA.opera) {
40    if ((mF = navigator.mimeTypes['application/x-shockwave-flash'])) {
41       if ((eP = mF.enabledPlugin)) {
42          vS = eP.description.replace(/\s[rd]/g, '.').replace(/[A-Za-z\s]+/g, '').split('.');
43          parseFlashVersion(vS);
44       }
45    }
47 else if(uA.ie) {
48     try
49     {
50         ax6 = new ActiveXObject(sF + "." + sF + ".6");
51         ax6.AllowScriptAccess = "always";
52     }
53     catch (e)
54     {
55         if(ax6 !== null)
56         {
57             version = 6.0;
58         }
59     }
60     if (version === 0) {
61     try
62     {
63         ax = new ActiveXObject(sF + "." + sF);
64         vS = ax.GetVariable("$version").replace(/[A-Za-z\s]+/g, '').split(',');
65         parseFlashVersion(vS);
66     } catch (e2) {}
67     }
70 /** Create a calendar view to represent a single or multiple
71   * month range of dates, rendered as a grid with date and
72   * weekday labels.
73   * 
74   * @class SWFDetect
75   * @constructor
76   */
78         
79 Y.SWFDetect = {
81     /**
82      * Returns the version of either the Flash Player plugin (in Mozilla/WebKit/Opera browsers),
83      * or the Flash Player ActiveX control (in IE), as a String of the form "MM.mm.rr", where
84      * MM is the major version, mm is the minor version, and rr is the revision.
85      * @method getFlashVersion
86      */ 
87     
88     getFlashVersion : function () {
89         return (String(uA.flashMajor) + "." + String(uA.flashMinor) + "." + String(uA.flashRev));
90     },
92     /**
93      * Checks whether the version of the Flash player installed on the user's machine is greater
94      * than or equal to the one specified. If it is, this method returns true; it is false otherwise.
95      * @method isFlashVersionAtLeast
96      * @return {Boolean} Whether the Flash player version is greater than or equal to the one specified.
97      * @param flashMajor {int} The Major version of the Flash player to compare against.
98      * @param flashMinor {int} The Minor version of the Flash player to compare against.
99      * @param flashRev {int} The Revision version of the Flash player to compare against.
100      */ 
101     isFlashVersionAtLeast : function (flashMajor, flashMinor, flashRev) {
102         var uaMajor    = makeInt(uA.flashMajor),
103             uaMinor    = makeInt(uA.flashMinor),
104             uaRev      = makeInt(uA.flashRev);
105             
106         flashMajor = makeInt(flashMajor || 0);
107         flashMinor = makeInt(flashMinor || 0);
108         flashRev   = makeInt(flashRev || 0);
110         if (flashMajor === uaMajor) {
111             if (flashMinor === uaMinor) {
112                 return flashRev <= uaRev;
113             }
114             return flashMinor < uaMinor;
115         }
116         return flashMajor < uaMajor;
117     }           
121 }, '3.5.0' ,{requires:['yui-base']});