2 * FusionCharts: Flash Player detection and Chart embedding. Version 1.2.3F ( 22
3 * November 2008) - Specialized for FusionChartsFREE Checking Flash Version >=6
4 * and added updateChartXML() for FREE Charts. Version: 1.2.3 (1st September,
5 * 2008) - Added Fix for % and & characters, scaled dimensions, fixes in to
6 * properly handling of double quotes and single quotes in setDataXML()
7 * function. Version: 1.2.2 (10th July, 2008) - Added Fix for % scaled
8 * dimensions, fixes in setDataXML() and setDataURL() functions Version: 1.2.1
9 * (21st December, 2007) - Added setting up Transparent/opaque mode:
10 * setTransparent() function Version: 1.2 (1st November, 2007) - Added FORM
11 * fixes for IE Version: 1.1 (29th June, 2007) - Added Player detection, New
12 * conditional fixes for IE
14 * Morphed from SWFObject (http://blog.deconcept.com/swfobject/) under MIT
15 * License: http://www.opensource.org/licenses/mit-license.php
18 if (typeof infosoftglobal == "undefined")
19 var infosoftglobal = new Object();
20 if (typeof infosoftglobal.FusionChartsUtil == "undefined")
21 infosoftglobal.FusionChartsUtil = new Object();
22 infosoftglobal.FusionCharts = function(swf, id, w, h, debugMode,
23 registerWithJS, c, scaleMode, lang, detectFlashVersion,
24 autoInstallRedirect) {
25 if (!document.getElementById) {
29 // Flag to see whether data has been set initially
30 this.initialDataSet = false;
32 // Create container objects
33 this.params = new Object();
34 this.variables = new Object();
35 this.attributes = new Array();
37 // Set attributes for the SWF
39 this.setAttribute('swf', swf);
42 this.setAttribute('id', id);
45 w = w.toString().replace(/\%$/, "%25");
47 this.setAttribute('width', w);
49 h = h.toString().replace(/\%$/, "%25");
51 this.setAttribute('height', h);
54 // Set background color
56 this.addParam('bgcolor', c);
60 this.addParam('quality', 'high');
62 // Add scripting access parameter
63 this.addParam('allowScriptAccess', 'always');
65 // Pass width and height to be appended as chartWidth and chartHeight
66 this.addVariable('chartWidth', w);
67 this.addVariable('chartHeight', h);
69 // Whether in debug mode
70 debugMode = debugMode ? debugMode : 0;
71 this.addVariable('debugMode', debugMode);
72 // Pass DOM ID to Chart
73 this.addVariable('DOMId', id);
74 // Whether to registed with JavaScript
75 registerWithJS = registerWithJS ? registerWithJS : 0;
76 this.addVariable('registerWithJS', registerWithJS);
78 // Scale Mode of chart
79 scaleMode = scaleMode ? scaleMode : 'noScale';
80 this.addVariable('scaleMode', scaleMode);
82 // Application Message Language
83 lang = lang ? lang : 'EN';
84 this.addVariable('lang', lang);
86 // Whether to auto detect and re-direct to Flash Player installation
87 this.detectFlashVersion = detectFlashVersion ? detectFlashVersion : 1;
88 this.autoInstallRedirect = autoInstallRedirect ? autoInstallRedirect : 1;
90 // Ger Flash Player version
91 this.installedVer = infosoftglobal.FusionChartsUtil.getPlayerVersion();
93 if (!window.opera && document.all && this.installedVer.major > 7) {
94 // Only add the onunload cleanup if the Flash Player version supports
95 // External Interface and we are in IE
96 infosoftglobal.FusionCharts.doPrepUnload = true;
100 infosoftglobal.FusionCharts.prototype = {
101 setAttribute : function(name, value) {
102 this.attributes[name] = value;
104 getAttribute : function(name) {
105 return this.attributes[name];
107 addParam : function(name, value) {
108 this.params[name] = value;
110 getParams : function() {
113 addVariable : function(name, value) {
114 this.variables[name] = value;
116 getVariable : function(name) {
117 return this.variables[name];
119 getVariables : function() {
120 return this.variables;
122 getVariablePairs : function() {
123 var variablePairs = new Array();
125 var variables = this.getVariables();
126 for (key in variables) {
127 variablePairs.push(key + "=" + variables[key]);
129 return variablePairs;
131 getSWFHTML : function() {
133 if (navigator.plugins && navigator.mimeTypes
134 && navigator.mimeTypes.length) {
135 // netscape plugin architecture
136 swfNode = '<embed type="application/x-shockwave-flash" src="'
137 + this.getAttribute('swf') + '" width="'
138 + this.getAttribute('width') + '" height="'
139 + this.getAttribute('height') + '" ';
140 swfNode += ' id="' + this.getAttribute('id') + '" name="'
141 + this.getAttribute('id') + '" ';
142 var params = this.getParams();
143 for ( var key in params) {
144 swfNode += [ key ] + '="' + params[key] + '" ';
146 var pairs = this.getVariablePairs().join("&");
147 if (pairs.length > 0) {
148 swfNode += 'flashvars="' + pairs + '"';
152 swfNode = '<object id="'
153 + this.getAttribute('id')
154 + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'
155 + this.getAttribute('width') + '" height="'
156 + this.getAttribute('height') + '">';
157 swfNode += '<param name="movie" value="' + this.getAttribute('swf')
159 var params = this.getParams();
160 for ( var key in params) {
161 swfNode += '<param name="' + key + '" value="' + params[key]
164 var pairs = this.getVariablePairs().join("&");
165 if (pairs.length > 0) {
166 swfNode += '<param name="flashvars" value="' + pairs + '" />';
168 swfNode += "</object>";
172 setDataURL : function(strDataURL) {
173 // This method sets the data URL for the chart.
174 // If being set initially
175 if (this.initialDataSet == false) {
176 this.addVariable('dataURL', strDataURL);
178 this.initialDataSet = true;
180 // Else, we update the chart data using External Interface
181 // Get reference to chart object
182 var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this
183 .getAttribute('id'));
185 if (!chartObj.setDataURL) {
186 __flash__addCallback(chartObj, "setDataURL");
189 chartObj.setDataURL(strDataURL);
193 // fixes the double quoted attributes to single quotes
194 // Encodes all quotes inside attribute values
195 // Encodes % to %25 and & to %26;
196 encodeDataXML : function(strDataXML) {
198 var regExpReservedCharacters = [ "\\$", "\\+" ];
199 var arrDQAtt = strDataXML.match(/=\s*\".*?\"/g);
201 for (var i = 0; i < arrDQAtt.length; i++) {
202 var repStr = arrDQAtt[i].replace(/^=\s*\"|\"$/g, "");
203 repStr = repStr.replace(/\'/g, "%26apos;");
204 var strTo = strDataXML.indexOf(arrDQAtt[i]);
205 var repStrr = "='" + repStr + "'";
206 var strStart = strDataXML.substring(0, strTo);
207 var strEnd = strDataXML.substring(strTo + arrDQAtt[i].length);
208 var strDataXML = strStart + repStrr + strEnd;
212 strDataXML = strDataXML.replace(/\"/g, "%26quot;");
213 strDataXML = strDataXML.replace(/%(?![\da-f]{2}|[\da-f]{4})/ig, "%25");
214 strDataXML = strDataXML.replace(/\&/g, "%26");
219 setDataXML : function(strDataXML) {
220 // If being set initially
221 if (this.initialDataSet == false) {
222 // This method sets the data XML for the chart INITIALLY.
223 this.addVariable('dataXML', this.encodeDataXML(strDataXML));
225 this.initialDataSet = true;
227 // Else, we update the chart data using External Interface
228 // Get reference to chart object
229 var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this
230 .getAttribute('id'));
231 chartObj.setDataXML(strDataXML);
234 setTransparent : function(isTransparent) {
235 // Sets chart to transparent mode when isTransparent is true (default)
236 // When no parameter is passed, we assume transparent to be true.
237 if (typeof isTransparent == "undefined") {
238 isTransparent = true;
242 this.addParam('WMode', 'transparent');
244 this.addParam('WMode', 'Opaque');
247 render : function(elementId) {
248 // First check for installed version of Flash Player - we need a minimum
250 if ((this.detectFlashVersion == 1) && (this.installedVer.major < 6)) {
251 if (this.autoInstallRedirect == 1) {
252 // If we can auto redirect to install the player?
253 var installationConfirm = window
254 .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.");
255 if (installationConfirm) {
256 window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
261 // Else, do not take an action. It means the developer has
262 // specified a message in the DIV (and probably a link).
263 // So, expect the developers to provide a course of way to their
265 // window.alert("You need Adobe Flash Player 8 (or above) to
266 // view the charts. It is a free and lightweight installation
267 // from Adobe.com. ");
272 var n = (typeof elementId == 'string') ? document
273 .getElementById(elementId) : elementId;
274 n.innerHTML = this.getSWFHTML();
276 // Added <FORM> compatibility
277 // Check if it's added in Mozilla embed array or if already exits
278 if (!document.embeds[this.getAttribute('id')]
279 && !window[this.getAttribute('id')])
280 window[this.getAttribute('id')] = document.getElementById(this
281 .getAttribute('id'));
282 // or else document.forms[formName/formIndex][chartId]
288 /* ---- detection functions ---- */
289 infosoftglobal.FusionChartsUtil.getPlayerVersion = function() {
290 var PlayerVersion = new infosoftglobal.PlayerVersion([ 0, 0, 0 ]);
291 if (navigator.plugins && navigator.mimeTypes.length) {
292 var x = navigator.plugins["Shockwave Flash"];
293 if (x && x.description) {
294 PlayerVersion = new infosoftglobal.PlayerVersion(x.description
295 .replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/,
298 } else if (navigator.userAgent
299 && navigator.userAgent.indexOf("Windows CE") >= 0) {
306 axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."
308 PlayerVersion = new infosoftglobal.PlayerVersion([ counter, 0,
315 // Win IE (non mobile)
316 // Do minor version lookup in IE, but avoid Flash Player 6 crashing
319 var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
322 var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
323 PlayerVersion = new infosoftglobal.PlayerVersion([ 6, 0, 21 ]);
324 axo.AllowScriptAccess = "always"; // error if player version <
325 // 6.0.47 (thanks to Michael
326 // Williams @ Adobe for this
329 if (PlayerVersion.major == 6) {
330 return PlayerVersion;
334 axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
339 PlayerVersion = new infosoftglobal.PlayerVersion(axo.GetVariable(
340 "$version").split(" ")[1].split(","));
343 return PlayerVersion;
345 infosoftglobal.PlayerVersion = function(arrVersion) {
346 this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
347 this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
348 this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
350 // ------------ Fix for Out of Memory Bug in IE in FP9 ---------------//
351 /* Fix for video streaming bug */
352 infosoftglobal.FusionChartsUtil.cleanupSWFs = function() {
353 var objects = document.getElementsByTagName("OBJECT");
354 for (var i = objects.length - 1; i >= 0; i--) {
355 objects[i].style.display = 'none';
356 for ( var x in objects[i]) {
357 if (typeof objects[i][x] == 'function') {
358 objects[i][x] = function() {
365 if (infosoftglobal.FusionCharts.doPrepUnload) {
366 if (!infosoftglobal.unloadSet) {
367 infosoftglobal.FusionChartsUtil.prepUnload = function() {
368 __flash_unloadHandler = function() {
370 __flash_savedUnloadHandler = function() {
372 window.attachEvent("onunload",
373 infosoftglobal.FusionChartsUtil.cleanupSWFs);
375 window.attachEvent("onbeforeunload",
376 infosoftglobal.FusionChartsUtil.prepUnload);
377 infosoftglobal.unloadSet = true;
380 /* Add document.getElementById if needed (mobile IE < 5) */
381 if (!document.getElementById && document.all) {
382 document.getElementById = function(id) {
383 return document.all[id];
386 /* Add Array.push if needed (ie5) */
387 if (Array.prototype.push == null) {
388 Array.prototype.push = function(item) {
389 this[this.length] = item;
394 /* Function to return Flash Object from ID */
395 infosoftglobal.FusionChartsUtil.getChartObject = function(id) {
397 if (navigator.appName.indexOf("Microsoft Internet") == -1) {
398 if (document.embeds && document.embeds[id])
399 chartRef = document.embeds[id];
401 chartRef = window.document[id];
403 chartRef = window[id];
406 chartRef = document.getElementById(id);
411 * Function to update chart's data at client side (FOR FusionCharts vFREE and
414 infosoftglobal.FusionChartsUtil.updateChartXML = function(chartId, strXML) {
415 // Get reference to chart object
416 var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(chartId);
417 // Set dataURL to null
418 chartObj.SetVariable("_root.dataURL", "");
420 chartObj.SetVariable("_root.isNewData", "1");
421 // Set the actual data
422 chartObj.SetVariable("_root.newData", strXML);
423 // Go to the required frame
424 chartObj.TGotoLabel("/", "JavaScriptHandler");
427 /* Aliases for easy usage */
428 var getChartFromId = infosoftglobal.FusionChartsUtil.getChartObject;
429 var updateChartXML = infosoftglobal.FusionChartsUtil.updateChartXML;
430 var FusionCharts = infosoftglobal.FusionCharts;