1 /* Unobtrusive Flash Objects (UFO) v3.22 <http://www.bobbyvandersluis.com/ufo/>
2 Copyright 2005-2007 Bobby van der Sluis
3 This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
5 CONTAINS MINOR CHANGE FOR MOODLE (bottom code for MDL-9825)
9 req: ["movie", "width", "height", "majorversion", "build"],
10 opt: ["play", "loop", "menu", "quality", "scale", "salign", "wmode", "bgcolor", "base", "flashvars", "devicefont", "allowscriptaccess", "seamlesstabbing", "allowfullscreen", "allownetworking"],
11 optAtt: ["id", "name", "align"],
12 optExc: ["swliveconnect"],
16 ua: navigator.userAgent.toLowerCase(),
21 create: function(FO, id) {
22 if (!UFO.uaHas("w3cdom") || UFO.uaHas("ieMac")) return;
23 UFO.getFlashVersion();
24 UFO.foList[id] = UFO.updateFO(FO);
25 UFO.createCSS("#" + id, "visibility:hidden;");
29 updateFO: function(FO) {
30 if (typeof FO.xi != "undefined" && FO.xi == "true") {
31 if (typeof FO.ximovie == "undefined") FO.ximovie = UFO.ximovie;
32 if (typeof FO.xiwidth == "undefined") FO.xiwidth = UFO.xiwidth;
33 if (typeof FO.xiheight == "undefined") FO.xiheight = UFO.xiheight;
35 FO.mainCalled = false;
39 domLoad: function(id) {
40 var _t = setInterval(function() {
41 if ((document.getElementsByTagName("body")[0] != null || document.body != null) && document.getElementById(id) != null) {
46 if (typeof document.addEventListener != "undefined") {
47 document.addEventListener("DOMContentLoaded", function() { UFO.main(id); clearInterval(_t); } , null); // Gecko, Opera 9+
52 var _fo = UFO.foList[id];
53 if (_fo.mainCalled) return;
54 UFO.foList[id].mainCalled = true;
55 document.getElementById(id).style.visibility = "hidden";
56 if (UFO.hasRequired(id)) {
57 if (UFO.hasFlashVersion(parseInt(_fo.majorversion, 10), parseInt(_fo.build, 10))) {
58 if (typeof _fo.setcontainercss != "undefined" && _fo.setcontainercss == "true") UFO.setContainerCSS(id);
61 else if (_fo.xi == "true" && UFO.hasFlashVersion(6, 65)) {
65 document.getElementById(id).style.visibility = "visible";
68 createCSS: function(selector, declaration) {
69 var _h = document.getElementsByTagName("head")[0];
70 var _s = UFO.createElement("style");
71 if (!UFO.uaHas("ieWin")) _s.appendChild(document.createTextNode(selector + " {" + declaration + "}")); // bugs in IE/Win
72 _s.setAttribute("type", "text/css");
73 _s.setAttribute("media", "screen");
75 if (UFO.uaHas("ieWin") && document.styleSheets && document.styleSheets.length > 0) {
76 var _ls = document.styleSheets[document.styleSheets.length - 1];
77 if (typeof _ls.addRule == "object") _ls.addRule(selector, declaration);
81 setContainerCSS: function(id) {
82 var _fo = UFO.foList[id];
83 var _w = /%/.test(_fo.width) ? "" : "px";
84 var _h = /%/.test(_fo.height) ? "" : "px";
85 UFO.createCSS("#" + id, "width:" + _fo.width + _w +"; height:" + _fo.height + _h +";");
86 if (_fo.width == "100%") {
87 UFO.createCSS("body", "margin-left:0; margin-right:0; padding-left:0; padding-right:0;");
89 if (_fo.height == "100%") {
90 UFO.createCSS("html", "height:100%; overflow:hidden;");
91 UFO.createCSS("body", "margin-top:0; margin-bottom:0; padding-top:0; padding-bottom:0; height:100%;");
95 createElement: function(el) {
96 return (UFO.uaHas("xml") && typeof document.createElementNS != "undefined") ? document.createElementNS("http://www.w3.org/1999/xhtml", el) : document.createElement(el);
99 createObjParam: function(el, aName, aValue) {
100 var _p = UFO.createElement("param");
101 _p.setAttribute("name", aName);
102 _p.setAttribute("value", aValue);
106 uaHas: function(ft) {
110 return (typeof document.getElementById != "undefined" && typeof document.getElementsByTagName != "undefined" && (typeof document.createElement != "undefined" || typeof document.createElementNS != "undefined"));
112 var _m = document.getElementsByTagName("meta");
114 for (var i = 0; i < _l; i++) {
115 if (/content-type/i.test(_m[i].getAttribute("http-equiv")) && /xml/i.test(_m[i].getAttribute("content"))) return true;
119 return /msie/.test(_u) && !/opera/.test(_u) && /mac/.test(_u);
121 return /msie/.test(_u) && !/opera/.test(_u) && /win/.test(_u);
123 return /gecko/.test(_u) && !/applewebkit/.test(_u);
125 return /opera/.test(_u);
127 return /applewebkit/.test(_u);
133 getFlashVersion: function() {
134 if (UFO.fv[0] != 0) return;
135 if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
136 UFO.pluginType = "npapi";
137 var _d = navigator.plugins["Shockwave Flash"].description;
138 if (typeof _d != "undefined") {
139 _d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
140 var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10);
141 var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
145 else if (window.ActiveXObject) {
146 UFO.pluginType = "ax";
147 try { // avoid fp 6 crashes
148 var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
152 var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
154 _a.AllowScriptAccess = "always"; // throws if fp < 6.47
157 if (UFO.fv[0] == 6) return;
160 var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
164 if (typeof _a == "object") {
165 var _d = _a.GetVariable("$version"); // bugs in fp 6.21/6.23
166 if (typeof _d != "undefined") {
167 _d = _d.replace(/^\S+\s+(.*)$/, "$1").split(",");
168 UFO.fv = [parseInt(_d[0], 10), parseInt(_d[2], 10)];
174 hasRequired: function(id) {
175 var _l = UFO.req.length;
176 for (var i = 0; i < _l; i++) {
177 if (typeof UFO.foList[id][UFO.req[i]] == "undefined") return false;
182 hasFlashVersion: function(major, release) {
183 return (UFO.fv[0] > major || (UFO.fv[0] == major && UFO.fv[1] >= release)) ? true : false;
186 writeSWF: function(id) {
187 var _fo = UFO.foList[id];
188 var _e = document.getElementById(id);
189 if (UFO.pluginType == "npapi") {
190 if (UFO.uaHas("gecko") || UFO.uaHas("xml")) {
191 while(_e.hasChildNodes()) {
192 _e.removeChild(_e.firstChild);
194 var _obj = UFO.createElement("object");
195 _obj.setAttribute("type", "application/x-shockwave-flash");
196 _obj.setAttribute("data", _fo.movie);
197 _obj.setAttribute("width", _fo.width);
198 _obj.setAttribute("height", _fo.height);
199 var _l = UFO.optAtt.length;
200 for (var i = 0; i < _l; i++) {
201 if (typeof _fo[UFO.optAtt[i]] != "undefined") _obj.setAttribute(UFO.optAtt[i], _fo[UFO.optAtt[i]]);
203 var _o = UFO.opt.concat(UFO.optExc);
205 for (var i = 0; i < _l; i++) {
206 if (typeof _fo[_o[i]] != "undefined") UFO.createObjParam(_obj, _o[i], _fo[_o[i]]);
208 _e.appendChild(_obj);
212 var _o = UFO.opt.concat(UFO.optAtt).concat(UFO.optExc);
214 for (var i = 0; i < _l; i++) {
215 if (typeof _fo[_o[i]] != "undefined") _emb += ' ' + _o[i] + '="' + _fo[_o[i]] + '"';
217 _e.innerHTML = '<embed type="application/x-shockwave-flash" src="' + _fo.movie + '" width="' + _fo.width + '" height="' + _fo.height + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' + _emb + '></embed>';
220 else if (UFO.pluginType == "ax") {
222 var _l = UFO.optAtt.length;
223 for (var i = 0; i < _l; i++) {
224 if (typeof _fo[UFO.optAtt[i]] != "undefined") _objAtt += ' ' + UFO.optAtt[i] + '="' + _fo[UFO.optAtt[i]] + '"';
227 var _l = UFO.opt.length;
228 for (var i = 0; i < _l; i++) {
229 if (typeof _fo[UFO.opt[i]] != "undefined") _objPar += '<param name="' + UFO.opt[i] + '" value="' + _fo[UFO.opt[i]] + '" />';
231 var _p = window.location.protocol == "https:" ? "https:" : "http:";
232 _e.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + _objAtt + ' width="' + _fo.width + '" height="' + _fo.height + '" codebase="' + _p + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + _fo.majorversion + ',0,' + _fo.build + ',0"><param name="movie" value="' + _fo.movie + '" />' + _objPar + '</object>';
236 createDialog: function(id) {
237 var _fo = UFO.foList[id];
238 UFO.createCSS("html", "height:100%; overflow:hidden;");
239 UFO.createCSS("body", "height:100%; overflow:hidden;");
240 UFO.createCSS("#xi-con", "position:absolute; left:0; top:0; z-index:1000; width:100%; height:100%; background-color:#fff; filter:alpha(opacity:75); opacity:0.75;");
241 UFO.createCSS("#xi-dia", "position:absolute; left:50%; top:50%; margin-left: -" + Math.round(parseInt(_fo.xiwidth, 10) / 2) + "px; margin-top: -" + Math.round(parseInt(_fo.xiheight, 10) / 2) + "px; width:" + _fo.xiwidth + "px; height:" + _fo.xiheight + "px;");
242 var _b = document.getElementsByTagName("body")[0];
243 var _c = UFO.createElement("div");
244 _c.setAttribute("id", "xi-con");
245 var _d = UFO.createElement("div");
246 _d.setAttribute("id", "xi-dia");
249 var _mmu = window.location;
250 if (UFO.uaHas("xml") && UFO.uaHas("safari")) {
251 var _mmd = document.getElementsByTagName("title")[0].firstChild.nodeValue = document.getElementsByTagName("title")[0].firstChild.nodeValue.slice(0, 47) + " - Flash Player Installation";
254 var _mmd = document.title = document.title.slice(0, 47) + " - Flash Player Installation";
256 var _mmp = UFO.pluginType == "ax" ? "ActiveX" : "PlugIn";
257 var _uc = typeof _fo.xiurlcancel != "undefined" ? "&xiUrlCancel=" + _fo.xiurlcancel : "";
258 var _uf = typeof _fo.xiurlfailed != "undefined" ? "&xiUrlFailed=" + _fo.xiurlfailed : "";
259 UFO.foList["xi-dia"] = { movie:_fo.ximovie, width:_fo.xiwidth, height:_fo.xiheight, majorversion:"6", build:"65", flashvars:"MMredirectURL=" + _mmu + "&MMplayerType=" + _mmp + "&MMdoctitle=" + _mmd + _uc + _uf };
260 UFO.writeSWF("xi-dia");
263 expressInstallCallback: function() {
264 var _b = document.getElementsByTagName("body")[0];
265 var _c = document.getElementById("xi-con");
267 UFO.createCSS("body", "height:auto; overflow:auto;");
268 UFO.createCSS("html", "height:auto; overflow:auto;");
271 cleanupIELeaks: function() {
272 var _o = document.getElementsByTagName("object");
274 for (var i = 0; i < _l; i++) {
275 _o[i].style.display = "none";
277 for (var x in _o[i]) {
279 if (typeof _o[i][x] == "function") {
283 // something is wrong, probably infinite loop caused by embedded html file
293 if (typeof window.attachEvent != "undefined" && UFO.uaHas("ieWin")) {
294 window.attachEvent("onunload", UFO.cleanupIELeaks);