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/>
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"],
14 ua
: navigator
.userAgent
.toLowerCase(),
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;");
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
;
33 FO
.mainCalled
= false;
37 domLoad: function(id
) {
38 var _t
= setInterval(function() {
39 if ((document
.getElementsByTagName("body")[0] != null || document
.body
!= null) && document
.getElementById(id
) != null) {
44 if (typeof document
.addEventListener
!= "undefined") {
45 document
.addEventListener("DOMContentLoaded", function() { UFO
.main(id
); clearInterval(_t
); } , null); // Gecko, Opera 9+
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
);
59 else if (_fo
.xi
== "true" && UFO
.hasFlashVersion(6, 65)) {
63 document
.getElementById(id
).style
.visibility
= "visible";
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");
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
);
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;");
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%;");
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
);
97 createObjParam: function(el
, aName
, aValue
) {
98 var _p
= UFO
.createElement("param");
99 _p
.setAttribute("name", aName
);
100 _p
.setAttribute("value", aValue
);
104 uaHas: function(ft
) {
108 return (typeof document
.getElementById
!= "undefined" && typeof document
.getElementsByTagName
!= "undefined" && (typeof document
.createElement
!= "undefined" || typeof document
.createElementNS
!= "undefined"));
110 var _m
= document
.getElementsByTagName("meta");
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;
117 return /msie/.test(_u
) && !/opera/.test(_u
) && /mac/.test(_u
);
119 return /msie/.test(_u
) && !/opera/.test(_u
) && /win/.test(_u
);
121 return /gecko/.test(_u
) && !/applewebkit/.test(_u
);
123 return /opera/.test(_u
);
125 return /applewebkit/.test(_u
);
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;
143 else if (window
.ActiveXObject
) {
144 UFO
.pluginType
= "ax";
145 try { // avoid fp 6 crashes
146 var _a
= new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
150 var _a
= new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
152 _a
.AllowScriptAccess
= "always"; // throws if fp < 6.47
155 if (UFO
.fv
[0] == 6) return;
158 var _a
= new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
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)];
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;
180 hasFlashVersion: function(major
, release
) {
181 return (UFO
.fv
[0] > major
|| (UFO
.fv
[0] == major
&& UFO
.fv
[1] >= release
)) ? true : false;
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
);
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
]]);
201 var _o
= UFO
.opt
.concat(UFO
.optExc
);
203 for (var i
= 0; i
< _l
; i
++) {
204 if (typeof _fo
[_o
[i
]] != "undefined") UFO
.createObjParam(_obj
, _o
[i
], _fo
[_o
[i
]]);
206 _e
.appendChild(_obj
);
210 var _o
= UFO
.opt
.concat(UFO
.optAtt
).concat(UFO
.optExc
);
212 for (var i
= 0; i
< _l
; i
++) {
213 if (typeof _fo
[_o
[i
]] != "undefined") _emb
+= ' ' + _o
[i
] + '="' + _fo
[_o
[i
]] + '"';
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>';
218 else if (UFO
.pluginType
== "ax") {
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
]] + '"';
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
]] + '" />';
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>';
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");
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";
252 var _mmd
= document
.title
= document
.title
.slice(0, 47) + " - Flash Player Installation";
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");
261 expressInstallCallback: function() {
262 var _b
= document
.getElementsByTagName("body")[0];
263 var _c
= document
.getElementById("xi-con");
265 UFO
.createCSS("body", "height:auto; overflow:auto;");
266 UFO
.createCSS("html", "height:auto; overflow:auto;");
269 cleanupIELeaks: function() {
270 var _o
= document
.getElementsByTagName("object");
272 for (var i
= 0; i
< _l
; i
++) {
273 _o
[i
].style
.display
= "none";
275 for (var x
in _o
[i
]) {
277 if (typeof _o
[i
][x
] == "function") {
281 // something is wrong, probably infinite loop caused by embedded html file
291 if (typeof window
.attachEvent
!= "undefined" && UFO
.uaHas("ieWin")) {
292 window
.attachEvent("onunload", UFO
.cleanupIELeaks
);