flashVars.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.embed.flashVars"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.embed.flashVars"] = true;
  8. dojo.provide("dojox.embed.flashVars");
  9. dojo.mixin(dojox.embed.flashVars, {
  10. // summary
  11. // Handles flashvar serialization
  12. // Converting complex objects into a simple, clear string that can be appended
  13. // to the swf as a query: myMovie.swf?flashvars=foo.
  14. // Note this needs to work with the SWF, which must know what variables to expect.
  15. // Therefore this is something of an "internal" class - unless you know how to
  16. // modify or create SWFs.
  17. //
  18. // description:
  19. // JSON could be done, but Deft does not yet have a JSON parser, and quotes are
  20. // very problematic since Flash cannot use eval(); JSON parsing was successful
  21. // when it was fully escaped, but that made it very large anyway. flashvar
  22. // serialization at most is 200% larger than JSON.
  23. //
  24. // See:
  25. // Deft/common/flashVars.as
  26. //
  27. serialize: function(/* String */n, /*Object*/o){
  28. // summary:
  29. // Key method. Serializes an object.
  30. // n:String
  31. // The name for the object, such as: "button"
  32. // o:Object
  33. // The object to serialize
  34. //
  35. var esc = function(val){
  36. // have to encode certain characters that indicate an object
  37. if(typeof val=="string"){
  38. val = val.replace(/;/g,"_sc_");
  39. val = val.replace(/\./g,"_pr_");
  40. val = val.replace(/\:/g,"_cl_");
  41. //val = escape(val);
  42. }
  43. return val;
  44. };
  45. var df = dojox.embed.flashVars.serialize;
  46. var txt = "";
  47. if(dojo.isArray(o)){
  48. for(var i=0;i<o.length;i++){
  49. txt += df(n+"."+i, esc(o[i]))+";";
  50. }
  51. return txt.replace(/;{2,}/g,";");
  52. }else if(dojo.isObject(o)){
  53. for(var nm in o){
  54. txt += df(n+"."+nm, esc(o[nm]))+";";
  55. }
  56. return txt.replace(/;{2,}/g,";");
  57. }
  58. // Dev note: important that there is no double semi-colons
  59. return n+":"+o; // String
  60. }
  61. });
  62. }