]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/swfobject.js
Release 6.2.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / swfobject.js
1 /**
2  * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
3  *
4  * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
5  * http://www.opensource.org/licenses/mit-license.php
6  *
7  */
8 if(typeof deconcept == "undefined") var deconcept = new Object();
9 if(typeof deconcept.util == "undefined") deconcept.util = new Object();
10 if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
11 deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
12         if (!document.getElementById) { return; }
13         this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
14         this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
15         this.params = new Object();
16         this.variables = new Object();
17         this.attributes = new Array();
18         if(swf) { this.setAttribute('swf', swf); }
19         if(id) { this.setAttribute('id', id); }
20         if(w) { this.setAttribute('width', w); }
21         if(h) { this.setAttribute('height', h); }
22         if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
23         this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
24         if (!window.opera && document.all && this.installedVer.major > 7) {
25                 // only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
26                 deconcept.SWFObject.doPrepUnload = true;
27         }
28         if(c) { this.addParam('bgcolor', c); }
29         var q = quality ? quality : 'high';
30         this.addParam('quality', q);
31         this.setAttribute('useExpressInstall', false);
32         this.setAttribute('doExpressInstall', false);
33         var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
34         this.setAttribute('xiRedirectUrl', xir);
35         this.setAttribute('redirectUrl', '');
36         if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
37 }
38 deconcept.SWFObject.prototype = {
39         useExpressInstall: function(path) {
40                 this.xiSWFPath = !path ? "expressinstall.swf" : path;
41                 this.setAttribute('useExpressInstall', true);
42         },
43         setAttribute: function(name, value){
44                 this.attributes[name] = value;
45         },
46         getAttribute: function(name){
47                 return this.attributes[name];
48         },
49         addParam: function(name, value){
50                 this.params[name] = value;
51         },
52         getParams: function(){
53                 return this.params;
54         },
55         addVariable: function(name, value){
56                 this.variables[name] = value;
57         },
58         getVariable: function(name){
59                 return this.variables[name];
60         },
61         getVariables: function(){
62                 return this.variables;
63         },
64         getVariablePairs: function(){
65                 var variablePairs = new Array();
66                 var key;
67                 var variables = this.getVariables();
68                 for(key in variables){
69                         variablePairs[variablePairs.length] = key +"="+ variables[key];
70                 }
71                 return variablePairs;
72         },
73         getSWFHTML: function() {
74                 var swfNode = "";
75                 if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
76                         if (this.getAttribute("doExpressInstall")) {
77                                 this.addVariable("MMplayerType", "PlugIn");
78                                 this.setAttribute('swf', this.xiSWFPath);
79                         }
80                         swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
81                         swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
82                         var params = this.getParams();
83                          for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
84                         var pairs = this.getVariablePairs().join("&");
85                          if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
86                         swfNode += '/>';
87                 } else { // PC IE
88                         if (this.getAttribute("doExpressInstall")) {
89                                 this.addVariable("MMplayerType", "ActiveX");
90                                 this.setAttribute('swf', this.xiSWFPath);
91                         }
92                         swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
93                         swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
94                         var params = this.getParams();
95                         for(var key in params) {
96                          swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
97                         }
98                         var pairs = this.getVariablePairs().join("&");
99                         if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
100                         swfNode += "</object>";
101                 }
102                 return swfNode;
103         },
104         write: function(elementId){
105                 if(this.getAttribute('useExpressInstall')) {
106                         // check to see if we need to do an express install
107                         var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
108                         if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
109                                 this.setAttribute('doExpressInstall', true);
110                                 this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
111                                 document.title = document.title.slice(0, 47) + " - Flash Player Installation";
112                                 this.addVariable("MMdoctitle", document.title);
113                         }
114                 }
115                 if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
116                         var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
117                         n.innerHTML = this.getSWFHTML();
118                         return true;
119                 }else{
120                         if(this.getAttribute('redirectUrl') != "") {
121                                 document.location.replace(this.getAttribute('redirectUrl'));
122                         }
123                 }
124                 return false;
125         }
126 }
127
128 /* ---- detection functions ---- */
129 deconcept.SWFObjectUtil.getPlayerVersion = function(){
130         var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
131         if(navigator.plugins && navigator.mimeTypes.length){
132                 var x = navigator.plugins["Shockwave Flash"];
133                 if(x && x.description) {
134                         PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
135                 }
136         }else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
137                 var axo = 1;
138                 var counter = 3;
139                 while(axo) {
140                         try {
141                                 counter++;
142                                 axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
143 //                              document.write("player v: "+ counter);
144                                 PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
145                         } catch (e) {
146                                 axo = null;
147                         }
148                 }
149         } else { // Win IE (non mobile)
150                 // do minor version lookup in IE, but avoid fp6 crashing issues
151                 // see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
152                 try{
153                         var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
154                 }catch(e){
155                         try {
156                                 var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
157                                 PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
158                                 axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
159                         } catch(e) {
160                                 if (PlayerVersion.major == 6) {
161                                         return PlayerVersion;
162                                 }
163                         }
164                         try {
165                                 axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
166                         } catch(e) {}
167                 }
168                 if (axo != null) {
169                         PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
170                 }
171         }
172         return PlayerVersion;
173 }
174 deconcept.PlayerVersion = function(arrVersion){
175         this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
176         this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
177         this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
178 }
179 deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
180         if(this.major < fv.major) return false;
181         if(this.major > fv.major) return true;
182         if(this.minor < fv.minor) return false;
183         if(this.minor > fv.minor) return true;
184         if(this.rev < fv.rev) return false;
185         return true;
186 }
187 /* ---- get value of query string param ---- */
188 deconcept.util = {
189         getRequestParameter: function(param) {
190                 var q = document.location.search || document.location.hash;
191                 if (param == null) { return q; }
192                 if(q) {
193                         var pairs = q.substring(1).split("&");
194                         for (var i=0; i < pairs.length; i++) {
195                                 if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
196                                         return pairs[i].substring((pairs[i].indexOf("=")+1));
197                                 }
198                         }
199                 }
200                 return "";
201         }
202 }
203 /* fix for video streaming bug */
204 deconcept.SWFObjectUtil.cleanupSWFs = function() {
205         var objects = document.getElementsByTagName("OBJECT");
206         for (var i = objects.length - 1; i >= 0; i--) {
207                 objects[i].style.display = 'none';
208                 for (var x in objects[i]) {
209                         if (typeof objects[i][x] == 'function') {
210                                 objects[i][x] = function(){};
211                         }
212                 }
213         }
214 }
215 // fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
216 if (deconcept.SWFObject.doPrepUnload) {
217         if (!deconcept.unloadSet) {
218                 deconcept.SWFObjectUtil.prepUnload = function() {
219                         __flash_unloadHandler = function(){};
220                         __flash_savedUnloadHandler = function(){};
221                         window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
222                 }
223                 window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
224                 deconcept.unloadSet = true;
225         }
226 }
227 /* add document.getElementById if needed (mobile IE < 5) */
228 if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}
229
230 /* add some aliases for ease of use/backwards compatibility */
231 var getQueryParamValue = deconcept.util.getRequestParameter;
232 var FlashObject = deconcept.SWFObject; // for legacy support
233 var SWFObject = deconcept.SWFObject;
234
235 /* begin SUGARCRM customization */
236
237 function loadChartSWF(chartName, xmlFile, width, height, stylesheet, colorscheme, langFile){
238         
239         if(!document.getElementById(chartName + '_div')) {
240            return;      
241         }
242         
243         if (width == '100%'){
244                 width = document.getElementById(chartName + '_div').clientWidth;
245         }
246         else{
247                 width = width.replace(/px/,'');
248         }
249         
250         height = height.replace(/px/,'');       
251         var home = new SWFObject("include/SugarCharts/SugarFlash/swf/chart.swf", chartName, "100%", "100%", "7");
252         home.addParam("wmode","transparent");
253         home.addParam("menu","false");
254         home.addParam("quality","high");
255         home.addVariable( "inputFile" , xmlFile)
256         home.addVariable( "swfLocation" ,"include/SugarCharts/SugarFlash/swf/");
257         home.addVariable( "inputColorScheme" , colorscheme);
258         home.addVariable( "inputStyleSheet", stylesheet);
259         home.addVariable( "inputLanguage", langFile);
260         home.addVariable( "myWidth", width);
261         home.addVariable( "myHeight", height);
262         home.write(chartName + '_div');
263 }
264
265 /* end SUGARCRM customization */