Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1921 lines
65 KiB

  1. /*!
  2. * Ext JS Library 3.2.0
  3. * Copyright(c) 2006-2010 Ext JS, Inc.
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /*! SWFObject v2.2 <http://code.google.com/p/swfobject/>
  8. is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
  9. */
  10. var swfobject = function() {
  11. var UNDEF = "undefined",
  12. OBJECT = "object",
  13. SHOCKWAVE_FLASH = "Shockwave Flash",
  14. SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
  15. FLASH_MIME_TYPE = "application/x-shockwave-flash",
  16. EXPRESS_INSTALL_ID = "SWFObjectExprInst",
  17. ON_READY_STATE_CHANGE = "onreadystatechange",
  18. win = window,
  19. doc = document,
  20. nav = navigator,
  21. plugin = false,
  22. domLoadFnArr = [main],
  23. regObjArr = [],
  24. objIdArr = [],
  25. listenersArr = [],
  26. storedAltContent,
  27. storedAltContentId,
  28. storedCallbackFn,
  29. storedCallbackObj,
  30. isDomLoaded = false,
  31. isExpressInstallActive = false,
  32. dynamicStylesheet,
  33. dynamicStylesheetMedia,
  34. autoHideShow = true,
  35. /* Centralized function for browser feature detection
  36. - User agent string detection is only used when no good alternative is possible
  37. - Is executed directly for optimal performance
  38. */
  39. ua = function() {
  40. var w3cdom = typeof doc.getElementById != UNDEF && typeof doc.getElementsByTagName != UNDEF && typeof doc.createElement != UNDEF,
  41. u = nav.userAgent.toLowerCase(),
  42. p = nav.platform.toLowerCase(),
  43. windows = p ? /win/.test(p) : /win/.test(u),
  44. mac = p ? /mac/.test(p) : /mac/.test(u),
  45. webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, // returns either the webkit version or false if not webkit
  46. ie = !+"\v1", // feature detection based on Andrea Giammarchi's solution: http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html
  47. playerVersion = [0,0,0],
  48. d = null;
  49. if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
  50. d = nav.plugins[SHOCKWAVE_FLASH].description;
  51. if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) { // navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
  52. plugin = true;
  53. ie = false; // cascaded feature detection for Internet Explorer
  54. d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
  55. playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
  56. playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
  57. playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
  58. }
  59. }
  60. else if (typeof win.ActiveXObject != UNDEF) {
  61. try {
  62. var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
  63. if (a) { // a will return null when ActiveX is disabled
  64. d = a.GetVariable("$version");
  65. if (d) {
  66. ie = true; // cascaded feature detection for Internet Explorer
  67. d = d.split(" ")[1].split(",");
  68. playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
  69. }
  70. }
  71. }
  72. catch(e) {}
  73. }
  74. return { w3:w3cdom, pv:playerVersion, wk:webkit, ie:ie, win:windows, mac:mac };
  75. }(),
  76. /* Cross-browser onDomLoad
  77. - Will fire an event as soon as the DOM of a web page is loaded
  78. - Internet Explorer workaround based on Diego Perini's solution: http://javascript.nwbox.com/IEContentLoaded/
  79. - Regular onload serves as fallback
  80. */
  81. onDomLoad = function() {
  82. if (!ua.w3) { return; }
  83. if ((typeof doc.readyState != UNDEF && doc.readyState == "complete") || (typeof doc.readyState == UNDEF && (doc.getElementsByTagName("body")[0] || doc.body))) { // function is fired after onload, e.g. when script is inserted dynamically
  84. callDomLoadFunctions();
  85. }
  86. if (!isDomLoaded) {
  87. if (typeof doc.addEventListener != UNDEF) {
  88. doc.addEventListener("DOMContentLoaded", callDomLoadFunctions, false);
  89. }
  90. if (ua.ie && ua.win) {
  91. doc.attachEvent(ON_READY_STATE_CHANGE, function() {
  92. if (doc.readyState == "complete") {
  93. doc.detachEvent(ON_READY_STATE_CHANGE, arguments.callee);
  94. callDomLoadFunctions();
  95. }
  96. });
  97. if (win == top) { // if not inside an iframe
  98. (function(){
  99. if (isDomLoaded) { return; }
  100. try {
  101. doc.documentElement.doScroll("left");
  102. }
  103. catch(e) {
  104. setTimeout(arguments.callee, 0);
  105. return;
  106. }
  107. callDomLoadFunctions();
  108. })();
  109. }
  110. }
  111. if (ua.wk) {
  112. (function(){
  113. if (isDomLoaded) { return; }
  114. if (!/loaded|complete/.test(doc.readyState)) {
  115. setTimeout(arguments.callee, 0);
  116. return;
  117. }
  118. callDomLoadFunctions();
  119. })();
  120. }
  121. addLoadEvent(callDomLoadFunctions);
  122. }
  123. }();
  124. function callDomLoadFunctions() {
  125. if (isDomLoaded) { return; }
  126. try { // test if we can really add/remove elements to/from the DOM; we don't want to fire it too early
  127. var t = doc.getElementsByTagName("body")[0].appendChild(createElement("span"));
  128. t.parentNode.removeChild(t);
  129. }
  130. catch (e) { return; }
  131. isDomLoaded = true;
  132. var dl = domLoadFnArr.length;
  133. for (var i = 0; i < dl; i++) {
  134. domLoadFnArr[i]();
  135. }
  136. }
  137. function addDomLoadEvent(fn) {
  138. if (isDomLoaded) {
  139. fn();
  140. }
  141. else {
  142. domLoadFnArr[domLoadFnArr.length] = fn; // Array.push() is only available in IE5.5+
  143. }
  144. }
  145. /* Cross-browser onload
  146. - Based on James Edwards' solution: http://brothercake.com/site/resources/scripts/onload/
  147. - Will fire an event as soon as a web page including all of its assets are loaded
  148. */
  149. function addLoadEvent(fn) {
  150. if (typeof win.addEventListener != UNDEF) {
  151. win.addEventListener("load", fn, false);
  152. }
  153. else if (typeof doc.addEventListener != UNDEF) {
  154. doc.addEventListener("load", fn, false);
  155. }
  156. else if (typeof win.attachEvent != UNDEF) {
  157. addListener(win, "onload", fn);
  158. }
  159. else if (typeof win.onload == "function") {
  160. var fnOld = win.onload;
  161. win.onload = function() {
  162. fnOld();
  163. fn();
  164. };
  165. }
  166. else {
  167. win.onload = fn;
  168. }
  169. }
  170. /* Main function
  171. - Will preferably execute onDomLoad, otherwise onload (as a fallback)
  172. */
  173. function main() {
  174. if (plugin) {
  175. testPlayerVersion();
  176. }
  177. else {
  178. matchVersions();
  179. }
  180. }
  181. /* Detect the Flash Player version for non-Internet Explorer browsers
  182. - Detecting the plug-in version via the object element is more precise than using the plugins collection item's description:
  183. a. Both release and build numbers can be detected
  184. b. Avoid wrong descriptions by corrupt installers provided by Adobe
  185. c. Avoid wrong descriptions by multiple Flash Player entries in the plugin Array, caused by incorrect browser imports
  186. - Disadvantage of this method is that it depends on the availability of the DOM, while the plugins collection is immediately available
  187. */
  188. function testPlayerVersion() {
  189. var b = doc.getElementsByTagName("body")[0];
  190. var o = createElement(OBJECT);
  191. o.setAttribute("type", FLASH_MIME_TYPE);
  192. var t = b.appendChild(o);
  193. if (t) {
  194. var counter = 0;
  195. (function(){
  196. if (typeof t.GetVariable != UNDEF) {
  197. var d = t.GetVariable("$version");
  198. if (d) {
  199. d = d.split(" ")[1].split(",");
  200. ua.pv = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
  201. }
  202. }
  203. else if (counter < 10) {
  204. counter++;
  205. setTimeout(arguments.callee, 10);
  206. return;
  207. }
  208. b.removeChild(o);
  209. t = null;
  210. matchVersions();
  211. })();
  212. }
  213. else {
  214. matchVersions();
  215. }
  216. }
  217. /* Perform Flash Player and SWF version matching; static publishing only
  218. */
  219. function matchVersions() {
  220. var rl = regObjArr.length;
  221. if (rl > 0) {
  222. for (var i = 0; i < rl; i++) { // for each registered object element
  223. var id = regObjArr[i].id;
  224. var cb = regObjArr[i].callbackFn;
  225. var cbObj = {success:false, id:id};
  226. if (ua.pv[0] > 0) {
  227. var obj = getElementById(id);
  228. if (obj) {
  229. if (hasPlayerVersion(regObjArr[i].swfVersion) && !(ua.wk && ua.wk < 312)) { // Flash Player version >= published SWF version: Houston, we have a match!
  230. setVisibility(id, true);
  231. if (cb) {
  232. cbObj.success = true;
  233. cbObj.ref = getObjectById(id);
  234. cb(cbObj);
  235. }
  236. }
  237. else if (regObjArr[i].expressInstall && canExpressInstall()) { // show the Adobe Express Install dialog if set by the web page author and if supported
  238. var att = {};
  239. att.data = regObjArr[i].expressInstall;
  240. att.width = obj.getAttribute("width") || "0";
  241. att.height = obj.getAttribute("height") || "0";
  242. if (obj.getAttribute("class")) { att.styleclass = obj.getAttribute("class"); }
  243. if (obj.getAttribute("align")) { att.align = obj.getAttribute("align"); }
  244. // parse HTML object param element's name-value pairs
  245. var par = {};
  246. var p = obj.getElementsByTagName("param");
  247. var pl = p.length;
  248. for (var j = 0; j < pl; j++) {
  249. if (p[j].getAttribute("name").toLowerCase() != "movie") {
  250. par[p[j].getAttribute("name")] = p[j].getAttribute("value");
  251. }
  252. }
  253. showExpressInstall(att, par, id, cb);
  254. }
  255. else { // Flash Player and SWF version mismatch or an older Webkit engine that ignores the HTML object element's nested param elements: display alternative content instead of SWF
  256. displayAltContent(obj);
  257. if (cb) { cb(cbObj); }
  258. }
  259. }
  260. }
  261. else { // if no Flash Player is installed or the fp version cannot be detected we let the HTML object element do its job (either show a SWF or alternative content)
  262. setVisibility(id, true);
  263. if (cb) {
  264. var o = getObjectById(id); // test whether there is an HTML object element or not
  265. if (o && typeof o.SetVariable != UNDEF) {
  266. cbObj.success = true;
  267. cbObj.ref = o;
  268. }
  269. cb(cbObj);
  270. }
  271. }
  272. }
  273. }
  274. }
  275. function getObjectById(objectIdStr) {
  276. var r = null;
  277. var o = getElementById(objectIdStr);
  278. if (o && o.nodeName == "OBJECT") {
  279. if (typeof o.SetVariable != UNDEF) {
  280. r = o;
  281. }
  282. else {
  283. var n = o.getElementsByTagName(OBJECT)[0];
  284. if (n) {
  285. r = n;
  286. }
  287. }
  288. }
  289. return r;
  290. }
  291. /* Requirements for Adobe Express Install
  292. - only one instance can be active at a time
  293. - fp 6.0.65 or higher
  294. - Win/Mac OS only
  295. - no Webkit engines older than version 312
  296. */
  297. function canExpressInstall() {
  298. return !isExpressInstallActive && hasPlayerVersion("6.0.65") && (ua.win || ua.mac) && !(ua.wk && ua.wk < 312);
  299. }
  300. /* Show the Adobe Express Install dialog
  301. - Reference: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75
  302. */
  303. function showExpressInstall(att, par, replaceElemIdStr, callbackFn) {
  304. isExpressInstallActive = true;
  305. storedCallbackFn = callbackFn || null;
  306. storedCallbackObj = {success:false, id:replaceElemIdStr};
  307. var obj = getElementById(replaceElemIdStr);
  308. if (obj) {
  309. if (obj.nodeName == "OBJECT") { // static publishing
  310. storedAltContent = abstractAltContent(obj);
  311. storedAltContentId = null;
  312. }
  313. else { // dynamic publishing
  314. storedAltContent = obj;
  315. storedAltContentId = replaceElemIdStr;
  316. }
  317. att.id = EXPRESS_INSTALL_ID;
  318. if (typeof att.width == UNDEF || (!/%$/.test(att.width) && parseInt(att.width, 10) < 310)) { att.width = "310"; }
  319. if (typeof att.height == UNDEF || (!/%$/.test(att.height) && parseInt(att.height, 10) < 137)) { att.height = "137"; }
  320. doc.title = doc.title.slice(0, 47) + " - Flash Player Installation";
  321. var pt = ua.ie && ua.win ? "ActiveX" : "PlugIn",
  322. fv = "MMredirectURL=" + win.location.toString().replace(/&/g,"%26") + "&MMplayerType=" + pt + "&MMdoctitle=" + doc.title;
  323. if (typeof par.flashvars != UNDEF) {
  324. par.flashvars += "&" + fv;
  325. }
  326. else {
  327. par.flashvars = fv;
  328. }
  329. // IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
  330. // because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
  331. if (ua.ie && ua.win && obj.readyState != 4) {
  332. var newObj = createElement("div");
  333. replaceElemIdStr += "SWFObjectNew";
  334. newObj.setAttribute("id", replaceElemIdStr);
  335. obj.parentNode.insertBefore(newObj, obj); // insert placeholder div that will be replaced by the object element that loads expressinstall.swf
  336. obj.style.display = "none";
  337. (function(){
  338. if (obj.readyState == 4) {
  339. obj.parentNode.removeChild(obj);
  340. }
  341. else {
  342. setTimeout(arguments.callee, 10);
  343. }
  344. })();
  345. }
  346. createSWF(att, par, replaceElemIdStr);
  347. }
  348. }
  349. /* Functions to abstract and display alternative content
  350. */
  351. function displayAltContent(obj) {
  352. if (ua.ie && ua.win && obj.readyState != 4) {
  353. // IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
  354. // because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
  355. var el = createElement("div");
  356. obj.parentNode.insertBefore(el, obj); // insert placeholder div that will be replaced by the alternative content
  357. el.parentNode.replaceChild(abstractAltContent(obj), el);
  358. obj.style.display = "none";
  359. (function(){
  360. if (obj.readyState == 4) {
  361. obj.parentNode.removeChild(obj);
  362. }
  363. else {
  364. setTimeout(arguments.callee, 10);
  365. }
  366. })();
  367. }
  368. else {
  369. obj.parentNode.replaceChild(abstractAltContent(obj), obj);
  370. }
  371. }
  372. function abstractAltContent(obj) {
  373. var ac = createElement("div");
  374. if (ua.win && ua.ie) {
  375. ac.innerHTML = obj.innerHTML;
  376. }
  377. else {
  378. var nestedObj = obj.getElementsByTagName(OBJECT)[0];
  379. if (nestedObj) {
  380. var c = nestedObj.childNodes;
  381. if (c) {
  382. var cl = c.length;
  383. for (var i = 0; i < cl; i++) {
  384. if (!(c[i].nodeType == 1 && c[i].nodeName == "PARAM") && !(c[i].nodeType == 8)) {
  385. ac.appendChild(c[i].cloneNode(true));
  386. }
  387. }
  388. }
  389. }
  390. }
  391. return ac;
  392. }
  393. /* Cross-browser dynamic SWF creation
  394. */
  395. function createSWF(attObj, parObj, id) {
  396. var r, el = getElementById(id);
  397. if (ua.wk && ua.wk < 312) { return r; }
  398. if (el) {
  399. if (typeof attObj.id == UNDEF) { // if no 'id' is defined for the object element, it will inherit the 'id' from the alternative content
  400. attObj.id = id;
  401. }
  402. if (ua.ie && ua.win) { // Internet Explorer + the HTML object element + W3C DOM methods do not combine: fall back to outerHTML
  403. var att = "";
  404. for (var i in attObj) {
  405. if (attObj[i] != Object.prototype[i]) { // filter out prototype additions from other potential libraries
  406. if (i.toLowerCase() == "data") {
  407. parObj.movie = attObj[i];
  408. }
  409. else if (i.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
  410. att += ' class="' + attObj[i] + '"';
  411. }
  412. else if (i.toLowerCase() != "classid") {
  413. att += ' ' + i + '="' + attObj[i] + '"';
  414. }
  415. }
  416. }
  417. var par = "";
  418. for (var j in parObj) {
  419. if (parObj[j] != Object.prototype[j]) { // filter out prototype additions from other potential libraries
  420. par += '<param name="' + j + '" value="' + parObj[j] + '" />';
  421. }
  422. }
  423. el.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + att + '>' + par + '</object>';
  424. objIdArr[objIdArr.length] = attObj.id; // stored to fix object 'leaks' on unload (dynamic publishing only)
  425. r = getElementById(attObj.id);
  426. }
  427. else { // well-behaving browsers
  428. var o = createElement(OBJECT);
  429. o.setAttribute("type", FLASH_MIME_TYPE);
  430. for (var m in attObj) {
  431. if (attObj[m] != Object.prototype[m]) { // filter out prototype additions from other potential libraries
  432. if (m.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
  433. o.setAttribute("class", attObj[m]);
  434. }
  435. else if (m.toLowerCase() != "classid") { // filter out IE specific attribute
  436. o.setAttribute(m, attObj[m]);
  437. }
  438. }
  439. }
  440. for (var n in parObj) {
  441. if (parObj[n] != Object.prototype[n] && n.toLowerCase() != "movie") { // filter out prototype additions from other potential libraries and IE specific param element
  442. createObjParam(o, n, parObj[n]);
  443. }
  444. }
  445. el.parentNode.replaceChild(o, el);
  446. r = o;
  447. }
  448. }
  449. return r;
  450. }
  451. function createObjParam(el, pName, pValue) {
  452. var p = createElement("param");
  453. p.setAttribute("name", pName);
  454. p.setAttribute("value", pValue);
  455. el.appendChild(p);
  456. }
  457. /* Cross-browser SWF removal
  458. - Especially needed to safely and completely remove a SWF in Internet Explorer
  459. */
  460. function removeSWF(id) {
  461. var obj = getElementById(id);
  462. if (obj && obj.nodeName == "OBJECT") {
  463. if (ua.ie && ua.win) {
  464. obj.style.display = "none";
  465. (function(){
  466. if (obj.readyState == 4) {
  467. removeObjectInIE(id);
  468. }
  469. else {
  470. setTimeout(arguments.callee, 10);
  471. }
  472. })();
  473. }
  474. else {
  475. obj.parentNode.removeChild(obj);
  476. }
  477. }
  478. }
  479. function removeObjectInIE(id) {
  480. var obj = getElementById(id);
  481. if (obj) {
  482. for (var i in obj) {
  483. if (typeof obj[i] == "function") {
  484. obj[i] = null;
  485. }
  486. }
  487. obj.parentNode.removeChild(obj);
  488. }
  489. }
  490. /* Functions to optimize JavaScript compression
  491. */
  492. function getElementById(id) {
  493. var el = null;
  494. try {
  495. el = doc.getElementById(id);
  496. }
  497. catch (e) {}
  498. return el;
  499. }
  500. function createElement(el) {
  501. return doc.createElement(el);
  502. }
  503. /* Updated attachEvent function for Internet Explorer
  504. - Stores attachEvent information in an Array, so on unload the detachEvent functions can be called to avoid memory leaks
  505. */
  506. function addListener(target, eventType, fn) {
  507. target.attachEvent(eventType, fn);
  508. listenersArr[listenersArr.length] = [target, eventType, fn];
  509. }
  510. /* Flash Player and SWF content version matching
  511. */
  512. function hasPlayerVersion(rv) {
  513. var pv = ua.pv, v = rv.split(".");
  514. v[0] = parseInt(v[0], 10);
  515. v[1] = parseInt(v[1], 10) || 0; // supports short notation, e.g. "9" instead of "9.0.0"
  516. v[2] = parseInt(v[2], 10) || 0;
  517. return (pv[0] > v[0] || (pv[0] == v[0] && pv[1] > v[1]) || (pv[0] == v[0] && pv[1] == v[1] && pv[2] >= v[2])) ? true : false;
  518. }
  519. /* Cross-browser dynamic CSS creation
  520. - Based on Bobby van der Sluis' solution: http://www.bobbyvandersluis.com/articles/dynamicCSS.php
  521. */
  522. function createCSS(sel, decl, media, newStyle) {
  523. if (ua.ie && ua.mac) { return; }
  524. var h = doc.getElementsByTagName("head")[0];
  525. if (!h) { return; } // to also support badly authored HTML pages that lack a head element
  526. var m = (media && typeof media == "string") ? media : "screen";
  527. if (newStyle) {
  528. dynamicStylesheet = null;
  529. dynamicStylesheetMedia = null;
  530. }
  531. if (!dynamicStylesheet || dynamicStylesheetMedia != m) {
  532. // create dynamic stylesheet + get a global reference to it
  533. var s = createElement("style");
  534. s.setAttribute("type", "text/css");
  535. s.setAttribute("media", m);
  536. dynamicStylesheet = h.appendChild(s);
  537. if (ua.ie && ua.win && typeof doc.styleSheets != UNDEF && doc.styleSheets.length > 0) {
  538. dynamicStylesheet = doc.styleSheets[doc.styleSheets.length - 1];
  539. }
  540. dynamicStylesheetMedia = m;
  541. }
  542. // add style rule
  543. if (ua.ie && ua.win) {
  544. if (dynamicStylesheet && typeof dynamicStylesheet.addRule == OBJECT) {
  545. dynamicStylesheet.addRule(sel, decl);
  546. }
  547. }
  548. else {
  549. if (dynamicStylesheet && typeof doc.createTextNode != UNDEF) {
  550. dynamicStylesheet.appendChild(doc.createTextNode(sel + " {" + decl + "}"));
  551. }
  552. }
  553. }
  554. function setVisibility(id, isVisible) {
  555. if (!autoHideShow) { return; }
  556. var v = isVisible ? "visible" : "hidden";
  557. if (isDomLoaded && getElementById(id)) {
  558. getElementById(id).style.visibility = v;
  559. }
  560. else {
  561. createCSS("#" + id, "visibility:" + v);
  562. }
  563. }
  564. /* Filter to avoid XSS attacks
  565. */
  566. function urlEncodeIfNecessary(s) {
  567. var regex = /[\\\"<>\.;]/;
  568. var hasBadChars = regex.exec(s) != null;
  569. return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
  570. }
  571. /* Release memory to avoid memory leaks caused by closures, fix hanging audio/video threads and force open sockets/NetConnections to disconnect (Internet Explorer only)
  572. */
  573. var cleanup = function() {
  574. if (ua.ie && ua.win) {
  575. window.attachEvent("onunload", function() {
  576. // remove listeners to avoid memory leaks
  577. var ll = listenersArr.length;
  578. for (var i = 0; i < ll; i++) {
  579. listenersArr[i][0].detachEvent(listenersArr[i][1], listenersArr[i][2]);
  580. }
  581. // cleanup dynamically embedded objects to fix audio/video threads and force open sockets and NetConnections to disconnect
  582. var il = objIdArr.length;
  583. for (var j = 0; j < il; j++) {
  584. removeSWF(objIdArr[j]);
  585. }
  586. // cleanup library's main closures to avoid memory leaks
  587. for (var k in ua) {
  588. ua[k] = null;
  589. }
  590. ua = null;
  591. for (var l in swfobject) {
  592. swfobject[l] = null;
  593. }
  594. swfobject = null;
  595. });
  596. }
  597. }();
  598. return {
  599. /* Public API
  600. - Reference: http://code.google.com/p/swfobject/wiki/documentation
  601. */
  602. registerObject: function(objectIdStr, swfVersionStr, xiSwfUrlStr, callbackFn) {
  603. if (ua.w3 && objectIdStr && swfVersionStr) {
  604. var regObj = {};
  605. regObj.id = objectIdStr;
  606. regObj.swfVersion = swfVersionStr;
  607. regObj.expressInstall = xiSwfUrlStr;
  608. regObj.callbackFn = callbackFn;
  609. regObjArr[regObjArr.length] = regObj;
  610. setVisibility(objectIdStr, false);
  611. }
  612. else if (callbackFn) {
  613. callbackFn({success:false, id:objectIdStr});
  614. }
  615. },
  616. getObjectById: function(objectIdStr) {
  617. if (ua.w3) {
  618. return getObjectById(objectIdStr);
  619. }
  620. },
  621. embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) {
  622. var callbackObj = {success:false, id:replaceElemIdStr};
  623. if (ua.w3 && !(ua.wk && ua.wk < 312) && swfUrlStr && replaceElemIdStr && widthStr && heightStr && swfVersionStr) {
  624. setVisibility(replaceElemIdStr, false);
  625. addDomLoadEvent(function() {
  626. widthStr += ""; // auto-convert to string
  627. heightStr += "";
  628. var att = {};
  629. if (attObj && typeof attObj === OBJECT) {
  630. for (var i in attObj) { // copy object to avoid the use of references, because web authors often reuse attObj for multiple SWFs
  631. att[i] = attObj[i];
  632. }
  633. }
  634. att.data = swfUrlStr;
  635. att.width = widthStr;
  636. att.height = heightStr;
  637. var par = {};
  638. if (parObj && typeof parObj === OBJECT) {
  639. for (var j in parObj) { // copy object to avoid the use of references, because web authors often reuse parObj for multiple SWFs
  640. par[j] = parObj[j];
  641. }
  642. }
  643. if (flashvarsObj && typeof flashvarsObj === OBJECT) {
  644. for (var k in flashvarsObj) { // copy object to avoid the use of references, because web authors often reuse flashvarsObj for multiple SWFs
  645. if (typeof par.flashvars != UNDEF) {
  646. par.flashvars += "&" + k + "=" + flashvarsObj[k];
  647. }
  648. else {
  649. par.flashvars = k + "=" + flashvarsObj[k];
  650. }
  651. }
  652. }
  653. if (hasPlayerVersion(swfVersionStr)) { // create SWF
  654. var obj = createSWF(att, par, replaceElemIdStr);
  655. if (att.id == replaceElemIdStr) {
  656. setVisibility(replaceElemIdStr, true);
  657. }
  658. callbackObj.success = true;
  659. callbackObj.ref = obj;
  660. }
  661. else if (xiSwfUrlStr && canExpressInstall()) { // show Adobe Express Install
  662. att.data = xiSwfUrlStr;
  663. showExpressInstall(att, par, replaceElemIdStr, callbackFn);
  664. return;
  665. }
  666. else { // show alternative content
  667. setVisibility(replaceElemIdStr, true);
  668. }
  669. if (callbackFn) { callbackFn(callbackObj); }
  670. });
  671. }
  672. else if (callbackFn) { callbackFn(callbackObj); }
  673. },
  674. switchOffAutoHideShow: function() {
  675. autoHideShow = false;
  676. },
  677. ua: ua,
  678. getFlashPlayerVersion: function() {
  679. return { major:ua.pv[0], minor:ua.pv[1], release:ua.pv[2] };
  680. },
  681. hasFlashPlayerVersion: hasPlayerVersion,
  682. createSWF: function(attObj, parObj, replaceElemIdStr) {
  683. if (ua.w3) {
  684. return createSWF(attObj, parObj, replaceElemIdStr);
  685. }
  686. else {
  687. return undefined;
  688. }
  689. },
  690. showExpressInstall: function(att, par, replaceElemIdStr, callbackFn) {
  691. if (ua.w3 && canExpressInstall()) {
  692. showExpressInstall(att, par, replaceElemIdStr, callbackFn);
  693. }
  694. },
  695. removeSWF: function(objElemIdStr) {
  696. if (ua.w3) {
  697. removeSWF(objElemIdStr);
  698. }
  699. },
  700. createCSS: function(selStr, declStr, mediaStr, newStyleBoolean) {
  701. if (ua.w3) {
  702. createCSS(selStr, declStr, mediaStr, newStyleBoolean);
  703. }
  704. },
  705. addDomLoadEvent: addDomLoadEvent,
  706. addLoadEvent: addLoadEvent,
  707. getQueryParamValue: function(param) {
  708. var q = doc.location.search || doc.location.hash;
  709. if (q) {
  710. if (/\?/.test(q)) { q = q.split("?")[1]; } // strip question mark
  711. if (param == null) {
  712. return urlEncodeIfNecessary(q);
  713. }
  714. var pairs = q.split("&");
  715. for (var i = 0; i < pairs.length; i++) {
  716. if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
  717. return urlEncodeIfNecessary(pairs[i].substring((pairs[i].indexOf("=") + 1)));
  718. }
  719. }
  720. }
  721. return "";
  722. },
  723. // For internal usage only
  724. expressInstallCallback: function() {
  725. if (isExpressInstallActive) {
  726. var obj = getElementById(EXPRESS_INSTALL_ID);
  727. if (obj && storedAltContent) {
  728. obj.parentNode.replaceChild(storedAltContent, obj);
  729. if (storedAltContentId) {
  730. setVisibility(storedAltContentId, true);
  731. if (ua.ie && ua.win) { storedAltContent.style.display = "block"; }
  732. }
  733. if (storedCallbackFn) { storedCallbackFn(storedCallbackObj); }
  734. }
  735. isExpressInstallActive = false;
  736. }
  737. }
  738. };
  739. }();
  740. /**
  741. * @class Ext.FlashComponent
  742. * @extends Ext.BoxComponent
  743. * @constructor
  744. * @xtype flash
  745. */
  746. Ext.FlashComponent = Ext.extend(Ext.BoxComponent, {
  747. /**
  748. * @cfg {String} flashVersion
  749. * Indicates the version the flash content was published for. Defaults to <tt>'9.0.115'</tt>.
  750. */
  751. flashVersion : '9.0.115',
  752. /**
  753. * @cfg {String} backgroundColor
  754. * The background color of the chart. Defaults to <tt>'#ffffff'</tt>.
  755. */
  756. backgroundColor: '#ffffff',
  757. /**
  758. * @cfg {String} wmode
  759. * The wmode of the flash object. This can be used to control layering. Defaults to <tt>'opaque'</tt>.
  760. */
  761. wmode: 'opaque',
  762. /**
  763. * @cfg {Object} flashVars
  764. * A set of key value pairs to be passed to the flash object as flash variables. Defaults to <tt>undefined</tt>.
  765. */
  766. flashVars: undefined,
  767. /**
  768. * @cfg {Object} flashParams
  769. * A set of key value pairs to be passed to the flash object as parameters. Possible parameters can be found here:
  770. * http://kb2.adobe.com/cps/127/tn_12701.html Defaults to <tt>undefined</tt>.
  771. */
  772. flashParams: undefined,
  773. /**
  774. * @cfg {String} url
  775. * The URL of the chart to include. Defaults to <tt>undefined</tt>.
  776. */
  777. url: undefined,
  778. swfId : undefined,
  779. swfWidth: '100%',
  780. swfHeight: '100%',
  781. /**
  782. * @cfg {Boolean} expressInstall
  783. * True to prompt the user to install flash if not installed. Note that this uses
  784. * Ext.FlashComponent.EXPRESS_INSTALL_URL, which should be set to the local resource. Defaults to <tt>false</tt>.
  785. */
  786. expressInstall: false,
  787. initComponent : function(){
  788. Ext.FlashComponent.superclass.initComponent.call(this);
  789. this.addEvents(
  790. /**
  791. * @event initialize
  792. *
  793. * @param {Chart} this
  794. */
  795. 'initialize'
  796. );
  797. },
  798. onRender : function(){
  799. Ext.FlashComponent.superclass.onRender.apply(this, arguments);
  800. var params = Ext.apply({
  801. allowScriptAccess: 'always',
  802. bgcolor: this.backgroundColor,
  803. wmode: this.wmode
  804. }, this.flashParams), vars = Ext.apply({
  805. allowedDomain: document.location.hostname,
  806. YUISwfId: this.getId(),
  807. YUIBridgeCallback: 'Ext.FlashEventProxy.onEvent'
  808. }, this.flashVars);
  809. new swfobject.embedSWF(this.url, this.id, this.swfWidth, this.swfHeight, this.flashVersion,
  810. this.expressInstall ? Ext.FlashComponent.EXPRESS_INSTALL_URL : undefined, vars, params);
  811. this.swf = Ext.getDom(this.id);
  812. this.el = Ext.get(this.swf);
  813. },
  814. getSwfId : function(){
  815. return this.swfId || (this.swfId = "extswf" + (++Ext.Component.AUTO_ID));
  816. },
  817. getId : function(){
  818. return this.id || (this.id = "extflashcmp" + (++Ext.Component.AUTO_ID));
  819. },
  820. onFlashEvent : function(e){
  821. switch(e.type){
  822. case "swfReady":
  823. this.initSwf();
  824. return;
  825. case "log":
  826. return;
  827. }
  828. e.component = this;
  829. this.fireEvent(e.type.toLowerCase().replace(/event$/, ''), e);
  830. },
  831. initSwf : function(){
  832. this.onSwfReady(!!this.isInitialized);
  833. this.isInitialized = true;
  834. this.fireEvent('initialize', this);
  835. },
  836. beforeDestroy: function(){
  837. if(this.rendered){
  838. swfobject.removeSWF(this.swf.id);
  839. }
  840. Ext.FlashComponent.superclass.beforeDestroy.call(this);
  841. },
  842. onSwfReady : Ext.emptyFn
  843. });
  844. /**
  845. * Sets the url for installing flash if it doesn't exist. This should be set to a local resource.
  846. * @static
  847. * @type String
  848. */
  849. Ext.FlashComponent.EXPRESS_INSTALL_URL = 'http:/' + '/swfobject.googlecode.com/svn/trunk/swfobject/expressInstall.swf';
  850. Ext.reg('flash', Ext.FlashComponent);/**
  851. * @class Ext.FlashProxy
  852. * @singleton
  853. */
  854. Ext.FlashEventProxy = {
  855. onEvent : function(id, e){
  856. var fp = Ext.getCmp(id);
  857. if(fp){
  858. fp.onFlashEvent(e);
  859. }else{
  860. arguments.callee.defer(10, this, [id, e]);
  861. }
  862. }
  863. };/**
  864. * @class Ext.chart.Chart
  865. * @extends Ext.FlashComponent
  866. * The Ext.chart package provides the capability to visualize data with flash based charting.
  867. * Each chart binds directly to an Ext.data.Store enabling automatic updates of the chart.
  868. * To change the look and feel of a chart, see the {@link #chartStyle} and {@link #extraStyle} config options.
  869. * @constructor
  870. * @xtype chart
  871. */
  872. Ext.chart.Chart = Ext.extend(Ext.FlashComponent, {
  873. refreshBuffer: 100,
  874. /**
  875. * @cfg {String} backgroundColor
  876. * @hide
  877. */
  878. /**
  879. * @cfg {Object} chartStyle
  880. * Sets styles for this chart. This contains default styling, so modifying this property will <b>override</b>
  881. * the built in styles of the chart. Use {@link #extraStyle} to add customizations to the default styling.
  882. */
  883. chartStyle: {
  884. padding: 10,
  885. animationEnabled: true,
  886. font: {
  887. name: 'Tahoma',
  888. color: 0x444444,
  889. size: 11
  890. },
  891. dataTip: {
  892. padding: 5,
  893. border: {
  894. color: 0x99bbe8,
  895. size:1
  896. },
  897. background: {
  898. color: 0xDAE7F6,
  899. alpha: .9
  900. },
  901. font: {
  902. name: 'Tahoma',
  903. color: 0x15428B,
  904. size: 10,
  905. bold: true
  906. }
  907. }
  908. },
  909. /**
  910. * @cfg {String} url
  911. * The url to load the chart from. This defaults to Ext.chart.Chart.CHART_URL, which should
  912. * be modified to point to the local charts resource.
  913. */
  914. /**
  915. * @cfg {Object} extraStyle
  916. * Contains extra styles that will be added or overwritten to the default chartStyle. Defaults to <tt>null</tt>.
  917. * For a detailed list of the options available, visit the YUI Charts site
  918. * at <a href="http://developer.yahoo.com/yui/charts/#basicstyles">http://developer.yahoo.com/yui/charts/#basicstyles</a><br/>
  919. * Some of the options availabe:<br />
  920. * <ul style="padding:5px;padding-left:16px;list-style-type:inherit;">
  921. * <li><b>padding</b> - The space around the edge of the chart's contents. Padding does not increase the size of the chart.</li>
  922. * <li><b>animationEnabled</b> - A Boolean value that specifies whether marker animations are enabled or not. Enabled by default.</li>
  923. * <li><b>font</b> - An Object defining the font style to be used in the chart. Defaults to <tt>{ name: 'Tahoma', color: 0x444444, size: 11 }</tt><br/>
  924. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  925. * <li><b>name</b> - font name</li>
  926. * <li><b>color</b> - font color (hex code, ie: "#ff0000", "ff0000" or 0xff0000)</li>
  927. * <li><b>size</b> - font size in points (numeric portion only, ie: 11)</li>
  928. * <li><b>bold</b> - boolean</li>
  929. * <li><b>italic</b> - boolean</li>
  930. * <li><b>underline</b> - boolean</li>
  931. * </ul>
  932. * </li>
  933. * <li><b>border</b> - An object defining the border style around the chart. The chart itself will decrease in dimensions to accomodate the border.<br/>
  934. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  935. * <li><b>color</b> - border color (hex code, ie: "#ff0000", "ff0000" or 0xff0000)</li>
  936. * <li><b>size</b> - border size in pixels (numeric portion only, ie: 1)</li>
  937. * </ul>
  938. * </li>
  939. * <li><b>background</b> - An object defining the background style of the chart.<br/>
  940. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  941. * <li><b>color</b> - border color (hex code, ie: "#ff0000", "ff0000" or 0xff0000)</li>
  942. * <li><b>image</b> - an image URL. May be relative to the current document or absolute.</li>
  943. * </ul>
  944. * </li>
  945. * <li><b>legend</b> - An object defining the legend style<br/>
  946. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  947. * <li><b>display</b> - location of the legend. Possible values are "none", "left", "right", "top", and "bottom".</li>
  948. * <li><b>spacing</b> - an image URL. May be relative to the current document or absolute.</li>
  949. * <li><b>padding, border, background, font</b> - same options as described above.</li>
  950. * </ul></li>
  951. * <li><b>dataTip</b> - An object defining the style of the data tip (tooltip).<br/>
  952. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  953. * <li><b>padding, border, background, font</b> - same options as described above.</li>
  954. * </ul></li>
  955. * <li><b>xAxis and yAxis</b> - An object defining the style of the style of either axis.<br/>
  956. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  957. * <li><b>color</b> - same option as described above.</li>
  958. * <li><b>size</b> - same option as described above.</li>
  959. * <li><b>showLabels</b> - boolean</li>
  960. * <li><b>labelRotation</b> - a value in degrees from -90 through 90. Default is zero.</li>
  961. * </ul></li>
  962. * <li><b>majorGridLines and minorGridLines</b> - An object defining the style of the style of the grid lines.<br/>
  963. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  964. * <li><b>color, size</b> - same options as described above.</li>
  965. * </ul></li></li>
  966. * <li><b>zeroGridLine</b> - An object defining the style of the style of the zero grid line.<br/>
  967. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  968. * <li><b>color, size</b> - same options as described above.</li>
  969. * </ul></li></li>
  970. * <li><b>majorTicks and minorTicks</b> - An object defining the style of the style of ticks in the chart.<br/>
  971. * <ul style="padding:5px;padding-left:26px;list-style-type:circle;">
  972. * <li><b>color, size</b> - same options as described above.</li>
  973. * <li><b>length</b> - the length of each tick in pixels extending from the axis.</li>
  974. * <li><b>display</b> - how the ticks are drawn. Possible values are "none", "inside", "outside", and "cross".</li>
  975. * </ul></li></li>
  976. * </ul>
  977. */
  978. extraStyle: null,
  979. /**
  980. * @cfg {Object} seriesStyles
  981. * Contains styles to apply to the series after a refresh. Defaults to <tt>null</tt>.
  982. */
  983. seriesStyles: null,
  984. /**
  985. * @cfg {Boolean} disableCaching
  986. * True to add a "cache buster" to the end of the chart url. Defaults to true for Opera and IE.
  987. */
  988. disableCaching: Ext.isIE || Ext.isOpera,
  989. disableCacheParam: '_dc',
  990. initComponent : function(){
  991. Ext.chart.Chart.superclass.initComponent.call(this);
  992. if(!this.url){
  993. this.url = Ext.chart.Chart.CHART_URL;
  994. }
  995. if(this.disableCaching){
  996. this.url = Ext.urlAppend(this.url, String.format('{0}={1}', this.disableCacheParam, new Date().getTime()));
  997. }
  998. this.addEvents(
  999. 'itemmouseover',
  1000. 'itemmouseout',
  1001. 'itemclick',
  1002. 'itemdoubleclick',
  1003. 'itemdragstart',
  1004. 'itemdrag',
  1005. 'itemdragend',
  1006. /**
  1007. * @event beforerefresh
  1008. * Fires before a refresh to the chart data is called. If the beforerefresh handler returns
  1009. * <tt>false</tt> the {@link #refresh} action will be cancelled.
  1010. * @param {Chart} this
  1011. */
  1012. 'beforerefresh',
  1013. /**
  1014. * @event refresh
  1015. * Fires after the chart data has been refreshed.
  1016. * @param {Chart} this
  1017. */
  1018. 'refresh'
  1019. );
  1020. this.store = Ext.StoreMgr.lookup(this.store);
  1021. },
  1022. /**
  1023. * Sets a single style value on the Chart instance.
  1024. *
  1025. * @param name {String} Name of the Chart style value to change.
  1026. * @param value {Object} New value to pass to the Chart style.
  1027. */
  1028. setStyle: function(name, value){
  1029. this.swf.setStyle(name, Ext.encode(value));
  1030. },
  1031. /**
  1032. * Resets all styles on the Chart instance.
  1033. *
  1034. * @param styles {Object} Initializer for all Chart styles.
  1035. */
  1036. setStyles: function(styles){
  1037. this.swf.setStyles(Ext.encode(styles));
  1038. },
  1039. /**
  1040. * Sets the styles on all series in the Chart.
  1041. *
  1042. * @param styles {Array} Initializer for all Chart series styles.
  1043. */
  1044. setSeriesStyles: function(styles){
  1045. this.seriesStyles = styles;
  1046. var s = [];
  1047. Ext.each(styles, function(style){
  1048. s.push(Ext.encode(style));
  1049. });
  1050. this.swf.setSeriesStyles(s);
  1051. },
  1052. setCategoryNames : function(names){
  1053. this.swf.setCategoryNames(names);
  1054. },
  1055. setLegendRenderer : function(fn, scope){
  1056. var chart = this;
  1057. scope = scope || chart;
  1058. chart.removeFnProxy(chart.legendFnName);
  1059. chart.legendFnName = chart.createFnProxy(function(name){
  1060. return fn.call(scope, name);
  1061. });
  1062. chart.swf.setLegendLabelFunction(chart.legendFnName);
  1063. },
  1064. setTipRenderer : function(fn, scope){
  1065. var chart = this;
  1066. scope = scope || chart;
  1067. chart.removeFnProxy(chart.tipFnName);
  1068. chart.tipFnName = chart.createFnProxy(function(item, index, series){
  1069. var record = chart.store.getAt(index);
  1070. return fn.call(scope, chart, record, index, series);
  1071. });
  1072. chart.swf.setDataTipFunction(chart.tipFnName);
  1073. },
  1074. setSeries : function(series){
  1075. this.series = series;
  1076. this.refresh();
  1077. },
  1078. /**
  1079. * Changes the data store bound to this chart and refreshes it.
  1080. * @param {Store} store The store to bind to this chart
  1081. */
  1082. bindStore : function(store, initial){
  1083. if(!initial && this.store){
  1084. if(store !== this.store && this.store.autoDestroy){
  1085. this.store.destroy();
  1086. }else{
  1087. this.store.un("datachanged", this.refresh, this);
  1088. this.store.un("add", this.delayRefresh, this);
  1089. this.store.un("remove", this.delayRefresh, this);
  1090. this.store.un("update", this.delayRefresh, this);
  1091. this.store.un("clear", this.refresh, this);
  1092. }
  1093. }
  1094. if(store){
  1095. store = Ext.StoreMgr.lookup(store);
  1096. store.on({
  1097. scope: this,
  1098. datachanged: this.refresh,
  1099. add: this.delayRefresh,
  1100. remove: this.delayRefresh,
  1101. update: this.delayRefresh,
  1102. clear: this.refresh
  1103. });
  1104. }
  1105. this.store = store;
  1106. if(store && !initial){
  1107. this.refresh();
  1108. }
  1109. },
  1110. onSwfReady : function(isReset){
  1111. Ext.chart.Chart.superclass.onSwfReady.call(this, isReset);
  1112. var ref;
  1113. this.swf.setType(this.type);
  1114. if(this.chartStyle){
  1115. this.setStyles(Ext.apply({}, this.extraStyle, this.chartStyle));
  1116. }
  1117. if(this.categoryNames){
  1118. this.setCategoryNames(this.categoryNames);
  1119. }
  1120. if(this.tipRenderer){
  1121. ref = this.getFunctionRef(this.tipRenderer);
  1122. this.setTipRenderer(ref.fn, ref.scope);
  1123. }
  1124. if(this.legendRenderer){
  1125. ref = this.getFunctionRef(this.legendRenderer);
  1126. this.setLegendRenderer(ref.fn, ref.scope);
  1127. }
  1128. if(!isReset){
  1129. this.bindStore(this.store, true);
  1130. }
  1131. this.refresh.defer(10, this);
  1132. },
  1133. delayRefresh : function(){
  1134. if(!this.refreshTask){
  1135. this.refreshTask = new Ext.util.DelayedTask(this.refresh, this);
  1136. }
  1137. this.refreshTask.delay(this.refreshBuffer);
  1138. },
  1139. refresh : function(){
  1140. if(this.fireEvent('beforerefresh', this) !== false){
  1141. var styleChanged = false;
  1142. // convert the store data into something YUI charts can understand
  1143. var data = [], rs = this.store.data.items;
  1144. for(var j = 0, len = rs.length; j < len; j++){
  1145. data[j] = rs[j].data;
  1146. }
  1147. //make a copy of the series definitions so that we aren't
  1148. //editing them directly.
  1149. var dataProvider = [];
  1150. var seriesCount = 0;
  1151. var currentSeries = null;
  1152. var i = 0;
  1153. if(this.series){
  1154. seriesCount = this.series.length;
  1155. for(i = 0; i < seriesCount; i++){
  1156. currentSeries = this.series[i];
  1157. var clonedSeries = {};
  1158. for(var prop in currentSeries){
  1159. if(prop == "style" && currentSeries.style !== null){
  1160. clonedSeries.style = Ext.encode(currentSeries.style);
  1161. styleChanged = true;
  1162. //we don't want to modify the styles again next time
  1163. //so null out the style property.
  1164. // this causes issues
  1165. // currentSeries.style = null;
  1166. } else{
  1167. clonedSeries[prop] = currentSeries[prop];
  1168. }
  1169. }
  1170. dataProvider.push(clonedSeries);
  1171. }
  1172. }
  1173. if(seriesCount > 0){
  1174. for(i = 0; i < seriesCount; i++){
  1175. currentSeries = dataProvider[i];
  1176. if(!currentSeries.type){
  1177. currentSeries.type = this.type;
  1178. }
  1179. currentSeries.dataProvider = data;
  1180. }
  1181. } else{
  1182. dataProvider.push({type: this.type, dataProvider: data});
  1183. }
  1184. this.swf.setDataProvider(dataProvider);
  1185. if(this.seriesStyles){
  1186. this.setSeriesStyles(this.seriesStyles);
  1187. }
  1188. this.fireEvent('refresh', this);
  1189. }
  1190. },
  1191. // private
  1192. createFnProxy : function(fn){
  1193. var fnName = 'extFnProxy' + (++Ext.chart.Chart.PROXY_FN_ID);
  1194. Ext.chart.Chart.proxyFunction[fnName] = fn;
  1195. return 'Ext.chart.Chart.proxyFunction.' + fnName;
  1196. },
  1197. // private
  1198. removeFnProxy : function(fn){
  1199. if(!Ext.isEmpty(fn)){
  1200. fn = fn.replace('Ext.chart.Chart.proxyFunction.', '');
  1201. delete Ext.chart.Chart.proxyFunction[fn];
  1202. }
  1203. },
  1204. // private
  1205. getFunctionRef : function(val){
  1206. if(Ext.isFunction(val)){
  1207. return {
  1208. fn: val,
  1209. scope: this
  1210. };
  1211. }else{
  1212. return {
  1213. fn: val.fn,
  1214. scope: val.scope || this
  1215. }
  1216. }
  1217. },
  1218. // private
  1219. onDestroy: function(){
  1220. if (this.refreshTask && this.refreshTask.cancel){
  1221. this.refreshTask.cancel();
  1222. }
  1223. Ext.chart.Chart.superclass.onDestroy.call(this);
  1224. this.bindStore(null);
  1225. this.removeFnProxy(this.tipFnName);
  1226. this.removeFnProxy(this.legendFnName);
  1227. }
  1228. });
  1229. Ext.reg('chart', Ext.chart.Chart);
  1230. Ext.chart.Chart.PROXY_FN_ID = 0;
  1231. Ext.chart.Chart.proxyFunction = {};
  1232. /**
  1233. * Sets the url to load the chart from. This should be set to a local resource.
  1234. * @static
  1235. * @type String
  1236. */
  1237. Ext.chart.Chart.CHART_URL = 'http:/' + '/yui.yahooapis.com/2.8.0/build/charts/assets/charts.swf';
  1238. /**
  1239. * @class Ext.chart.PieChart
  1240. * @extends Ext.chart.Chart
  1241. * @constructor
  1242. * @xtype piechart
  1243. */
  1244. Ext.chart.PieChart = Ext.extend(Ext.chart.Chart, {
  1245. type: 'pie',
  1246. onSwfReady : function(isReset){
  1247. Ext.chart.PieChart.superclass.onSwfReady.call(this, isReset);
  1248. this.setDataField(this.dataField);
  1249. this.setCategoryField(this.categoryField);
  1250. },
  1251. setDataField : function(field){
  1252. this.dataField = field;
  1253. this.swf.setDataField(field);
  1254. },
  1255. setCategoryField : function(field){
  1256. this.categoryField = field;
  1257. this.swf.setCategoryField(field);
  1258. }
  1259. });
  1260. Ext.reg('piechart', Ext.chart.PieChart);
  1261. /**
  1262. * @class Ext.chart.CartesianChart
  1263. * @extends Ext.chart.Chart
  1264. * @constructor
  1265. * @xtype cartesianchart
  1266. */
  1267. Ext.chart.CartesianChart = Ext.extend(Ext.chart.Chart, {
  1268. onSwfReady : function(isReset){
  1269. Ext.chart.CartesianChart.superclass.onSwfReady.call(this, isReset);
  1270. this.labelFn = [];
  1271. if(this.xField){
  1272. this.setXField(this.xField);
  1273. }
  1274. if(this.yField){
  1275. this.setYField(this.yField);
  1276. }
  1277. if(this.xAxis){
  1278. this.setXAxis(this.xAxis);
  1279. }
  1280. if(this.xAxes){
  1281. this.setXAxes(this.xAxes);
  1282. }
  1283. if(this.yAxis){
  1284. this.setYAxis(this.yAxis);
  1285. }
  1286. if(this.yAxes){
  1287. this.setYAxes(this.yAxes);
  1288. }
  1289. if(Ext.isDefined(this.constrainViewport)){
  1290. this.swf.setConstrainViewport(this.constrainViewport);
  1291. }
  1292. },
  1293. setXField : function(value){
  1294. this.xField = value;
  1295. this.swf.setHorizontalField(value);
  1296. },
  1297. setYField : function(value){
  1298. this.yField = value;
  1299. this.swf.setVerticalField(value);
  1300. },
  1301. setXAxis : function(value){
  1302. this.xAxis = this.createAxis('xAxis', value);
  1303. this.swf.setHorizontalAxis(this.xAxis);
  1304. },
  1305. setXAxes : function(value){
  1306. var axis;
  1307. for(var i = 0; i < value.length; i++) {
  1308. axis = this.createAxis('xAxis' + i, value[i]);
  1309. this.swf.setHorizontalAxis(axis);
  1310. }
  1311. },
  1312. setYAxis : function(value){
  1313. this.yAxis = this.createAxis('yAxis', value);
  1314. this.swf.setVerticalAxis(this.yAxis);
  1315. },
  1316. setYAxes : function(value){
  1317. var axis;
  1318. for(var i = 0; i < value.length; i++) {
  1319. axis = this.createAxis('yAxis' + i, value[i]);
  1320. this.swf.setVerticalAxis(axis);
  1321. }
  1322. },
  1323. createAxis : function(axis, value){
  1324. var o = Ext.apply({}, value),
  1325. ref,
  1326. old;
  1327. if(this[axis]){
  1328. old = this[axis].labelFunction;
  1329. this.removeFnProxy(old);
  1330. this.labelFn.remove(old);
  1331. }
  1332. if(o.labelRenderer){
  1333. ref = this.getFunctionRef(o.labelRenderer);
  1334. o.labelFunction = this.createFnProxy(function(v){
  1335. return ref.fn.call(ref.scope, v);
  1336. });
  1337. delete o.labelRenderer;
  1338. this.labelFn.push(o.labelFunction);
  1339. }
  1340. if(axis.indexOf('xAxis') > -1 && o.position == 'left'){
  1341. o.position = 'bottom';
  1342. }
  1343. return o;
  1344. },
  1345. onDestroy : function(){
  1346. Ext.chart.CartesianChart.superclass.onDestroy.call(this);
  1347. Ext.each(this.labelFn, function(fn){
  1348. this.removeFnProxy(fn);
  1349. }, this);
  1350. }
  1351. });
  1352. Ext.reg('cartesianchart', Ext.chart.CartesianChart);
  1353. /**
  1354. * @class Ext.chart.LineChart
  1355. * @extends Ext.chart.CartesianChart
  1356. * @constructor
  1357. * @xtype linechart
  1358. */
  1359. Ext.chart.LineChart = Ext.extend(Ext.chart.CartesianChart, {
  1360. type: 'line'
  1361. });
  1362. Ext.reg('linechart', Ext.chart.LineChart);
  1363. /**
  1364. * @class Ext.chart.ColumnChart
  1365. * @extends Ext.chart.CartesianChart
  1366. * @constructor
  1367. * @xtype columnchart
  1368. */
  1369. Ext.chart.ColumnChart = Ext.extend(Ext.chart.CartesianChart, {
  1370. type: 'column'
  1371. });
  1372. Ext.reg('columnchart', Ext.chart.ColumnChart);
  1373. /**
  1374. * @class Ext.chart.StackedColumnChart
  1375. * @extends Ext.chart.CartesianChart
  1376. * @constructor
  1377. * @xtype stackedcolumnchart
  1378. */
  1379. Ext.chart.StackedColumnChart = Ext.extend(Ext.chart.CartesianChart, {
  1380. type: 'stackcolumn'
  1381. });
  1382. Ext.reg('stackedcolumnchart', Ext.chart.StackedColumnChart);
  1383. /**
  1384. * @class Ext.chart.BarChart
  1385. * @extends Ext.chart.CartesianChart
  1386. * @constructor
  1387. * @xtype barchart
  1388. */
  1389. Ext.chart.BarChart = Ext.extend(Ext.chart.CartesianChart, {
  1390. type: 'bar'
  1391. });
  1392. Ext.reg('barchart', Ext.chart.BarChart);
  1393. /**
  1394. * @class Ext.chart.StackedBarChart
  1395. * @extends Ext.chart.CartesianChart
  1396. * @constructor
  1397. * @xtype stackedbarchart
  1398. */
  1399. Ext.chart.StackedBarChart = Ext.extend(Ext.chart.CartesianChart, {
  1400. type: 'stackbar'
  1401. });
  1402. Ext.reg('stackedbarchart', Ext.chart.StackedBarChart);
  1403. /**
  1404. * @class Ext.chart.Axis
  1405. * Defines a CartesianChart's vertical or horizontal axis.
  1406. * @constructor
  1407. */
  1408. Ext.chart.Axis = function(config){
  1409. Ext.apply(this, config);
  1410. };
  1411. Ext.chart.Axis.prototype =
  1412. {
  1413. /**
  1414. * The type of axis.
  1415. *
  1416. * @property type
  1417. * @type String
  1418. */
  1419. type: null,
  1420. /**
  1421. * The direction in which the axis is drawn. May be "horizontal" or "vertical".
  1422. *
  1423. * @property orientation
  1424. * @type String
  1425. */
  1426. orientation: "horizontal",
  1427. /**
  1428. * If true, the items on the axis will be drawn in opposite direction.
  1429. *
  1430. * @property reverse
  1431. * @type Boolean
  1432. */
  1433. reverse: false,
  1434. /**
  1435. * A string reference to the globally-accessible function that may be called to
  1436. * determine each of the label values for this axis.
  1437. *
  1438. * @property labelFunction
  1439. * @type String
  1440. */
  1441. labelFunction: null,
  1442. /**
  1443. * If true, labels that overlap previously drawn labels on the axis will be hidden.
  1444. *
  1445. * @property hideOverlappingLabels
  1446. * @type Boolean
  1447. */
  1448. hideOverlappingLabels: true,
  1449. /**
  1450. * The space, in pixels, between labels on an axis.
  1451. *
  1452. * @property labelSpacing
  1453. * @type Number
  1454. */
  1455. labelSpacing: 2
  1456. };
  1457. /**
  1458. * @class Ext.chart.NumericAxis
  1459. * @extends Ext.chart.Axis
  1460. * A type of axis whose units are measured in numeric values.
  1461. * @constructor
  1462. */
  1463. Ext.chart.NumericAxis = Ext.extend(Ext.chart.Axis, {
  1464. type: "numeric",
  1465. /**
  1466. * The minimum value drawn by the axis. If not set explicitly, the axis
  1467. * minimum will be calculated automatically.
  1468. *
  1469. * @property minimum
  1470. * @type Number
  1471. */
  1472. minimum: NaN,
  1473. /**
  1474. * The maximum value drawn by the axis. If not set explicitly, the axis
  1475. * maximum will be calculated automatically.
  1476. *
  1477. * @property maximum
  1478. * @type Number
  1479. */
  1480. maximum: NaN,
  1481. /**
  1482. * The spacing between major intervals on this axis.
  1483. *
  1484. * @property majorUnit
  1485. * @type Number
  1486. */
  1487. majorUnit: NaN,
  1488. /**
  1489. * The spacing between minor intervals on this axis.
  1490. *
  1491. * @property minorUnit
  1492. * @type Number
  1493. */
  1494. minorUnit: NaN,
  1495. /**
  1496. * If true, the labels, ticks, gridlines, and other objects will snap to the
  1497. * nearest major or minor unit. If false, their position will be based on
  1498. * the minimum value.
  1499. *
  1500. * @property snapToUnits
  1501. * @type Boolean
  1502. */
  1503. snapToUnits: true,
  1504. /**
  1505. * If true, and the bounds are calculated automatically, either the minimum
  1506. * or maximum will be set to zero.
  1507. *
  1508. * @property alwaysShowZero
  1509. * @type Boolean
  1510. */
  1511. alwaysShowZero: true,
  1512. /**
  1513. * The scaling algorithm to use on this axis. May be "linear" or
  1514. * "logarithmic".
  1515. *
  1516. * @property scale
  1517. * @type String
  1518. */
  1519. scale: "linear",
  1520. /**
  1521. * Indicates whether to round the major unit.
  1522. *
  1523. * @property roundMajorUnit
  1524. * @type Boolean
  1525. */
  1526. roundMajorUnit: true,
  1527. /**
  1528. * Indicates whether to factor in the size of the labels when calculating a
  1529. * major unit.
  1530. *
  1531. * @property calculateByLabelSize
  1532. * @type Boolean
  1533. */
  1534. calculateByLabelSize: true,
  1535. /**
  1536. * Indicates the position of the axis relative to the chart
  1537. *
  1538. * @property position
  1539. * @type String
  1540. */
  1541. position: 'left',
  1542. /**
  1543. * Indicates whether to extend maximum beyond data's maximum to the nearest
  1544. * majorUnit.
  1545. *
  1546. * @property adjustMaximumByMajorUnit
  1547. * @type Boolean
  1548. */
  1549. adjustMaximumByMajorUnit: true,
  1550. /**
  1551. * Indicates whether to extend the minimum beyond data's minimum to the
  1552. * nearest majorUnit.
  1553. *
  1554. * @property adjustMinimumByMajorUnit
  1555. * @type Boolean
  1556. */
  1557. adjustMinimumByMajorUnit: true
  1558. });
  1559. /**
  1560. * @class Ext.chart.TimeAxis
  1561. * @extends Ext.chart.Axis
  1562. * A type of axis whose units are measured in time-based values.
  1563. * @constructor
  1564. */
  1565. Ext.chart.TimeAxis = Ext.extend(Ext.chart.Axis, {
  1566. type: "time",
  1567. /**
  1568. * The minimum value drawn by the axis. If not set explicitly, the axis
  1569. * minimum will be calculated automatically.
  1570. *
  1571. * @property minimum
  1572. * @type Date
  1573. */
  1574. minimum: null,
  1575. /**
  1576. * The maximum value drawn by the axis. If not set explicitly, the axis
  1577. * maximum will be calculated automatically.
  1578. *
  1579. * @property maximum
  1580. * @type Number
  1581. */
  1582. maximum: null,
  1583. /**
  1584. * The spacing between major intervals on this axis.
  1585. *
  1586. * @property majorUnit
  1587. * @type Number
  1588. */
  1589. majorUnit: NaN,
  1590. /**
  1591. * The time unit used by the majorUnit.
  1592. *
  1593. * @property majorTimeUnit
  1594. * @type String
  1595. */
  1596. majorTimeUnit: null,
  1597. /**
  1598. * The spacing between minor intervals on this axis.
  1599. *
  1600. * @property majorUnit
  1601. * @type Number
  1602. */
  1603. minorUnit: NaN,
  1604. /**
  1605. * The time unit used by the minorUnit.
  1606. *
  1607. * @property majorTimeUnit
  1608. * @type String
  1609. */
  1610. minorTimeUnit: null,
  1611. /**
  1612. * If true, the labels, ticks, gridlines, and other objects will snap to the
  1613. * nearest major or minor unit. If false, their position will be based on
  1614. * the minimum value.
  1615. *
  1616. * @property snapToUnits
  1617. * @type Boolean
  1618. */
  1619. snapToUnits: true,
  1620. /**
  1621. * Series that are stackable will only stack when this value is set to true.
  1622. *
  1623. * @property stackingEnabled
  1624. * @type Boolean
  1625. */
  1626. stackingEnabled: false,
  1627. /**
  1628. * Indicates whether to factor in the size of the labels when calculating a
  1629. * major unit.
  1630. *
  1631. * @property calculateByLabelSize
  1632. * @type Boolean
  1633. */
  1634. calculateByLabelSize: true
  1635. });
  1636. /**
  1637. * @class Ext.chart.CategoryAxis
  1638. * @extends Ext.chart.Axis
  1639. * A type of axis that displays items in categories.
  1640. * @constructor
  1641. */
  1642. Ext.chart.CategoryAxis = Ext.extend(Ext.chart.Axis, {
  1643. type: "category",
  1644. /**
  1645. * A list of category names to display along this axis.
  1646. *
  1647. * @property categoryNames
  1648. * @type Array
  1649. */
  1650. categoryNames: null,
  1651. /**
  1652. * Indicates whether or not to calculate the number of categories (ticks and
  1653. * labels) when there is not enough room to display all labels on the axis.
  1654. * If set to true, the axis will determine the number of categories to plot.
  1655. * If not, all categories will be plotted.
  1656. *
  1657. * @property calculateCategoryCount
  1658. * @type Boolean
  1659. */
  1660. calculateCategoryCount: false
  1661. });
  1662. /**
  1663. * @class Ext.chart.Series
  1664. * Series class for the charts widget.
  1665. * @constructor
  1666. */
  1667. Ext.chart.Series = function(config) { Ext.apply(this, config); };
  1668. Ext.chart.Series.prototype =
  1669. {
  1670. /**
  1671. * The type of series.
  1672. *
  1673. * @property type
  1674. * @type String
  1675. */
  1676. type: null,
  1677. /**
  1678. * The human-readable name of the series.
  1679. *
  1680. * @property displayName
  1681. * @type String
  1682. */
  1683. displayName: null
  1684. };
  1685. /**
  1686. * @class Ext.chart.CartesianSeries
  1687. * @extends Ext.chart.Series
  1688. * CartesianSeries class for the charts widget.
  1689. * @constructor
  1690. */
  1691. Ext.chart.CartesianSeries = Ext.extend(Ext.chart.Series, {
  1692. /**
  1693. * The field used to access the x-axis value from the items from the data
  1694. * source.
  1695. *
  1696. * @property xField
  1697. * @type String
  1698. */
  1699. xField: null,
  1700. /**
  1701. * The field used to access the y-axis value from the items from the data
  1702. * source.
  1703. *
  1704. * @property yField
  1705. * @type String
  1706. */
  1707. yField: null,
  1708. /**
  1709. * False to not show this series in the legend. Defaults to <tt>true</tt>.
  1710. *
  1711. * @property showInLegend
  1712. * @type Boolean
  1713. */
  1714. showInLegend: true,
  1715. /**
  1716. * Indicates which axis the series will bind to
  1717. *
  1718. * @property axis
  1719. * @type String
  1720. */
  1721. axis: 'primary'
  1722. });
  1723. /**
  1724. * @class Ext.chart.ColumnSeries
  1725. * @extends Ext.chart.CartesianSeries
  1726. * ColumnSeries class for the charts widget.
  1727. * @constructor
  1728. */
  1729. Ext.chart.ColumnSeries = Ext.extend(Ext.chart.CartesianSeries, {
  1730. type: "column"
  1731. });
  1732. /**
  1733. * @class Ext.chart.LineSeries
  1734. * @extends Ext.chart.CartesianSeries
  1735. * LineSeries class for the charts widget.
  1736. * @constructor
  1737. */
  1738. Ext.chart.LineSeries = Ext.extend(Ext.chart.CartesianSeries, {
  1739. type: "line"
  1740. });
  1741. /**
  1742. * @class Ext.chart.BarSeries
  1743. * @extends Ext.chart.CartesianSeries
  1744. * BarSeries class for the charts widget.
  1745. * @constructor
  1746. */
  1747. Ext.chart.BarSeries = Ext.extend(Ext.chart.CartesianSeries, {
  1748. type: "bar"
  1749. });
  1750. /**
  1751. * @class Ext.chart.PieSeries
  1752. * @extends Ext.chart.Series
  1753. * PieSeries class for the charts widget.
  1754. * @constructor
  1755. */
  1756. Ext.chart.PieSeries = Ext.extend(Ext.chart.Series, {
  1757. type: "pie",
  1758. dataField: null,
  1759. categoryField: null
  1760. });