Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zaus/5201739 to your computer and use it in GitHub Desktop.
Save zaus/5201739 to your computer and use it in GitHub Desktop.

Revisions

  1. zaus revised this gist Mar 20, 2013. 1 changed file with 12 additions and 22 deletions.
    34 changes: 12 additions & 22 deletions parse-hash-bang-arguments-in-javascript.js
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,22 @@
    /**
    * Parse hash bang parameters from a URL as key value object.
    *
    * For repeated parameters the last parameter is effective.
    *
    * If = syntax is not used the value is set to null.
    *
    * #x&y=3 -> { x:null, y:3 }
    *
    * @param aURL URL to parse or null if window.location is used
    *
    * #!x&y=3 -> { x:null, y:3 }
    * @param url URL to parse or null if window.location is used
    * @return Object of key -> value mappings.
    * @source https://gist.github.com/zaus/5201739
    */
    function parseHashBangArgs(aURL) {
    function hashbang(url, i, hash) {
    url = url || window.location.href;

    aURL = aURL || window.location.href;

    var vars = {};
    var hashes = aURL.slice(aURL.indexOf('#') + 1).split('&');
    var vars = {}, hashes = url.slice(url.indexOf('#!') + 2).split('&');

    for(var i = 0; i < hashes.length; i++) {
    var hash = hashes[i].split('=');

    if(hash.length > 1) {
    vars[hash[0]] = hash[1];
    } else {
    vars[hash[0]] = null;
    }
    }
    for(i = hashes.length; i--;) {
    hash = hashes[i].split('=');

    return vars;
    vars[hash[0]] = hash.length > 1 ? hash[1] : null;
    }

    return vars;
    }
  2. @miohtama miohtama renamed this gist Jan 6, 2012. 1 changed file with 0 additions and 0 deletions.
  3. @miohtama miohtama renamed this gist Jan 6, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @miohtama miohtama created this gist Jan 6, 2012.
    32 changes: 32 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    /**
    * Parse hash bang parameters from a URL as key value object.
    *
    * For repeated parameters the last parameter is effective.
    *
    * If = syntax is not used the value is set to null.
    *
    * #x&y=3 -> { x:null, y:3 }
    *
    * @param aURL URL to parse or null if window.location is used
    *
    * @return Object of key -> value mappings.
    */
    function parseHashBangArgs(aURL) {

    aURL = aURL || window.location.href;

    var vars = {};
    var hashes = aURL.slice(aURL.indexOf('#') + 1).split('&');

    for(var i = 0; i < hashes.length; i++) {
    var hash = hashes[i].split('=');

    if(hash.length > 1) {
    vars[hash[0]] = hash[1];
    } else {
    vars[hash[0]] = null;
    }
    }

    return vars;
    }