Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.flash");
12
dojo.require("dojo.string.*");
13
dojo.require("dojo.uri.*");
14
dojo.require("dojo.html.common");
15
dojo.flash = function () {
16
};
17
dojo.flash = {flash6_version:null, flash8_version:null, ready:false, _visible:true, _loadedListeners:new Array(), _installingListeners:new Array(), setSwf:function (fileInfo) {
18
	if (fileInfo == null || dojo.lang.isUndefined(fileInfo)) {
19
		return;
20
	}
21
	if (fileInfo.flash6 != null && !dojo.lang.isUndefined(fileInfo.flash6)) {
22
		this.flash6_version = fileInfo.flash6;
23
	}
24
	if (fileInfo.flash8 != null && !dojo.lang.isUndefined(fileInfo.flash8)) {
25
		this.flash8_version = fileInfo.flash8;
26
	}
27
	if (!dojo.lang.isUndefined(fileInfo.visible)) {
28
		this._visible = fileInfo.visible;
29
	}
30
	this._initialize();
31
}, useFlash6:function () {
32
	if (this.flash6_version == null) {
33
		return false;
34
	} else {
35
		if (this.flash6_version != null && dojo.flash.info.commVersion == 6) {
36
			return true;
37
		} else {
38
			return false;
39
		}
40
	}
41
}, useFlash8:function () {
42
	if (this.flash8_version == null) {
43
		return false;
44
	} else {
45
		if (this.flash8_version != null && dojo.flash.info.commVersion == 8) {
46
			return true;
47
		} else {
48
			return false;
49
		}
50
	}
51
}, addLoadedListener:function (listener) {
52
	this._loadedListeners.push(listener);
53
}, addInstallingListener:function (listener) {
54
	this._installingListeners.push(listener);
55
}, loaded:function () {
56
	dojo.flash.ready = true;
57
	if (dojo.flash._loadedListeners.length > 0) {
58
		for (var i = 0; i < dojo.flash._loadedListeners.length; i++) {
59
			dojo.flash._loadedListeners[i].call(null);
60
		}
61
	}
62
}, installing:function () {
63
	if (dojo.flash._installingListeners.length > 0) {
64
		for (var i = 0; i < dojo.flash._installingListeners.length; i++) {
65
			dojo.flash._installingListeners[i].call(null);
66
		}
67
	}
68
}, _initialize:function () {
69
	var installer = new dojo.flash.Install();
70
	dojo.flash.installer = installer;
71
	if (installer.needed() == true) {
72
		installer.install();
73
	} else {
74
		dojo.flash.obj = new dojo.flash.Embed(this._visible);
75
		dojo.flash.obj.write(dojo.flash.info.commVersion);
76
		dojo.flash.comm = new dojo.flash.Communicator();
77
	}
78
}};
79
dojo.flash.Info = function () {
80
	if (dojo.render.html.ie) {
81
		document.writeln("<script language=\"VBScript\" type=\"text/vbscript\">");
82
		document.writeln("Function VBGetSwfVer(i)");
83
		document.writeln("  on error resume next");
84
		document.writeln("  Dim swControl, swVersion");
85
		document.writeln("  swVersion = 0");
86
		document.writeln("  set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))");
87
		document.writeln("  if (IsObject(swControl)) then");
88
		document.writeln("	swVersion = swControl.GetVariable(\"$version\")");
89
		document.writeln("  end if");
90
		document.writeln("  VBGetSwfVer = swVersion");
91
		document.writeln("End Function");
92
		document.writeln("</script>");
93
	}
94
	this._detectVersion();
95
	this._detectCommunicationVersion();
96
};
97
dojo.flash.Info.prototype = {version:-1, versionMajor:-1, versionMinor:-1, versionRevision:-1, capable:false, commVersion:6, installing:false, isVersionOrAbove:function (reqMajorVer, reqMinorVer, reqVer) {
98
	reqVer = parseFloat("." + reqVer);
99
	if (this.versionMajor >= reqMajorVer && this.versionMinor >= reqMinorVer && this.versionRevision >= reqVer) {
100
		return true;
101
	} else {
102
		return false;
103
	}
104
}, _detectVersion:function () {
105
	var versionStr;
106
	for (var testVersion = 25; testVersion > 0; testVersion--) {
107
		if (dojo.render.html.ie) {
108
			versionStr = VBGetSwfVer(testVersion);
109
		} else {
110
			versionStr = this._JSFlashInfo(testVersion);
111
		}
112
		if (versionStr == -1) {
113
			this.capable = false;
114
			return;
115
		} else {
116
			if (versionStr != 0) {
117
				var versionArray;
118
				if (dojo.render.html.ie) {
119
					var tempArray = versionStr.split(" ");
120
					var tempString = tempArray[1];
121
					versionArray = tempString.split(",");
122
				} else {
123
					versionArray = versionStr.split(".");
124
				}
125
				this.versionMajor = versionArray[0];
126
				this.versionMinor = versionArray[1];
127
				this.versionRevision = versionArray[2];
128
				var versionString = this.versionMajor + "." + this.versionRevision;
129
				this.version = parseFloat(versionString);
130
				this.capable = true;
131
				break;
132
			}
133
		}
134
	}
135
}, _JSFlashInfo:function (testVersion) {
136
	if (navigator.plugins != null && navigator.plugins.length > 0) {
137
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
138
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
139
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
140
			var descArray = flashDescription.split(" ");
141
			var tempArrayMajor = descArray[2].split(".");
142
			var versionMajor = tempArrayMajor[0];
143
			var versionMinor = tempArrayMajor[1];
144
			if (descArray[3] != "") {
145
				var tempArrayMinor = descArray[3].split("r");
146
			} else {
147
				var tempArrayMinor = descArray[4].split("r");
148
			}
149
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
150
			var version = versionMajor + "." + versionMinor + "." + versionRevision;
151
			return version;
152
		}
153
	}
154
	return -1;
155
}, _detectCommunicationVersion:function () {
156
	if (this.capable == false) {
157
		this.commVersion = null;
158
		return;
159
	}
160
	if (typeof djConfig["forceFlashComm"] != "undefined" && typeof djConfig["forceFlashComm"] != null) {
161
		this.commVersion = djConfig["forceFlashComm"];
162
		return;
163
	}
164
	if (dojo.render.html.safari == true || dojo.render.html.opera == true) {
165
		this.commVersion = 8;
166
	} else {
167
		this.commVersion = 6;
168
	}
169
}};
170
dojo.flash.Embed = function (visible) {
171
	this._visible = visible;
172
};
173
dojo.flash.Embed.prototype = {width:215, height:138, id:"flashObject", _visible:true, protocol:function () {
174
	switch (window.location.protocol) {
175
	  case "https:":
176
		return "https";
177
		break;
178
	  default:
179
		return "http";
180
		break;
181
	}
182
}, write:function (flashVer, doExpressInstall) {
183
	if (dojo.lang.isUndefined(doExpressInstall)) {
184
		doExpressInstall = false;
185
	}
186
	var containerStyle = new dojo.string.Builder();
187
	containerStyle.append("width: " + this.width + "px; ");
188
	containerStyle.append("height: " + this.height + "px; ");
189
	if (this._visible == false) {
190
		containerStyle.append("position: absolute; ");
191
		containerStyle.append("z-index: 10000; ");
192
		containerStyle.append("top: -1000px; ");
193
		containerStyle.append("left: -1000px; ");
194
	}
195
	containerStyle = containerStyle.toString();
196
	var objectHTML;
197
	var swfloc;
198
	if (flashVer == 6) {
199
		swfloc = dojo.flash.flash6_version;
200
		var dojoPath = djConfig.baseRelativePath;
201
		swfloc = swfloc + "?baseRelativePath=" + escape(dojoPath);
202
		objectHTML = "<embed id=\"" + this.id + "\" src=\"" + swfloc + "\" " + "	quality=\"high\" bgcolor=\"#ffffff\" " + "	width=\"" + this.width + "\" height=\"" + this.height + "\" " + "	name=\"" + this.id + "\" " + "	align=\"middle\" allowScriptAccess=\"sameDomain\" " + "	type=\"application/x-shockwave-flash\" swLiveConnect=\"true\" " + "	pluginspage=\"" + this.protocol() + "://www.macromedia.com/go/getflashplayer\">";
203
	} else {
204
		swfloc = dojo.flash.flash8_version;
205
		var swflocObject = swfloc;
206
		var swflocEmbed = swfloc;
207
		var dojoPath = djConfig.baseRelativePath;
208
		if (doExpressInstall) {
209
			var redirectURL = escape(window.location);
210
			document.title = document.title.slice(0, 47) + " - Flash Player Installation";
211
			var docTitle = escape(document.title);
212
			swflocObject += "?MMredirectURL=" + redirectURL + "&MMplayerType=ActiveX" + "&MMdoctitle=" + docTitle + "&baseRelativePath=" + escape(dojoPath);
213
			swflocEmbed += "?MMredirectURL=" + redirectURL + "&MMplayerType=PlugIn" + "&baseRelativePath=" + escape(dojoPath);
214
		}
215
		if (swflocEmbed.indexOf("?") == -1) {
216
			swflocEmbed += "?baseRelativePath=" + escape(dojoPath) + "' ";
217
		}
218
		objectHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " + "codebase=\"" + this.protocol() + "://fpdownload.macromedia.com/pub/shockwave/cabs/flash/" + "swflash.cab#version=8,0,0,0\" " + "width=\"" + this.width + "\" " + "height=\"" + this.height + "\" " + "id=\"" + this.id + "\" " + "align=\"middle\"> " + "<param name=\"allowScriptAccess\" value=\"sameDomain\" /> " + "<param name=\"movie\" value=\"" + swflocObject + "\" /> " + "<param name=\"quality\" value=\"high\" /> " + "<param name=\"bgcolor\" value=\"#ffffff\" /> " + "<embed src=\"" + swflocEmbed + "' " + "quality=\"high\" " + "bgcolor=\"#ffffff\" " + "width=\"" + this.width + "\" " + "height=\"" + this.height + "\" " + "id=\"" + this.id + "\" " + "name=\"" + this.id + "\" " + "swLiveConnect=\"true\" " + "align=\"middle\" " + "allowScriptAccess=\"sameDomain\" " + "type=\"application/x-shockwave-flash\" " + "pluginspage=\"" + this.protocol() + "://www.macromedia.com/go/getflashplayer\" />" + "</object>";
219
	}
220
	objectHTML = "<div id=\"" + this.id + "Container\" style=\"" + containerStyle + "\"> " + objectHTML + "</div>";
221
	document.writeln(objectHTML);
222
}, get:function () {
223
	return document.getElementById(this.id);
224
}, setVisible:function (visible) {
225
	var container = dojo.byId(this.id + "Container");
226
	if (visible == true) {
227
		container.style.visibility = "visible";
228
	} else {
229
		container.style.position = "absolute";
230
		container.style.x = "-1000px";
231
		container.style.y = "-1000px";
232
		container.style.visibility = "hidden";
233
	}
234
}, center:function () {
235
	var elementWidth = this.width;
236
	var elementHeight = this.height;
237
	var scroll_offset = dojo.html.getScroll().offset;
238
	var viewport_size = dojo.html.getViewport();
239
	var x = scroll_offset.x + (viewport_size.width - elementWidth) / 2;
240
	var y = scroll_offset.y + (viewport_size.height - elementHeight) / 2;
241
	var container = dojo.byId(this.id + "Container");
242
	container.style.top = y + "px";
243
	container.style.left = x + "px";
244
}};
245
dojo.flash.Communicator = function () {
246
	if (dojo.flash.useFlash6()) {
247
		this._writeFlash6();
248
	} else {
249
		if (dojo.flash.useFlash8()) {
250
			this._writeFlash8();
251
		}
252
	}
253
};
254
dojo.flash.Communicator.prototype = {_writeFlash6:function () {
255
	var id = dojo.flash.obj.id;
256
	document.writeln("<script language=\"JavaScript\">");
257
	document.writeln("  function " + id + "_DoFSCommand(command, args){ ");
258
	document.writeln("	dojo.flash.comm._handleFSCommand(command, args); ");
259
	document.writeln("}");
260
	document.writeln("</script>");
261
	if (dojo.render.html.ie) {
262
		document.writeln("<SCRIPT LANGUAGE=VBScript> ");
263
		document.writeln("on error resume next ");
264
		document.writeln("Sub " + id + "_FSCommand(ByVal command, ByVal args)");
265
		document.writeln(" call " + id + "_DoFSCommand(command, args)");
266
		document.writeln("end sub");
267
		document.writeln("</SCRIPT> ");
268
	}
269
}, _writeFlash8:function () {
270
}, _handleFSCommand:function (command, args) {
271
	if (command != null && !dojo.lang.isUndefined(command) && /^FSCommand:(.*)/.test(command) == true) {
272
		command = command.match(/^FSCommand:(.*)/)[1];
273
	}
274
	if (command == "addCallback") {
275
		this._fscommandAddCallback(command, args);
276
	} else {
277
		if (command == "call") {
278
			this._fscommandCall(command, args);
279
		} else {
280
			if (command == "fscommandReady") {
281
				this._fscommandReady();
282
			}
283
		}
284
	}
285
}, _fscommandAddCallback:function (command, args) {
286
	var functionName = args;
287
	var callFunc = function () {
288
		return dojo.flash.comm._call(functionName, arguments);
289
	};
290
	dojo.flash.comm[functionName] = callFunc;
291
	dojo.flash.obj.get().SetVariable("_succeeded", true);
292
}, _fscommandCall:function (command, args) {
293
	var plugin = dojo.flash.obj.get();
294
	var functionName = args;
295
	var numArgs = parseInt(plugin.GetVariable("_numArgs"));
296
	var flashArgs = new Array();
297
	for (var i = 0; i < numArgs; i++) {
298
		var currentArg = plugin.GetVariable("_" + i);
299
		flashArgs.push(currentArg);
300
	}
301
	var runMe;
302
	if (functionName.indexOf(".") == -1) {
303
		runMe = window[functionName];
304
	} else {
305
		runMe = eval(functionName);
306
	}
307
	var results = null;
308
	if (!dojo.lang.isUndefined(runMe) && runMe != null) {
309
		results = runMe.apply(null, flashArgs);
310
	}
311
	plugin.SetVariable("_returnResult", results);
312
}, _fscommandReady:function () {
313
	var plugin = dojo.flash.obj.get();
314
	plugin.SetVariable("fscommandReady", "true");
315
}, _call:function (functionName, args) {
316
	var plugin = dojo.flash.obj.get();
317
	plugin.SetVariable("_functionName", functionName);
318
	plugin.SetVariable("_numArgs", args.length);
319
	for (var i = 0; i < args.length; i++) {
320
		var value = args[i];
321
		value = value.replace(/\0/g, "\\0");
322
		plugin.SetVariable("_" + i, value);
323
	}
324
	plugin.TCallLabel("/_flashRunner", "execute");
325
	var results = plugin.GetVariable("_returnResult");
326
	results = results.replace(/\\0/g, "\x00");
327
	return results;
328
}, _addExternalInterfaceCallback:function (methodName) {
329
	var wrapperCall = function () {
330
		var methodArgs = new Array(arguments.length);
331
		for (var i = 0; i < arguments.length; i++) {
332
			methodArgs[i] = arguments[i];
333
		}
334
		return dojo.flash.comm._execFlash(methodName, methodArgs);
335
	};
336
	dojo.flash.comm[methodName] = wrapperCall;
337
}, _encodeData:function (data) {
338
	var entityRE = /\&([^;]*)\;/g;
339
	data = data.replace(entityRE, "&amp;$1;");
340
	data = data.replace(/</g, "&lt;");
341
	data = data.replace(/>/g, "&gt;");
342
	data = data.replace("\\", "&custom_backslash;&custom_backslash;");
343
	data = data.replace(/\n/g, "\\n");
344
	data = data.replace(/\r/g, "\\r");
345
	data = data.replace(/\f/g, "\\f");
346
	data = data.replace(/\0/g, "\\0");
347
	data = data.replace(/\'/g, "\\'");
348
	data = data.replace(/\"/g, "\\\"");
349
	return data;
350
}, _decodeData:function (data) {
351
	if (data == null || typeof data == "undefined") {
352
		return data;
353
	}
354
	data = data.replace(/\&custom_lt\;/g, "<");
355
	data = data.replace(/\&custom_gt\;/g, ">");
356
	data = eval("\"" + data + "\"");
357
	return data;
358
}, _chunkArgumentData:function (value, argIndex) {
359
	var plugin = dojo.flash.obj.get();
360
	var numSegments = Math.ceil(value.length / 1024);
361
	for (var i = 0; i < numSegments; i++) {
362
		var startCut = i * 1024;
363
		var endCut = i * 1024 + 1024;
364
		if (i == (numSegments - 1)) {
365
			endCut = i * 1024 + value.length;
366
		}
367
		var piece = value.substring(startCut, endCut);
368
		piece = this._encodeData(piece);
369
		plugin.CallFunction("<invoke name=\"chunkArgumentData\" " + "returntype=\"javascript\">" + "<arguments>" + "<string>" + piece + "</string>" + "<number>" + argIndex + "</number>" + "</arguments>" + "</invoke>");
370
	}
371
}, _chunkReturnData:function () {
372
	var plugin = dojo.flash.obj.get();
373
	var numSegments = plugin.getReturnLength();
374
	var resultsArray = new Array();
375
	for (var i = 0; i < numSegments; i++) {
376
		var piece = plugin.CallFunction("<invoke name=\"chunkReturnData\" " + "returntype=\"javascript\">" + "<arguments>" + "<number>" + i + "</number>" + "</arguments>" + "</invoke>");
377
		if (piece == "\"\"" || piece == "''") {
378
			piece = "";
379
		} else {
380
			piece = piece.substring(1, piece.length - 1);
381
		}
382
		resultsArray.push(piece);
383
	}
384
	var results = resultsArray.join("");
385
	return results;
386
}, _execFlash:function (methodName, methodArgs) {
387
	var plugin = dojo.flash.obj.get();
388
	plugin.startExec();
389
	plugin.setNumberArguments(methodArgs.length);
390
	for (var i = 0; i < methodArgs.length; i++) {
391
		this._chunkArgumentData(methodArgs[i], i);
392
	}
393
	plugin.exec(methodName);
394
	var results = this._chunkReturnData();
395
	results = this._decodeData(results);
396
	plugin.endExec();
397
	return results;
398
}};
399
dojo.flash.Install = function () {
400
};
401
dojo.flash.Install.prototype = {needed:function () {
402
	if (dojo.flash.info.capable == false) {
403
		return true;
404
	}
405
	if (dojo.render.os.mac == true && !dojo.flash.info.isVersionOrAbove(8, 0, 0)) {
406
		return true;
407
	}
408
	if (!dojo.flash.info.isVersionOrAbove(6, 0, 0)) {
409
		return true;
410
	}
411
	return false;
412
}, install:function () {
413
	dojo.flash.info.installing = true;
414
	dojo.flash.installing();
415
	if (dojo.flash.info.capable == false) {
416
		var installObj = new dojo.flash.Embed(false);
417
		installObj.write(8);
418
	} else {
419
		if (dojo.flash.info.isVersionOrAbove(6, 0, 65)) {
420
			var installObj = new dojo.flash.Embed(false);
421
			installObj.write(8, true);
422
			installObj.setVisible(true);
423
			installObj.center();
424
		} else {
425
			alert("This content requires a more recent version of the Macromedia " + " Flash Player.");
426
			window.location.href = +dojo.flash.Embed.protocol() + "://www.macromedia.com/go/getflashplayer";
427
		}
428
	}
429
}, _onInstallStatus:function (msg) {
430
	if (msg == "Download.Complete") {
431
		dojo.flash._initialize();
432
	} else {
433
		if (msg == "Download.Cancelled") {
434
			alert("This content requires a more recent version of the Macromedia " + " Flash Player.");
435
			window.location.href = dojo.flash.Embed.protocol() + "://www.macromedia.com/go/getflashplayer";
436
		} else {
437
			if (msg == "Download.Failed") {
438
				alert("There was an error downloading the Flash Player update. " + "Please try again later, or visit macromedia.com to download " + "the latest version of the Flash plugin.");
439
			}
440
		}
441
	}
442
}};
443
dojo.flash.info = new dojo.flash.Info();
444