Subversion Repositories Applications.papyrus

Rev

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