Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / ufo.js
blob392a6ca72efb9c234060049153bf3ba337c7e8ff
1 /*      Unobtrusive Flash Objects (UFO) v3.20 <http://www.bobbyvandersluis.com/ufo/>
2         Copyright 2005, 2006 Bobby van der Sluis
3         This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
4 */
6 var UFO = {
7         req: ["movie", "width", "height", "majorversion", "build"],
8         opt: ["play", "loop", "menu", "quality", "scale", "salign", "wmode", "bgcolor", "base", "flashvars", "devicefont", "allowscriptaccess", "seamlesstabbing"],
9         optAtt: ["id", "name", "align"],
10         optExc: ["swliveconnect"],
11         ximovie: "ufo.swf",
12         xiwidth: "215",
13         xiheight: "138",
14         ua: navigator.userAgent.toLowerCase(),
15         pluginType: "",
16         fv: [0,0],
17         foList: [],
18                 
19         create: function(FO, id) {
20                 if (!UFO.uaHas("w3cdom") || UFO.uaHas("ieMac")) return;
21                 UFO.getFlashVersion();
22                 UFO.foList[id] = UFO.updateFO(FO);
23                 UFO.createCSS("#" + id, "visibility:hidden;");
24                 UFO.domLoad(id);
25         },
27         updateFO: function(FO) {
28                 if (typeof FO.xi != "undefined" && FO.xi == "true") {
29                         if (typeof FO.ximovie == "undefined") FO.ximovie = UFO.ximovie;
30                         if (typeof FO.xiwidth == "undefined") FO.xiwidth = UFO.xiwidth;
31                         if (typeof FO.xiheight == "undefined") FO.xiheight = UFO.xiheight;
32                 }
33                 FO.mainCalled = false;
34                 return FO;
35         },
37         domLoad: function(id) {
38                 var _t = setInterval(function() {
39                         if ((document.getElementsByTagName("body")[0] != null || document.body != null) && document.getElementById(id) != null) {
40                                 UFO.main(id);
41                                 clearInterval(_t);
42                         }
43                 }, 250);
44                 if (typeof document.addEventListener != "undefined") {
45                         document.addEventListener("DOMContentLoaded", function() { UFO.main(id); clearInterval(_t); } , null); // Gecko, Opera 9+
46                 }
47         },
49         main: function(id) {
50                 var _fo = UFO.foList[id];
51                 if (_fo.mainCalled) return;
52                 UFO.foList[id].mainCalled = true;
53                 document.getElementById(id).style.visibility = "hidden";
54                 if (UFO.hasRequired(id)) {
55                         if (UFO.hasFlashVersion(parseInt(_fo.majorversion, 10), parseInt(_fo.build, 10))) {
56                                 if (typeof _fo.setcontainercss != "undefined" && _fo.setcontainercss == "true") UFO.setContainerCSS(id);
57                                 UFO.writeSWF(id);
58                         }
59                         else if (_fo.xi == "true" && UFO.hasFlashVersion(6, 65)) {
60                                 UFO.createDialog(id);
61                         }
62                 }
63                 document.getElementById(id).style.visibility = "visible";
64         },
65         
66         createCSS: function(selector, declaration) {
67                 var _h = document.getElementsByTagName("head")[0]; 
68                 var _s = UFO.createElement("style");
69                 if (!UFO.uaHas("ieWin")) _s.appendChild(document.createTextNode(selector + " {" + declaration + "}")); // bugs in IE/Win
70                 _s.setAttribute("type", "text/css");
71                 _s.setAttribute("media", "screen"); 
72                 _h.appendChild(_s);
73                 if (UFO.uaHas("ieWin") && document.styleSheets && document.styleSheets.length > 0) {
74                         var _ls = document.styleSheets[document.styleSheets.length - 1];
75                         if (typeof _ls.addRule == "object") _ls.addRule(selector, declaration);
76                 }
77         },
78         
79         setContainerCSS: function(id) {
80                 var _fo = UFO.foList[id];
81                 var _w = /%/.test(_fo.width) ? "" : "px";
82                 var _h = /%/.test(_fo.height) ? "" : "px";
83                 UFO.createCSS("#" + id, "width:" + _fo.width + _w +"; height:" + _fo.height + _h +";");
84                 if (_fo.width == "100%") {
85                         UFO.createCSS("body", "margin-left:0; margin-right:0; padding-left:0; padding-right:0;");
86                 }
87                 if (_fo.height == "100%") {
88                         UFO.createCSS("html", "height:100%; overflow:hidden;");
89                         UFO.createCSS("body", "margin-top:0; margin-bottom:0; padding-top:0; padding-bottom:0; height:100%;");
90                 }
91         },
93         createElement: function(el) {
94                 return (UFO.uaHas("xml") && typeof document.createElementNS != "undefined") ?  document.createElementNS("http://www.w3.org/1999/xhtml", el) : document.createElement(el);
95         },
97         createObjParam: function(el, aName, aValue) {
98                 var _p = UFO.createElement("param");
99                 _p.setAttribute("name", aName); 
100                 _p.setAttribute("value", aValue);
101                 el.appendChild(_p);
102         },
104         uaHas: function(ft) {
105                 var _u = UFO.ua;
106                 switch(ft) {
107                         case "w3cdom":
108                                 return (typeof document.getElementById != "undefined" && typeof document.getElementsByTagName != "undefined" && (typeof document.createElement != "undefined" || typeof document.createElementNS != "undefined"));
109                         case "xml":
110                                 var _m = document.getElementsByTagName("meta");
111                                 var _l = _m.length;
112                                 for (var i = 0; i < _l; i++) {
113                                         if (/content-type/i.test(_m[i].getAttribute("http-equiv")) && /xml/i.test(_m[i].getAttribute("content"))) return true;
114                                 }
115                                 return false;
116                         case "ieMac":
117                                 return /msie/.test(_u) && !/opera/.test(_u) && /mac/.test(_u);
118                         case "ieWin":
119                                 return /msie/.test(_u) && !/opera/.test(_u) && /win/.test(_u);
120                         case "gecko":
121                                 return /gecko/.test(_u) && !/applewebkit/.test(_u);
122                         case "opera":
123                                 return /opera/.test(_u);
124                         case "safari":
125                                 return /applewebkit/.test(_u);
126                         default:
127                                 return false;
128                 }
129         },
130         
131         getFlashVersion: function() {
132                 if (UFO.fv[0] != 0) return;  
133                 if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
134                         UFO.pluginType = "npapi";
135                         var _d = navigator.plugins["Shockwave Flash"].description;
136                         if (typeof _d != "undefined") {
137                                 _d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
138                                 var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10);
139                                 var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
140                                 UFO.fv = [_m, _r];
141                         }
142                 }
143                 else if (window.ActiveXObject) {
144                         UFO.pluginType = "ax";
145                         try { // avoid fp 6 crashes
146                                 var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
147                         }
148                         catch(e) {
149                                 try { 
150                                         var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
151                                         UFO.fv = [6, 0];
152                                         _a.AllowScriptAccess = "always"; // throws if fp < 6.47 
153                                 }
154                                 catch(e) {
155                                         if (UFO.fv[0] == 6) return;
156                                 }
157                                 try {
158                                         var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
159                                 }
160                                 catch(e) {}
161                         }
162                         if (typeof _a == "object") {
163                                 var _d = _a.GetVariable("$version"); // bugs in fp 6.21/6.23
164                                 if (typeof _d != "undefined") {
165                                         _d = _d.replace(/^\S+\s+(.*)$/, "$1").split(",");
166                                         UFO.fv = [parseInt(_d[0], 10), parseInt(_d[2], 10)];
167                                 }
168                         }
169                 }
170         },
172         hasRequired: function(id) {
173                 var _l = UFO.req.length;
174                 for (var i = 0; i < _l; i++) {
175                         if (typeof UFO.foList[id][UFO.req[i]] == "undefined") return false;
176                 }
177                 return true;
178         },
179         
180         hasFlashVersion: function(major, release) {
181                 return (UFO.fv[0] > major || (UFO.fv[0] == major && UFO.fv[1] >= release)) ? true : false;
182         },
184         writeSWF: function(id) {
185                 var _fo = UFO.foList[id];
186                 var _e = document.getElementById(id);
187                 if (UFO.pluginType == "npapi") {
188                         if (UFO.uaHas("gecko") || UFO.uaHas("xml")) {
189                                 while(_e.hasChildNodes()) {
190                                         _e.removeChild(_e.firstChild);
191                                 }
192                                 var _obj = UFO.createElement("object");
193                                 _obj.setAttribute("type", "application/x-shockwave-flash");
194                                 _obj.setAttribute("data", _fo.movie);
195                                 _obj.setAttribute("width", _fo.width);
196                                 _obj.setAttribute("height", _fo.height);
197                                 var _l = UFO.optAtt.length;
198                                 for (var i = 0; i < _l; i++) {
199                                         if (typeof _fo[UFO.optAtt[i]] != "undefined") _obj.setAttribute(UFO.optAtt[i], _fo[UFO.optAtt[i]]);
200                                 }
201                                 var _o = UFO.opt.concat(UFO.optExc);
202                                 var _l = _o.length;
203                                 for (var i = 0; i < _l; i++) {
204                                         if (typeof _fo[_o[i]] != "undefined") UFO.createObjParam(_obj, _o[i], _fo[_o[i]]);
205                                 }
206                                 _e.appendChild(_obj);
207                         }
208                         else {
209                                 var _emb = "";
210                                 var _o = UFO.opt.concat(UFO.optAtt).concat(UFO.optExc);
211                                 var _l = _o.length;
212                                 for (var i = 0; i < _l; i++) {
213                                         if (typeof _fo[_o[i]] != "undefined") _emb += ' ' + _o[i] + '="' + _fo[_o[i]] + '"';
214                                 }
215                                 _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>';
216                         }
217                 }
218                 else if (UFO.pluginType == "ax") {
219                         var _objAtt = "";
220                         var _l = UFO.optAtt.length;
221                         for (var i = 0; i < _l; i++) {
222                                 if (typeof _fo[UFO.optAtt[i]] != "undefined") _objAtt += ' ' + UFO.optAtt[i] + '="' + _fo[UFO.optAtt[i]] + '"';
223                         }
224                         var _objPar = "";
225                         var _l = UFO.opt.length;
226                         for (var i = 0; i < _l; i++) {
227                                 if (typeof _fo[UFO.opt[i]] != "undefined") _objPar += '<param name="' + UFO.opt[i] + '" value="' + _fo[UFO.opt[i]] + '" />';
228                         }
229                         var _p = window.location.protocol == "https:" ? "https:" : "http:";
230                         _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>';
231                 }
232         },
233                 
234         createDialog: function(id) {
235                 var _fo = UFO.foList[id];
236                 UFO.createCSS("html", "height:100%; overflow:hidden;");
237                 UFO.createCSS("body", "height:100%; overflow:hidden;");
238                 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;");
239                 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;");
240                 var _b = document.getElementsByTagName("body")[0];
241                 var _c = UFO.createElement("div");
242                 _c.setAttribute("id", "xi-con");
243                 var _d = UFO.createElement("div");
244                 _d.setAttribute("id", "xi-dia");
245                 _c.appendChild(_d);
246                 _b.appendChild(_c);
247                 var _mmu = window.location;
248                 if (UFO.uaHas("xml") && UFO.uaHas("safari")) {
249                         var _mmd = document.getElementsByTagName("title")[0].firstChild.nodeValue = document.getElementsByTagName("title")[0].firstChild.nodeValue.slice(0, 47) + " - Flash Player Installation";
250                 }
251                 else {
252                         var _mmd = document.title = document.title.slice(0, 47) + " - Flash Player Installation";
253                 }
254                 var _mmp = UFO.pluginType == "ax" ? "ActiveX" : "PlugIn";
255                 var _uc = typeof _fo.xiurlcancel != "undefined" ? "&xiUrlCancel=" + _fo.xiurlcancel : "";
256                 var _uf = typeof _fo.xiurlfailed != "undefined" ? "&xiUrlFailed=" + _fo.xiurlfailed : "";
257                 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 };
258                 UFO.writeSWF("xi-dia");
259         },
261         expressInstallCallback: function() {
262                 var _b = document.getElementsByTagName("body")[0];
263                 var _c = document.getElementById("xi-con");
264                 _b.removeChild(_c);
265                 UFO.createCSS("body", "height:auto; overflow:auto;");
266                 UFO.createCSS("html", "height:auto; overflow:auto;");
267         },
269         cleanupIELeaks: function() {
270                 var _o = document.getElementsByTagName("object");
271                 var _l = _o.length
272                 for (var i = 0; i < _l; i++) {
273                         _o[i].style.display = "none";
274             var j = 0;
275                         for (var x in _o[i]) {
276                 j++;
277                                 if (typeof _o[i][x] == "function") {
278                                         _o[i][x] = null;
279                                 }
280                 if (j > 1000) {
281                     // something is wrong, probably infinite loop caused by embedded html file
282                     // see MDL-9825
283                     break;
284                 }
285                         }
286                 }
287         }
291 if (typeof window.attachEvent != "undefined" && UFO.uaHas("ieWin")) {
292         window.attachEvent("onunload", UFO.cleanupIELeaks);