0
|
1 |
/* |
|
2 |
* FlashObject embed |
|
3 |
* by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/) |
|
4 |
* |
|
5 |
* v1.1.1 - 05-17-2005 |
|
6 |
* |
|
7 |
* writes the embed code for a flash movie, includes plugin detection |
|
8 |
* |
|
9 |
* Usage: |
|
10 |
* |
|
11 |
* myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor"); |
|
12 |
* myFlash.write("objId"); |
|
13 |
* |
|
14 |
* for best practices, see: |
|
15 |
* http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
var FlashObject = function(swf, id, w, h, ver, c) { |
|
20 |
this.swf = swf; |
|
21 |
this.id = id; |
|
22 |
this.width = w; |
|
23 |
this.height = h; |
|
24 |
this.version = ver; |
|
25 |
this.align = "middle"; |
|
26 |
|
|
27 |
this.params = new Object(); |
|
28 |
this.variables = new Object(); |
|
29 |
|
|
30 |
this.redirect = ""; |
|
31 |
this.sq = document.location.search.split("?")[1] || ""; |
|
32 |
this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>"; |
|
33 |
|
|
34 |
if (c) this.color = this.addParam('bgcolor', c); |
|
35 |
this.addParam('quality', 'high'); // default to high |
|
36 |
this.doDetect = getQueryParamValue('detectflash'); |
|
37 |
} |
|
38 |
|
|
39 |
var FOP = FlashObject.prototype; |
|
40 |
|
|
41 |
FOP.addParam = function(name, value) { this.params[name] = value; } |
|
42 |
|
|
43 |
FOP.getParams = function() { return this.params; } |
|
44 |
|
|
45 |
FOP.getParam = function(name) { return this.params[name]; } |
|
46 |
|
|
47 |
FOP.addVariable = function(name, value) { this.variables[name] = value; } |
|
48 |
|
|
49 |
FOP.getVariable = function(name) { return this.variables[name]; } |
|
50 |
|
|
51 |
FOP.getVariables = function() { return this.variables; } |
|
52 |
|
|
53 |
FOP.getParamTags = function() { |
|
54 |
var paramTags = ""; |
|
55 |
for (var param in this.getParams()) { |
|
56 |
paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />'; |
|
57 |
} |
|
58 |
return (paramTags == "") ? false:paramTags; |
|
59 |
} |
|
60 |
|
|
61 |
FOP.getHTML = function() { |
|
62 |
var flashHTML = ""; |
|
63 |
if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture |
|
64 |
flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"'; |
|
65 |
for (var param in this.getParams()) { |
|
66 |
flashHTML += ' ' + param + '="' + this.getParam(param) + '"'; |
|
67 |
} |
|
68 |
if (this.getVariablePairs()) { |
|
69 |
flashHTML += ' flashVars="' + this.getVariablePairs() + '"'; |
|
70 |
} |
|
71 |
flashHTML += '></embed>'; |
|
72 |
} else { // PC IE |
|
73 |
flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" name="' + this.id + '" align="' + this.align + '">'; |
|
74 |
flashHTML += '<param name="movie" value="' + this.swf + '" />'; |
|
75 |
if (this.getParamTags()) { |
|
76 |
flashHTML += this.getParamTags(); |
|
77 |
} |
|
78 |
if (this.getVariablePairs() != null) { |
|
79 |
flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />'; |
|
80 |
} |
|
81 |
flashHTML += '</object>'; |
|
82 |
} |
|
83 |
return flashHTML; |
|
84 |
} |
|
85 |
|
|
86 |
FOP.getVariablePairs = function() { |
|
87 |
var variablePairs = new Array(); |
|
88 |
for (var name in this.getVariables()) { |
|
89 |
variablePairs.push(name + "=" + escape(this.getVariable(name))); |
|
90 |
} |
|
91 |
return (variablePairs.length > 0) ? variablePairs.join("&"):false; |
|
92 |
} |
|
93 |
|
|
94 |
FOP.write = function(elementId) { |
|
95 |
if(detectFlash(this.version) || this.doDetect=='false') { |
|
96 |
if (elementId) { |
|
97 |
document.getElementById(elementId).innerHTML = this.getHTML(); |
|
98 |
} else { |
|
99 |
document.write(this.getHTML()); |
|
100 |
} |
|
101 |
} else { |
|
102 |
if (this.redirect != "") { |
|
103 |
document.location.replace(this.redirect); |
|
104 |
} else if (this.altTxt) { |
|
105 |
if (elementId) { |
|
106 |
document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt; |
|
107 |
} else { |
|
108 |
document.write(this.altTxt +""+ this.bypassTxt); |
|
109 |
} |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
/* ---- detection functions ---- */ |
|
115 |
function getFlashVersion() { |
|
116 |
var flashversion = 0; |
|
117 |
if (navigator.plugins && navigator.mimeTypes.length) { |
|
118 |
var x = navigator.plugins["Shockwave Flash"]; |
|
119 |
if(x && x.description) { |
|
120 |
var y = x.description; |
|
121 |
flashversion = y.charAt(y.indexOf('.')-1); |
|
122 |
var aux= y.charAt(y.indexOf('.')-2); |
|
123 |
if("0123456789".indexOf(aux)!=-1) flashversion=aux+flashversion; |
|
124 |
} |
|
125 |
} else { |
|
126 |
result = false; |
|
127 |
for(var i = 15; i >= 3 && result != true; i--){ |
|
128 |
execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript'); |
|
129 |
flashversion = i; |
|
130 |
} |
|
131 |
} |
|
132 |
return flashversion; |
|
133 |
} |
|
134 |
|
|
135 |
function detectFlash(ver) { return (getFlashVersion() >= ver) ? true:false; } |
|
136 |
|
|
137 |
// get value of query string param |
|
138 |
function getQueryParamValue(param) { |
|
139 |
var q = document.location.search || document.location.href.split("#")[1]; |
|
140 |
if (q) { |
|
141 |
var detectIndex = q.indexOf(param +"="); |
|
142 |
var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length; |
|
143 |
if (q.length > 1 && detectIndex > -1) { |
|
144 |
return q.substring(q.indexOf("=", detectIndex)+1, endIndex); |
|
145 |
} else { |
|
146 |
return ""; |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
/* add Array.push if needed */ |
|
152 |
if(Array.prototype.push == null){ |
|
153 |
Array.prototype.push = function(item) { this[this.length] = item; return this.length; } |
|
154 |
} |