From 1354d17270961fff662d40f90521223f8fd0d73b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 14 Aug 2012 18:59:10 +0400 Subject: update dojo to 1.7.3 --- lib/dojo/io-query.js.uncompressed.js | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 lib/dojo/io-query.js.uncompressed.js (limited to 'lib/dojo/io-query.js.uncompressed.js') diff --git a/lib/dojo/io-query.js.uncompressed.js b/lib/dojo/io-query.js.uncompressed.js new file mode 100644 index 000000000..a5799bfc2 --- /dev/null +++ b/lib/dojo/io-query.js.uncompressed.js @@ -0,0 +1,98 @@ +define("dojo/io-query", ["./_base/lang"], function(lang){ + // module: + // dojo/io-query + // summary: + // This module defines query string processing functions. + + var backstop = {}; + + function objectToQuery(/*Object*/ map){ + // summary: + // takes a name/value mapping object and returns a string representing + // a URL-encoded version of that object. + // example: + // this object: + // + // | { + // | blah: "blah", + // | multi: [ + // | "thud", + // | "thonk" + // | ] + // | }; + // + // yields the following query string: + // + // | "blah=blah&multi=thud&multi=thonk" + + // FIXME: need to implement encodeAscii!! + var enc = encodeURIComponent, pairs = []; + for(var name in map){ + var value = map[name]; + if(value != backstop[name]){ + var assign = enc(name) + "="; + if(lang.isArray(value)){ + for(var i = 0, l = value.length; i < l; ++i){ + pairs.push(assign + enc(value[i])); + } + }else{ + pairs.push(assign + enc(value)); + } + } + } + return pairs.join("&"); // String + } + + function queryToObject(/*String*/ str){ + // summary: + // Create an object representing a de-serialized query section of a + // URL. Query keys with multiple values are returned in an array. + // + // example: + // This string: + // + // | "foo=bar&foo=baz&thinger=%20spaces%20=blah&zonk=blarg&" + // + // results in this object structure: + // + // | { + // | foo: [ "bar", "baz" ], + // | thinger: " spaces =blah", + // | zonk: "blarg" + // | } + // + // Note that spaces and other urlencoded entities are correctly + // handled. + + // FIXME: should we grab the URL string if we're not passed one? + var dec = decodeURIComponent, qp = str.split("&"), ret = {}, name, val; + for(var i = 0, l = qp.length, item; i < l; ++i){ + item = qp[i]; + if(item.length){ + var s = item.indexOf("="); + if(s < 0){ + name = dec(item); + val = ""; + }else{ + name = dec(item.slice(0, s)); + val = dec(item.slice(s + 1)); + } + if(typeof ret[name] == "string"){ // inline'd type check + ret[name] = [ret[name]]; + } + + if(lang.isArray(ret[name])){ + ret[name].push(val); + }else{ + ret[name] = val; + } + } + } + return ret; // Object + } + + return { + objectToQuery: objectToQuery, + queryToObject: queryToObject + }; +}); \ No newline at end of file -- cgit v1.2.3