comparison static/QueryString.js @ 1041:a4632a7b2e17

upgrade knockout and jquery, simplify the static/ dirs for all web services Ignore-this: 8637b7b61cc5d38e8cf15bb1afd7466c
author Drew Perttula <drewp@bigasterisk.com>
date Wed, 28 May 2014 05:54:23 +0000
parents
children
comparison
equal deleted inserted replaced
1040:b65995e32a23 1041:a4632a7b2e17
1 // This is public domain code written in 2011 by Jan Wolter and distributed
2 // for free at http://unixpapa.com/js/querystring.html
3 //
4 // Query String Parser
5 //
6 // qs= new QueryString()
7 // qs= new QueryString(string)
8 //
9 // Create a query string object based on the given query string. If
10 // no string is given, we use the one from the current page by default.
11 //
12 // qs.value(key)
13 //
14 // Return a value for the named key. If the key was not defined,
15 // it will return undefined. If the key was multiply defined it will
16 // return the last value set. If it was defined without a value, it
17 // will return an empty string.
18 //
19 // qs.values(key)
20 //
21 // Return an array of values for the named key. If the key was not
22 // defined, an empty array will be returned. If the key was multiply
23 // defined, the values will be given in the order they appeared on
24 // in the query string.
25 //
26 // qs.keys()
27 //
28 // Return an array of unique keys in the query string. The order will
29 // not necessarily be the same as in the original query, and repeated
30 // keys will only be listed once.
31 //
32 // QueryString.decode(string)
33 //
34 // This static method is an error tolerant version of the builtin
35 // function decodeURIComponent(), modified to also change pluses into
36 // spaces, so that it is suitable for query string decoding. You
37 // shouldn't usually need to call this yourself as the value(),
38 // values(), and keys() methods already decode everything they return.
39 //
40 // Note: W3C recommends that ; be accepted as an alternative to & for
41 // separating query string fields. To support that, simply insert a semicolon
42 // immediately after each ampersand in the regular expression in the first
43 // function below.
44
45 function QueryString(qs)
46 {
47 this.dict= {};
48
49 // If no query string was passed in use the one from the current page
50 if (!qs) qs= location.search;
51
52 // Delete leading question mark, if there is one
53 if (qs.charAt(0) == '?') qs= qs.substring(1);
54
55 // Parse it
56 var re= /([^=&]+)(=([^&]*))?/g;
57 while (match= re.exec(qs))
58 {
59 var key= decodeURIComponent(match[1].replace(/\+/g,' '));
60 var value= match[3] ? QueryString.decode(match[3]) : '';
61 if (this.dict[key])
62 this.dict[key].push(value);
63 else
64 this.dict[key]= [value];
65 }
66 }
67
68 QueryString.decode= function(s)
69 {
70 s= s.replace(/\+/g,' ');
71 s= s.replace(/%([EF][0-9A-F])%([89AB][0-9A-F])%([89AB][0-9A-F])/gi,
72 function(code,hex1,hex2,hex3)
73 {
74 var n1= parseInt(hex1,16)-0xE0;
75 var n2= parseInt(hex2,16)-0x80;
76 if (n1 == 0 && n2 < 32) return code;
77 var n3= parseInt(hex3,16)-0x80;
78 var n= (n1<<12) + (n2<<6) + n3;
79 if (n > 0xFFFF) return code;
80 return String.fromCharCode(n);
81 });
82 s= s.replace(/%([CD][0-9A-F])%([89AB][0-9A-F])/gi,
83 function(code,hex1,hex2)
84 {
85 var n1= parseInt(hex1,16)-0xC0;
86 if (n1 < 2) return code;
87 var n2= parseInt(hex2,16)-0x80;
88 return String.fromCharCode((n1<<6)+n2);
89 });
90 s= s.replace(/%([0-7][0-9A-F])/gi,
91 function(code,hex)
92 {
93 return String.fromCharCode(parseInt(hex,16));
94 });
95 return s;
96 };
97
98 QueryString.prototype.value= function (key)
99 {
100 var a= this.dict[key];
101 return a ? a[a.length-1] : undefined;
102 };
103
104 QueryString.prototype.values= function (key)
105 {
106 var a= this.dict[key];
107 return a ? a : [];
108 };
109
110 QueryString.prototype.keys= function ()
111 {
112 var a= [];
113 for (var key in this.dict)
114 a.push(key);
115 return a;
116 };