Methods
-
<static> parts( url ) → {FooGallery.utils.url~Parts}
Parses the supplied url into an object containing it's component parts.
-
Parameters
Name Type Description url
string The url to parse.
Returns
Examples
// alias the FooGallery.utils.url namespace var _url = FooGallery.utils.url; console.log( _url.parts( "http://example.com/path/?param=true#something" ) ); // => {"hash":"#something", ...}
Details
-
<static> full( url ) → {string}
Given a
url
that could be relative or full this ensures a full url is returned. -
Description
Given a full url this will simply return it however if given a relative url this will create a full url using the current location to fill in the blanks.
Parameters
Name Type Description url
string The url to ensure is full.
Returns
Examples
// alias the FooGallery.utils.url namespace var _url = FooGallery.utils.url; console.log( _url.full( "http://example.com/path/" ) ); // => "http://example.com/path/" console.log( _url.full( "/path/" ) ); // => "{protocol}//{host}/path/" console.log( _url.full( "path/" ) ); // => "{protocol}//{host}/{pathname}/path/" console.log( _url.full( "../path/" ) ); // => "{protocol}//{host}/{calculated pathname}/path/" console.log( _url.full() ); // => null console.log( _url.full( 123 ) ); // => null
Details
-
<static> param( search, key [, value ] ) → {string}
Gets or sets a parameter in the given
search
string. -
Parameters
Name Type Attributes Description search
string The search string to use (usually
location.search
).key
string The key of the parameter.
value
string <optional> The value to set for the parameter. If not provided the current value for the
key
is returned.Returns
Examples
// alias the FooGallery.utils.url namespace var _url = FooGallery.utils.url, // create a search string to test search = "?wmode=opaque&autoplay=1"; console.log( _url.param( search, "wmode" ) ); // => "opaque" console.log( _url.param( search, "autoplay" ) ); // => "1" console.log( _url.param( search, "nonexistent" ) ); // => null
// alias the FooGallery.utils.url namespace var _url = FooGallery.utils.url, // create a search string to test search = "?wmode=opaque&autoplay=1"; console.log( _url.param( search, "wmode", "window" ) ); // => "?wmode=window&autoplay=1" console.log( _url.param( search, "autoplay", "0" ) ); // => "?wmode=opaque&autoplay=0" console.log( _url.param( search, "v", "2" ) ); // => "?wmode=opaque&autoplay=1&v=2"
Details
Type Definitions
-
Parts
A plain JavaScript object returned by the FooGallery.utils.url.parts method.
-
Properties
Name Type Description hash
string A string containing a
#
followed by the fragment identifier of the URL.host
string A string containing the host, that is the hostname, a
:
, and the port of the URL.hostname
string A string containing the domain of the URL.
href
string A string containing the entire URL.
origin
string A string containing the canonical form of the origin of the specific location.
pathname
string A string containing an initial
/
followed by the path of the URL.port
string A string containing the port number of the URL.
protocol
string A string containing the protocol scheme of the URL, including the final
:
.search
string A string containing a
?
followed by the parameters of the URL. Also known as "querystring".Details