Documenting isSameDomain(), isRelativeUrl(), isAbsoluteUrl(), makePathAbsolute(), and makeUrlAbsolute().

This commit is contained in:
Kin Blas 2011-06-17 18:22:00 -07:00
parent 849c533839
commit 9f4ae3ba79

View file

@ -21,7 +21,7 @@
<div data-role="content">
<p>jQuery Mobile exposes several methods and properties on the $.mobile object for use in your applications.</p>
<p>jQuery Mobile exposes several methods and properties on the $.mobile object for use in your applications.</p>
<dl>
@ -244,8 +244,8 @@ $.mobile.hidePageLoadingMsg();
<strong>// Parsing the Url below results an object that is returned with the
// following properties:
//
// obj.href: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content
// obj.hrefNoHash: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread
// obj.href: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&amp;type=unread#msg-content
// obj.hrefNoHash: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&amp;type=unread
// obj.hrefNoSearch: http://jblas:password@mycompany.com:8080/mail/inbox
// obj.domain: http://jblas:password@mycompany.com:8080
// obj.protocol: http:
@ -258,7 +258,7 @@ $.mobile.hidePageLoadingMsg();
// obj.pathname: /mail/inbox
// obj.directory: /mail/
// obj.filename: inbox
// obj.search: ?msg=1234&type=unread
// obj.search: ?msg=1234&amp;type=unread
// obj.hash: #msg-content</strong>
var obj = $.mobile.path.parseUrl("http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234");
@ -268,6 +268,188 @@ var obj = $.mobile.path.parseUrl("http://jblas:password@mycompany.com:8080/mail/
</dd>
<dt><code>$.mobile.path.makePathAbsolute</code> (<em>method</em>)</dt>
<dd>Utility method for converting a relative file or directory path into an absolute path.</dd>
<dd>
<dl>
<dt>Arguments</dt>
<dd><code>relPath</code> (<em>string</em>, required) A relative file or directory path.</dd>
<dd><code>absPath</code> (<em>string</em>, required) An absolute file or relative path to resolve against.</dd>
<dt>Return Value</dt>
<dd>This function returns a string that is an absolute version of the relative path passed in.</dd>
</dl>
</dd>
<dd>Examples:
<pre>
<code>
<strong>// Returns: /a/b/c/file.html</strong>
var absPath = $.mobile.path.makePathAbsolute("file.html", "/a/b/c/bar.html");
<strong>// Returns: /a/foo/file.html</strong>
var absPath = $.mobile.path.makePathAbsolute("../../foo/file.html", "/a/b/c/bar.html");
</code>
</pre>
</dd>
<dt><code>$.mobile.path.makeUrlAbsolute</code> (<em>method</em>)</dt>
<dd>Utility method for converting a relative URL to an absolute URL.</dd>
<dd>
<dl>
<dt>Arguments</dt>
<dd><code>relUrl</code> (<em>string</em>, required) A relative URL.</dd>
<dd><code>absUrl</code> (<em>string</em>, required) An absolute URL to resolve against.</dd>
<dt>Return Value</dt>
<dd>This function returns a string that is an absolute version of the relative URL passed in.</dd>
</dl>
</dd>
<dd>Examples:
<pre>
<code>
<strong>// Returns: http://foo.com/a/b/c/file.html</strong>
var absUrl = $.mobile.path.makeUrlAbsolute("file.html", "http://foo.com/a/b/c/test.html");
<strong>// Returns: http://foo.com/a/foo/file.html</strong>
var absUrl = $.mobile.path.makeUrlAbsolute("../../foo/file.html", "http://foo.com/a/b/c/test.html");
<strong>// Returns: http://foo.com/bar/file.html</strong>
var absUrl = $.mobile.path.makeUrlAbsolute("//foo.com/bar/file.html", "http://foo.com/a/b/c/test.html");
<strong>// Returns: http://foo.com/a/b/c/test.html?a=1&amp;b=2</strong>
var absUrl = $.mobile.path.makeUrlAbsolute("?a=1&amp;b=2", "http://foo.com/a/b/c/test.html");
<strong>// Returns: http://foo.com/a/b/c/test.html#bar</strong>
var absUrl = $.mobile.path.makeUrlAbsolute("#bar", "http://foo.com/a/b/c/test.html");
</code>
</pre>
</dd>
<dt><code>$.mobile.path.isSameDomain</code> (<em>method</em>)</dt>
<dd>Utility method for comparing the domain of 2 URLs.</dd>
<dd>
<dl>
<dt>Arguments</dt>
<dd><code>url1</code> (<em>string</em>, required) A relative URL.</dd>
<dd><code>url2</code> (<em>string</em>, required) An absolute URL to resolve against.</dd>
<dt>Return Value</dt>
<dd>This function returns a boolean true if the domains match, false if they don't.</dd>
</dl>
</dd>
<dd>Examples:
<pre>
<code>
<strong>// Returns: true</strong>
var same = $.mobile.path.isSameDomain("http://foo.com/a/file.html", "http://foo.com/a/b/c/test.html");
<strong>// Returns: false</strong>
var same = $.mobile.path.isSameDomain("file://foo.com/a/file.html", "http://foo.com/a/b/c/test.html");
<strong>// Returns: false</strong>
var same = $.mobile.path.isSameDomain("https://foo.com/a/file.html", "http://foo.com/a/b/c/test.html");
<strong>// Returns: false</strong>
var same = $.mobile.path.isSameDomain("http://foo.com/a/file.html", "http://bar.com/a/b/c/test.html");
</code>
</pre>
</dd>
<dt><code>$.mobile.path.isRelativeUrl</code> (<em>method</em>)</dt>
<dd>Utility method for determining if a URL is a relative variant.</dd>
<dd>
<dl>
<dt>Arguments</dt>
<dd><code>url</code> (<em>string</em>, required) A relative or absolute URL.</dd>
<dt>Return Value</dt>
<dd>This function returns a boolean true if the URL is relative, false if it is absolute.</dd>
</dl>
</dd>
<dd>Examples:
<pre>
<code>
<strong>// Returns: false</strong>
var isRel = $.mobile.path.isRelativeUrl("http://foo.com/a/file.html");
<strong>// Returns: true</strong>
var isRel = $.mobile.path.isRelativeUrl("//foo.com/a/file.html");
<strong>// Returns: true</strong>
var isRel = $.mobile.path.isRelativeUrl("/a/file.html");
<strong>// Returns: true</strong>
var isRel = $.mobile.path.isRelativeUrl("file.html");
<strong>// Returns: true</strong>
var isRel = $.mobile.path.isRelativeUrl("?a=1&amp;b=2");
<strong>// Returns: true</strong>
var isRel = $.mobile.path.isRelativeUrl("#foo");
</code>
</pre>
</dd>
<dt><code>$.mobile.path.isAbsoluteUrl</code> (<em>method</em>)</dt>
<dd>Utility method for determining if a URL is absolute.</dd>
<dd>
<dl>
<dt>Arguments</dt>
<dd><code>url</code> (<em>string</em>, required) A relative or absolute URL.</dd>
<dt>Return Value</dt>
<dd>This function returns a boolean true if the URL is absolute, false if it is absolute.</dd>
</dl>
</dd>
<dd>Examples:
<pre>
<code>
<strong>// Returns: true</strong>
var isAbs = $.mobile.path.isAbsoluteUrl("http://foo.com/a/file.html");
<strong>// Returns: false</strong>
var isAbs = $.mobile.path.isAbsoluteUrl("//foo.com/a/file.html");
<strong>// Returns: false</strong>
var isAbs = $.mobile.path.isAbsoluteUrl("/a/file.html");
<strong>// Returns: false</strong>
var isAbs = $.mobile.path.isAbsoluteUrl("file.html");
<strong>// Returns: false</strong>
var isAbs = $.mobile.path.isAbsoluteUrl("?a=1&amp;b=2");
<strong>// Returns: false</strong>
var isAbs = $.mobile.path.isAbsoluteUrl("#foo");
</code>
</pre>
</dd>
<dt><code>$.mobile.base</code> (<em>methods, properties</em>)</dt>
<dd>Utilities for working with generated base element. TODO: document as public API is finalized.</dd>