Pass a string to the URI subclass and it will extend it, returning a new string-like object with new methods useful for managing that URI.
Syntax
new URI([strURI, options]);
Arguments
strURI - (string) the URI to parse into the class.
options - (object) a key/value set of options.
Options
base - (mixed) A base href for the URI (defaults to the document base location). Can be a string or an instance of URI. This is used to interpret relative urls (for instance if you were to call new URI('/foo/bar.html') the class will infer that this path is relative to the current document base location).
Example
var myURI = new URI('http://user:password@www.test.com:8383/the/path.html?query=value#anchor');
Returns
URI - (string; optional) - an instance of the URI class that has new methods useful for managing the URI. If not declared the window's current base location is used.
Sets the query string from an object (much like myURI.set('data', obj)) but also allows merging.
Syntax
myURI.setData(data[, merge, part]);
Arguments
object - (object) the key/values you want to set for the query string
merge - (boolean, optional) if true the values will be merged with the existing query string. Defaults to false.
part - (string, optional) this defaults to 'query' for setting query string data to the URI, but you could, for example specify 'fragment' to assign query string data to the '#...' portion of the URI (which is useful in ajax applications that wish to store state in the URI without reloading the document).
Alternate Syntax
myURI.setData(key, value);
Alternate Syntax Arguments
key - (string) the key of the data which you wish to assign
value - (string or number) the value you wish to assign
Returns
(URI) this instance of URI
Example
myURI.setData(myObject); //same as myURI.set('data', myObject);
myURI.setData(myObject, true); //merges myObject w/ existing query values
myURI.setData('foo', 'bar'); //sets foo=bar in the query string
myURI.setData({foo: 'bar'}, false, 'fragment'); //adds #foo=bar to the url fragment
Returns the query string values as an object. Same as URI.get('data').
Syntax
myURI.getData([key, part]);
Arguments
key - (string; optional) If specified, returns the value for the given key.
part - (string; optional) If specified, returns the data from the given part (defaults to 'query'). This is useful if you choose to store data in the fragment (the '#...' part of the URI) which is useful in ajax applications that wish to store state in the URI without reloading the document.
Returns
mixed - the string value for the given key; if key is not specified, returns an object for all the query string values.