Hello fellow MooTools users,

In the new MooTools More RC1 there's a Uri class which introduces some
great Uri functionality. I've done a few of those myself and I'm sure
alot of you have done so too. Since URIs are such an important part of
web development it is likely to appear in many different places
(namespaces, hyperlinks, document serialization, handling relative
paths etc.). A common approach might be in order. I'd like to initiate
some discussion about various features and uses for such a class.

You can find my suggestion at our SVN at: http://clientside.svn.calyptus.se/

Code file:
http://clientside.svn.calyptus.se/JavaScript/Native/Uri.js

Specs:
http://clientside.svn.calyptus.se/Tests/Native/Uri.js

The use for this are as follows:

Constructors:

new Uri() - The URI of the current document base uri (i.e. <base
href="..." /> or window.location).
new Uri(uri) - The URI parsed from the string.
new Uri(uri, '../relative/uri') - The URI of the fullUri + the
relative Uri.

The Uri has different values depending on the scheme used.
For example a http:// uri has the following values:
scheme, href, protocol, user, password, hostname, port, directory,
pathname, file, search, hash

A mailto: uri has the following values:
scheme, href, email, username, hostname, headers, subject, body

If the scheme supports it, you can get the relative or absolute Uri
using this syntax:
uri.toAbsolute(baseUri) - The absolute path to uri from baseUri for
example: /group/mootools-users/
uri.toRelative(baseUri) - The relative path to uri from baseUri for
example: ../mootools-users/

Example:
new Uri('http://groups.google.com/', '/group/mootools-
users/').toRelative('http://groups.google.com/group/othergroup/')
returns: '../mootools-users/'

This makes this class very useful to convert various Uri:s to and from
relative paths. It's also extensible to support other schemes. But
IMHO, it also makes a good base for other functionality found in the
new MooTools More URI class.

Thoughts?

What other uses are out there for Uri handling?

Reply via email to