2 * FusionCharts: Flash Player detection and Chart embedding.
3 * Version 1.2.3F ( 22 November 2008) - Specialized for FusionChartsFREE
4 * Checking Flash Version >=6 and added updateChartXML() for FREE Charts.
5 * Version: 1.2.3 (1st September, 2008) - Added Fix for % and & characters, scaled dimensions, fixes in to properly handling of double quotes and single quotes in setDataXML() function.
6 * Version: 1.2.2 (10th July, 2008) - Added Fix for % scaled dimensions, fixes in setDataXML() and setDataURL() functions
7 * Version: 1.2.1 (21st December, 2007) - Added setting up Transparent/opaque mode: setTransparent() function
8 * Version: 1.2 (1st November, 2007) - Added FORM fixes for IE
9 * Version: 1.1 (29th June, 2007) - Added Player detection, New conditional fixes for IE
11 * Morphed from SWFObject (http://blog.deconcept.com/swfobject/) under MIT License:
12 * http://www.opensource.org/licenses/mit-license.php
15 if(typeof infosoftglobal == "undefined") var infosoftglobal = new Object();
16 if(typeof infosoftglobal.FusionChartsUtil == "undefined") infosoftglobal.FusionChartsUtil = new Object();
17 infosoftglobal.FusionCharts = function(swf, id, w, h, debugMode, registerWithJS, c, scaleMode, lang, detectFlashVersion, autoInstallRedirect){
18 if (!document.getElementById) { return; }
20 //Flag to see whether data has been set initially
21 this.initialDataSet = false;
23 //Create container objects
24 this.params = new Object();
25 this.variables = new Object();
26 this.attributes = new Array();
28 //Set attributes for the SWF
29 if(swf) { this.setAttribute('swf', swf); }
30 if(id) { this.setAttribute('id', id); }
32 w=w.toString().replace(/\%$/,"%25");
33 if(w) { this.setAttribute('width', w); }
34 h=h.toString().replace(/\%$/,"%25");
35 if(h) { this.setAttribute('height', h); }
38 //Set background color
39 if(c) { this.addParam('bgcolor', c); }
42 this.addParam('quality', 'high');
44 //Add scripting access parameter
45 this.addParam('allowScriptAccess', 'always');
47 //Pass width and height to be appended as chartWidth and chartHeight
48 this.addVariable('chartWidth', w);
49 this.addVariable('chartHeight', h);
51 //Whether in debug mode
52 debugMode = debugMode ? debugMode : 0;
53 this.addVariable('debugMode', debugMode);
54 //Pass DOM ID to Chart
55 this.addVariable('DOMId', id);
56 //Whether to registed with JavaScript
57 registerWithJS = registerWithJS ? registerWithJS : 0;
58 this.addVariable('registerWithJS', registerWithJS);
61 scaleMode = scaleMode ? scaleMode : 'noScale';
62 this.addVariable('scaleMode', scaleMode);
64 //Application Message Language
65 lang = lang ? lang : 'EN';
66 this.addVariable('lang', lang);
68 //Whether to auto detect and re-direct to Flash Player installation
69 this.detectFlashVersion = detectFlashVersion?detectFlashVersion:1;
70 this.autoInstallRedirect = autoInstallRedirect?autoInstallRedirect:1;
72 //Ger Flash Player version
73 this.installedVer = infosoftglobal.FusionChartsUtil.getPlayerVersion();
75 if (!window.opera && document.all && this.installedVer.major > 7) {
76 // Only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
77 infosoftglobal.FusionCharts.doPrepUnload = true;
81 infosoftglobal.FusionCharts.prototype = {
82 setAttribute: function(name, value){
83 this.attributes[name] = value;
85 getAttribute: function(name){
86 return this.attributes[name];
88 addParam: function(name, value){
89 this.params[name] = value;
91 getParams: function(){
94 addVariable: function(name, value){
95 this.variables[name] = value;
97 getVariable: function(name){
98 return this.variables[name];
100 getVariables: function(){
101 return this.variables;
103 getVariablePairs: function(){
104 var variablePairs = new Array();
106 var variables = this.getVariables();
107 for(key in variables){
108 variablePairs.push(key +"="+ variables[key]);
110 return variablePairs;
112 getSWFHTML: function() {
114 if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
115 // netscape plugin architecture
116 swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" ';
117 swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
118 var params = this.getParams();
119 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
120 var pairs = this.getVariablePairs().join("&");
121 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
124 swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
125 swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
126 var params = this.getParams();
127 for(var key in params) {
128 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
130 var pairs = this.getVariablePairs().join("&");
131 if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
132 swfNode += "</object>";
136 setDataURL: function(strDataURL){
137 //This method sets the data URL for the chart.
138 //If being set initially
139 if (this.initialDataSet==false){
140 this.addVariable('dataURL',strDataURL);
142 this.initialDataSet = true;
144 //Else, we update the chart data using External Interface
145 //Get reference to chart object
146 var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this.getAttribute('id'));
148 if (!chartObj.setDataURL)
150 __flash__addCallback(chartObj, "setDataURL");
153 chartObj.setDataURL(strDataURL);
157 //fixes the double quoted attributes to single quotes
158 //Encodes all quotes inside attribute values
159 //Encodes % to %25 and & to %26;
160 encodeDataXML: function(strDataXML){
162 var regExpReservedCharacters=["\\$","\\+"];
163 var arrDQAtt=strDataXML.match(/=\s*\".*?\"/g);
165 for(var i=0;i<arrDQAtt.length;i++){
166 var repStr=arrDQAtt[i].replace(/^=\s*\"|\"$/g,"");
167 repStr=repStr.replace(/\'/g,"%26apos;");
168 var strTo=strDataXML.indexOf(arrDQAtt[i]);
169 var repStrr="='"+repStr+"'";
170 var strStart=strDataXML.substring(0,strTo);
171 var strEnd=strDataXML.substring(strTo+arrDQAtt[i].length);
172 var strDataXML=strStart+repStrr+strEnd;
176 strDataXML=strDataXML.replace(/\"/g,"%26quot;");
177 strDataXML=strDataXML.replace(/%(?![\da-f]{2}|[\da-f]{4})/ig,"%25");
178 strDataXML=strDataXML.replace(/\&/g,"%26");
183 setDataXML: function(strDataXML){
184 //If being set initially
185 if (this.initialDataSet==false){
186 //This method sets the data XML for the chart INITIALLY.
187 this.addVariable('dataXML',this.encodeDataXML(strDataXML));
189 this.initialDataSet = true;
191 //Else, we update the chart data using External Interface
192 //Get reference to chart object
193 var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this.getAttribute('id'));
194 chartObj.setDataXML(strDataXML);
197 setTransparent: function(isTransparent){
198 //Sets chart to transparent mode when isTransparent is true (default)
199 //When no parameter is passed, we assume transparent to be true.
200 if(typeof isTransparent=="undefined") {
205 this.addParam('WMode', 'transparent');
207 this.addParam('WMode', 'Opaque');
210 render: function(elementId){
211 //First check for installed version of Flash Player - we need a minimum of 6
212 if((this.detectFlashVersion==1) && (this.installedVer.major < 6)){
213 if (this.autoInstallRedirect==1){
214 //If we can auto redirect to install the player?
215 var installationConfirm = window.confirm("You need Adobe Flash Player 6 (or above) to view the charts. It is a free and lightweight installation from Adobe.com. Please click on Ok to install the same.");
216 if (installationConfirm){
217 window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
222 //Else, do not take an action. It means the developer has specified a message in the DIV (and probably a link).
223 //So, expect the developers to provide a course of way to their end users.
224 //window.alert("You need Adobe Flash Player 8 (or above) to view the charts. It is a free and lightweight installation from Adobe.com. ");
229 var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
230 n.innerHTML = this.getSWFHTML();
232 //Added <FORM> compatibility
233 //Check if it's added in Mozilla embed array or if already exits
234 if(!document.embeds[this.getAttribute('id')] && !window[this.getAttribute('id')])
235 window[this.getAttribute('id')]=document.getElementById(this.getAttribute('id'));
236 //or else document.forms[formName/formIndex][chartId]
242 /* ---- detection functions ---- */
243 infosoftglobal.FusionChartsUtil.getPlayerVersion = function(){
244 var PlayerVersion = new infosoftglobal.PlayerVersion([0,0,0]);
245 if(navigator.plugins && navigator.mimeTypes.length){
246 var x = navigator.plugins["Shockwave Flash"];
247 if(x && x.description) {
248 PlayerVersion = new infosoftglobal.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
250 }else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){
257 axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
258 PlayerVersion = new infosoftglobal.PlayerVersion([counter,0,0]);
264 // Win IE (non mobile)
265 // Do minor version lookup in IE, but avoid Flash Player 6 crashing issues
267 var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
270 var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
271 PlayerVersion = new infosoftglobal.PlayerVersion([6,0,21]);
272 axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
274 if (PlayerVersion.major == 6) {
275 return PlayerVersion;
279 axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
283 PlayerVersion = new infosoftglobal.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
286 return PlayerVersion;
288 infosoftglobal.PlayerVersion = function(arrVersion){
289 this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
290 this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
291 this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
293 // ------------ Fix for Out of Memory Bug in IE in FP9 ---------------//
294 /* Fix for video streaming bug */
295 infosoftglobal.FusionChartsUtil.cleanupSWFs = function() {
296 var objects = document.getElementsByTagName("OBJECT");
297 for (var i = objects.length - 1; i >= 0; i--) {
298 objects[i].style.display = 'none';
299 for (var x in objects[i]) {
300 if (typeof objects[i][x] == 'function') {
301 objects[i][x] = function(){};
307 if (infosoftglobal.FusionCharts.doPrepUnload) {
308 if (!infosoftglobal.unloadSet) {
309 infosoftglobal.FusionChartsUtil.prepUnload = function() {
310 __flash_unloadHandler = function(){};
311 __flash_savedUnloadHandler = function(){};
312 window.attachEvent("onunload", infosoftglobal.FusionChartsUtil.cleanupSWFs);
314 window.attachEvent("onbeforeunload", infosoftglobal.FusionChartsUtil.prepUnload);
315 infosoftglobal.unloadSet = true;
318 /* Add document.getElementById if needed (mobile IE < 5) */
319 if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}
320 /* Add Array.push if needed (ie5) */
321 if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
323 /* Function to return Flash Object from ID */
324 infosoftglobal.FusionChartsUtil.getChartObject = function(id)
327 if (navigator.appName.indexOf("Microsoft Internet")==-1) {
328 if (document.embeds && document.embeds[id])
329 chartRef = document.embeds[id];
331 chartRef = window.document[id];
334 chartRef = window[id];
337 chartRef = document.getElementById(id);
342 Function to update chart's data at client side (FOR FusionCharts vFREE and 2.x
344 infosoftglobal.FusionChartsUtil.updateChartXML = function(chartId, strXML){
345 //Get reference to chart object
346 var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(chartId);
347 //Set dataURL to null
348 chartObj.SetVariable("_root.dataURL","");
350 chartObj.SetVariable("_root.isNewData","1");
351 //Set the actual data
352 chartObj.SetVariable("_root.newData",strXML);
353 //Go to the required frame
354 chartObj.TGotoLabel("/", "JavaScriptHandler");
358 /* Aliases for easy usage */
359 var getChartFromId = infosoftglobal.FusionChartsUtil.getChartObject;
360 var updateChartXML = infosoftglobal.FusionChartsUtil.updateChartXML;
361 var FusionCharts = infosoftglobal.FusionCharts;