t.u to tiny, which can convert an URL-String to an Objekt similar to location, with some added value.
tiny-url.js [1655b] - tiny-url-min.js.gz [508b]
The t.u-Method requires only tiny.js. Other scripts are not necessary.
The function t.u('[URL]') returns an Object with helpful instances and the Method .toString(). The instances are as follows:
| href | Full URL |
|---|---|
| protocol | URL-Protocol, e.g. 'http:' |
| hostname | Hostname (FQDN), e.g. 'tinyjs.sourceforge.net' |
| base | '//'+hostname |
| port | Port of the TCP connection (if not :80), e.g. 8080 |
| pathname | path including filename, e.g. '/index-en.html' |
| search | GET-Parameters-String with prefixing '?', e.g. '?test=true' |
| hash | Hash-Parameter of an page-internal link |
| params | An Object with all GET-Parameters |
If called without parameters, t.u() uses location.href as URL. Within the function, the instances of location.href are available (including params), so t.u().hostname === t.u.hostname.
The URL Object has a toString-Method, which is somewhat different from usual toString. It takes zero or one Arguments. Without arguments, it returns an absolute URL, if the first argument is false, it returns a relative URL. If the first argument is an URL, it returns an absolute URL using the argument as base.
| href | |
|---|---|
| protocol | |
| hostname | |
| base | |
| port | |
| pathname | |
| search | |
| hash | |
| params |
t('#example td').i(function(k, v) {
if (t.u[v.id]) { v.innerHTML = JSON.stringify(t.u[v.id]); }
});
© 2010 Alex Kloss