Blame view

static/plugins/webshim-gh-pages/js-webshim/dev/shims/swfmini.js 6.56 KB
831eac332   zhuzhenchao   add file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  /*!	SWFMini - a SWFObject 2.2 cut down version for webshims
   * 
   * based on SWFObject v2.2 <http://code.google.com/p/swfobject/> 
  	is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
  */
  
  var swfmini = function() {
  	var wasRemoved = function(){webshims.error('This method was removed from swfmini');};
  	var UNDEF = "undefined",
  		OBJECT = "object",
  		webshims = window.webshims,
  		SHOCKWAVE_FLASH = "Shockwave Flash",
  		SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
  		FLASH_MIME_TYPE = "application/x-shockwave-flash",
  		
  		win = window,
  		doc = document,
  		nav = navigator,
  		
  		plugin = false,
  		domLoadFnArr = [main],
  
  		isDomLoaded = false,
  		autoHideShow = true,
  	
  	/* Centralized function for browser feature detection
  		- User agent string detection is only used when no good alternative is possible
  		- Is executed directly for optimal performance
  	*/	
  	ua = function() {
  		var w3cdom = typeof doc.getElementById != UNDEF && typeof doc.getElementsByTagName != UNDEF && typeof doc.createElement != UNDEF,
  			u = nav.userAgent.toLowerCase(),
  			p = nav.platform.toLowerCase(),
  			windows = p ? /win/.test(p) : /win/.test(u),
  			mac = p ? /mac/.test(p) : /mac/.test(u),
  			webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, // returns either the webkit version or false if not webkit
  			ie = !+"\v1", // feature detection based on Andrea Giammarchi's solution: http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html
  			playerVersion = [0,0,0],
  			d = null;
  		if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
  			d = nav.plugins[SHOCKWAVE_FLASH].description;
  			if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) { // navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
  				plugin = true;
  				ie = false; // cascaded feature detection for Internet Explorer
  				d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
  				playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
  				playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
  				playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
  			}
  		}
  		else if (typeof win.ActiveXObject != UNDEF) {
  			try {
  				var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
  				if (a) { // a will return null when ActiveX is disabled
  					d = a.GetVariable("$version");
  					if (d) {
  						ie = true; // cascaded feature detection for Internet Explorer
  						d = d.split(" ")[1].split(",");
  						playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
  					}
  				}
  			}
  			catch(e) {}
  		}
  		return { w3:w3cdom, pv:playerVersion, wk:webkit, ie:ie, win:windows, mac:mac };
  	}();
  	
  	
  	function callDomLoadFunctions() {
  		if (isDomLoaded) { return; }
  		isDomLoaded = true;
  		var dl = domLoadFnArr.length;
  		for (var i = 0; i < dl; i++) {
  			domLoadFnArr[i]();
  		}
  	}
  	
  	function addDomLoadEvent(fn) {
  		if (isDomLoaded) {
  			fn();
  		}
  		else { 
  			domLoadFnArr[domLoadFnArr.length] = fn; // Array.push() is only available in IE5.5+
  		}
  	}
  
  	
  	/* Main function
  		- Will preferably execute onDomLoad, otherwise onload (as a fallback)
  	*/
  	function main() { 
  		if (plugin) {
  			testPlayerVersion();
  		}
  	}
  	
  	/* Detect the Flash Player version for non-Internet Explorer browsers
  		- Detecting the plug-in version via the object element is more precise than using the plugins collection item's description:
  		  a. Both release and build numbers can be detected
  		  b. Avoid wrong descriptions by corrupt installers provided by Adobe
  		  c. Avoid wrong descriptions by multiple Flash Player entries in the plugin Array, caused by incorrect browser imports
  		- Disadvantage of this method is that it depends on the availability of the DOM, while the plugins collection is immediately available
  	*/
  	function testPlayerVersion() {
  		var b = doc.getElementsByTagName("body")[0];
  		var o = createElement(OBJECT);
  		o.setAttribute("type", FLASH_MIME_TYPE);
  		var t = b.appendChild(o);
  		if (t) {
  			var counter = 0;
  			(function(){
  				if (typeof t.GetVariable != UNDEF) {
  					var d = t.GetVariable("$version");
  					if (d) {
  						d = d.split(" ")[1].split(",");
  						ua.pv = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
  					}
  				}
  				else if (counter < 10) {
  					counter++;
  					setTimeout(arguments.callee, 10);
  					return;
  				}
  				b.removeChild(o);
  				t = null;
  			})();
  		}
  	}
  
  	
  	function createElement(el) {
  		return doc.createElement(el);
  	}
  	
  
  	/* Flash Player and SWF content version matching
  	*/
  	function hasPlayerVersion(rv) {
  		var pv = ua.pv, v = rv.split(".");
  		v[0] = parseInt(v[0], 10);
  		v[1] = parseInt(v[1], 10) || 0; // supports short notation, e.g. "9" instead of "9.0.0"
  		v[2] = parseInt(v[2], 10) || 0;
  		return (pv[0] > v[0] || (pv[0] == v[0] && pv[1] > v[1]) || (pv[0] == v[0] && pv[1] == v[1] && pv[2] >= v[2])) ? true : false;
  	}
  	
  	
  
  
  
  	webshims.ready('DOM', callDomLoadFunctions);
  
  	webshims.loader.addModule('swfmini-embed', {d: ['swfmini']});
  	var loadEmbed = hasPlayerVersion('9.0.0') ?
  		function(){
  			webshims.loader.loadList(['swfmini-embed']);
  			return true;
  		} :
  		webshims.$.noop
  	;
  
  	if(!webshims.support.mediaelement){
  		loadEmbed();
  	} else {
  		webshims.ready('WINDOWLOAD', loadEmbed);
  	}
  
  	return {
  		/* Public API
  			- Reference: http://code.google.com/p/swfobject/wiki/documentation
  		*/ 
  		registerObject: wasRemoved,
  		
  		getObjectById: wasRemoved,
  		
  		embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) {
  			var args = arguments;
  			if(loadEmbed()){
  				webshims.ready('swfmini-embed', function(){
  					swfmini.embedSWF.apply(swfmini, args);
  				});
  			} else if(callbackFn) {
  				callbackFn({success:false, id:replaceElemIdStr});
  			}
  		},
  		
  		switchOffAutoHideShow: function() {
  			autoHideShow = false;
  		},
  		
  		ua: ua,
  		
  		getFlashPlayerVersion: function() {
  			return { major:ua.pv[0], minor:ua.pv[1], release:ua.pv[2] };
  		},
  		
  		hasFlashPlayerVersion: hasPlayerVersion,
  		
  		createSWF: function(attObj, parObj, replaceElemIdStr) {
  			if (ua.w3) {
  				return createSWF(attObj, parObj, replaceElemIdStr);
  			}
  			else {
  				return undefined;
  			}
  		},
  		
  		showExpressInstall: wasRemoved,
  		
  		removeSWF: wasRemoved,
  		
  		createCSS: wasRemoved,
  		
  		addDomLoadEvent: addDomLoadEvent,
  		
  		addLoadEvent: wasRemoved,
  		
  		
  		// For internal usage only
  		expressInstallCallback: wasRemoved
  	};
  }();
  
  webshims.isReady('swfmini', true);