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