PageRenderTime 29ms CodeModel.GetById 15ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/HelloRubberBandCtrl/html-template/AC_OETags.js

http://gmaps-utility-library-flash.googlecode.com/
JavaScript | 292 lines | 242 code | 25 blank | 25 comment | 72 complexity | ae7242475f675615d0553a6ffb9756fa MD5 | raw file
  1// Flash Player Version Detection - Rev 1.6
  2// Detect Client Browser type
  3// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
  4var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
  5var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
  6var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
  7
  8function ControlVersion()
  9{
 10	var version;
 11	var axo;
 12	var e;
 13
 14	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
 15
 16	try {
 17		// version will be set for 7.X or greater players
 18		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
 19		version = axo.GetVariable("$version");
 20	} catch (e) {
 21	}
 22
 23	if (!version)
 24	{
 25		try {
 26			// version will be set for 6.X players only
 27			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
 28			
 29			// installed player is some revision of 6.0
 30			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
 31			// so we have to be careful. 
 32			
 33			// default to the first public version
 34			version = "WIN 6,0,21,0";
 35
 36			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
 37			axo.AllowScriptAccess = "always";
 38
 39			// safe to call for 6.0r47 or greater
 40			version = axo.GetVariable("$version");
 41
 42		} catch (e) {
 43		}
 44	}
 45
 46	if (!version)
 47	{
 48		try {
 49			// version will be set for 4.X or 5.X player
 50			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
 51			version = axo.GetVariable("$version");
 52		} catch (e) {
 53		}
 54	}
 55
 56	if (!version)
 57	{
 58		try {
 59			// version will be set for 3.X player
 60			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
 61			version = "WIN 3,0,18,0";
 62		} catch (e) {
 63		}
 64	}
 65
 66	if (!version)
 67	{
 68		try {
 69			// version will be set for 2.X player
 70			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
 71			version = "WIN 2,0,0,11";
 72		} catch (e) {
 73			version = -1;
 74		}
 75	}
 76	
 77	return version;
 78}
 79
 80// JavaScript helper required to detect Flash Player PlugIn version information
 81function GetSwfVer(){
 82	// NS/Opera version >= 3 check for Flash plugin in plugin array
 83	var flashVer = -1;
 84	
 85	if (navigator.plugins != null && navigator.plugins.length > 0) {
 86		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
 87			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
 88			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
 89			var descArray = flashDescription.split(" ");
 90			var tempArrayMajor = descArray[2].split(".");			
 91			var versionMajor = tempArrayMajor[0];
 92			var versionMinor = tempArrayMajor[1];
 93			var versionRevision = descArray[3];
 94			if (versionRevision == "") {
 95				versionRevision = descArray[4];
 96			}
 97			if (versionRevision[0] == "d") {
 98				versionRevision = versionRevision.substring(1);
 99			} else if (versionRevision[0] == "r") {
100				versionRevision = versionRevision.substring(1);
101				if (versionRevision.indexOf("d") > 0) {
102					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
103				}
104			} else if (versionRevision[0] == "b") {
105				versionRevision = versionRevision.substring(1);
106			}
107			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
108		}
109	}
110	// MSN/WebTV 2.6 supports Flash 4
111	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
112	// WebTV 2.5 supports Flash 3
113	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
114	// older WebTV supports Flash 2
115	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
116	else if ( isIE && isWin && !isOpera ) {
117		flashVer = ControlVersion();
118	}
119	return flashVer;
120}
121
122// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
123function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
124{
125	versionStr = GetSwfVer();
126	if (versionStr == -1 ) {
127		return false;
128	} else if (versionStr != 0) {
129		if(isIE && isWin && !isOpera) {
130			// Given "WIN 2,0,0,11"
131			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
132			tempString        = tempArray[1];			// "2,0,0,11"
133			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
134		} else {
135			versionArray      = versionStr.split(".");
136		}
137		var versionMajor      = versionArray[0];
138		var versionMinor      = versionArray[1];
139		var versionRevision   = versionArray[2];
140
141        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
142		if (versionMajor > parseFloat(reqMajorVer)) {
143			return true;
144		} else if (versionMajor == parseFloat(reqMajorVer)) {
145			if (versionMinor > parseFloat(reqMinorVer))
146				return true;
147			else if (versionMinor == parseFloat(reqMinorVer)) {
148				if (versionRevision >= parseFloat(reqRevision))
149					return true;
150			}
151		}
152		return false;
153	}
154}
155
156function AC_AddExtension(src, ext)
157{
158  var qIndex = src.indexOf('?');
159  if ( qIndex != -1)
160  {
161    // Add the extention (if needed) before the query params
162    var path = src.substring(0, qIndex);
163    if (path.length >= ext.length && path.lastIndexOf(ext) == (path.length - ext.length))
164      return src;
165    else
166      return src.replace(/\?/, ext+'?'); 
167  }
168  else
169  {
170    // Add the extension (if needed) to the end of the URL
171    if (src.length >= ext.length && src.lastIndexOf(ext) == (src.length - ext.length))
172      return src;  // Already have extension
173    else
174      return src + ext;
175  }
176}
177
178function AC_Generateobj(objAttrs, params, embedAttrs) 
179{ 
180    var str = '';
181    if (isIE && isWin && !isOpera)
182    {
183  		str += '<object ';
184  		for (var i in objAttrs)
185  			str += i + '="' + objAttrs[i] + '" ';
186  		str += '>';
187  		for (var i in params)
188  			str += '<param name="' + i + '" value="' + params[i] + '" /> ';
189  		str += '</object>';
190    } else {
191  		str += '<embed ';
192  		for (var i in embedAttrs)
193  			str += i + '="' + embedAttrs[i] + '" ';
194  		str += '> </embed>';
195    }
196
197    document.write(str);
198}
199
200function AC_FL_RunContent(){
201  var ret = 
202    AC_GetArgs
203    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
204     , "application/x-shockwave-flash"
205    );
206  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
207}
208
209function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
210  var ret = new Object();
211  ret.embedAttrs = new Object();
212  ret.params = new Object();
213  ret.objAttrs = new Object();
214  for (var i=0; i < args.length; i=i+2){
215    var currArg = args[i].toLowerCase();    
216
217    switch (currArg){	
218      case "classid":
219        break;
220      case "pluginspage":
221        ret.embedAttrs[args[i]] = args[i+1];
222        break;
223      case "src":
224      case "movie":	
225        args[i+1] = AC_AddExtension(args[i+1], ext);
226        ret.embedAttrs["src"] = args[i+1];
227        ret.params[srcParamName] = args[i+1];
228        break;
229      case "onafterupdate":
230      case "onbeforeupdate":
231      case "onblur":
232      case "oncellchange":
233      case "onclick":
234      case "ondblClick":
235      case "ondrag":
236      case "ondragend":
237      case "ondragenter":
238      case "ondragleave":
239      case "ondragover":
240      case "ondrop":
241      case "onfinish":
242      case "onfocus":
243      case "onhelp":
244      case "onmousedown":
245      case "onmouseup":
246      case "onmouseover":
247      case "onmousemove":
248      case "onmouseout":
249      case "onkeypress":
250      case "onkeydown":
251      case "onkeyup":
252      case "onload":
253      case "onlosecapture":
254      case "onpropertychange":
255      case "onreadystatechange":
256      case "onrowsdelete":
257      case "onrowenter":
258      case "onrowexit":
259      case "onrowsinserted":
260      case "onstart":
261      case "onscroll":
262      case "onbeforeeditfocus":
263      case "onactivate":
264      case "onbeforedeactivate":
265      case "ondeactivate":
266      case "type":
267      case "codebase":
268        ret.objAttrs[args[i]] = args[i+1];
269        break;
270      case "id":
271      case "width":
272      case "height":
273      case "align":
274      case "vspace": 
275      case "hspace":
276      case "class":
277      case "title":
278      case "accesskey":
279      case "name":
280      case "tabindex":
281        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
282        break;
283      default:
284        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
285    }
286  }
287  ret.objAttrs["classid"] = classid;
288  if (mimeType) ret.embedAttrs["type"] = mimeType;
289  return ret;
290}
291
292