annotate querystring.js @ 93:817aa2851339 default tip

Added a very simple index.html.
author Atul Varma <varmaa@toolness.com>
date Fri, 23 May 2008 03:50:44 -0700
parents 19c686bef710
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
1 /* Client-side access to querystring name=value pairs
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
2 Version 1.2.4
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3 30 March 2008
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
4 Adam Vandenberg
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
5 */
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
6 function Querystring(qs) { // optionally pass a querystring to parse
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
7 this.params = {};
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8 this.get=Querystring_get;
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
9
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
10 if (qs == null);
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
11 qs=location.search.substring(1,location.search.length);
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
12
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
13 if (qs.length == 0)
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 return;
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16 // Turn <plus> back to <space>
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17 // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18 qs = qs.replace(/\+/g, ' ');
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
19 var args = qs.split('&'); // parse out name/value pairs separated via &
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
20
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
21 // split out each name=value pair
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
22 for (var i=0;i<args.length;i++) {
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
23 var pair = args[i].split('=');
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
24 var name = unescape(pair[0]);
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
25
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
26 var value = (pair.length==2)
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
27 ? unescape(pair[1])
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
28 : name;
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
29
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
30 this.params[name] = value;
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
31 }
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
32 }
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
33
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
34 function Querystring_get(key, default_) {
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
35 var value=this.params[key];
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
36 return (value!=null) ? value : default_;
19c686bef710 The app now optionally takes a querystring param of 'story', which points to a z-code file of a story to load. If none is given, troll is loaded.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
37 }