Sha256: 0dae420e547b9d506dc478cd35c33c0a5cd520887b94bf63db55314216402f19

Contents?: true

Size: 1.24 KB

Versions: 28

Compression:

Stored size: 1.24 KB

Contents

//parse a URL to form an object of properties
function parseURL(url)
{
    //save the unmodified url to href property
    //so that the object we get back contains
    //all the same properties as the built-in location object
    var loc = { 'href' : url };

    //split the URL by single-slashes to get the component parts
    var parts = url.replace('//', '/').split('/');

    //store the protocol and host
    loc.protocol = parts[0];
    loc.host = parts[1];

    //extract any port number from the host
    //from which we derive the port and hostname
    parts[1] = parts[1].split(':');
    loc.hostname = parts[1][0];
    loc.port = parts[1].length > 1 ? parts[1][1] : '';

    //splice and join the remainder to get the pathname
    parts.splice(0, 2);
    loc.pathname = '/' + parts.join('/');

    //extract any hash and remove from the pathname
    loc.pathname = loc.pathname.split('#');
    loc.hash = loc.pathname.length > 1 ? '#' + loc.pathname[1] : '';
    loc.pathname = loc.pathname[0];

    //extract any search query and remove from the pathname
    loc.pathname = loc.pathname.split('?');
    loc.search = loc.pathname.length > 1 ? '?' + loc.pathname[1] : '';
    loc.pathname = loc.pathname[0];

    //return the final object
    return loc;
}

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
refinerycms-0.9.5.13 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.12 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.11 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.10 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.9 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.8 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.7 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.6 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.5 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.4 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.3 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.2 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5.1 public/javascripts/refinery/parse_url.js
refinerycms-0.9.5 public/javascripts/refinery/parse_url.js
refinerycms-0.9.4.5 public/javascripts/parse_url.js
refinerycms-0.9.4.4 public/javascripts/parse_url.js
refinerycms-0.9.4.3 public/javascripts/parse_url.js
refinerycms-0.9.4.2 public/javascripts/parse_url.js
refinerycms-0.9.4.1 public/javascripts/parse_url.js
refinerycms-0.9.4 public/javascripts/parse_url.js