From 4b043a5cd5e02884cd238d98223ae8b26112460e Mon Sep 17 00:00:00 2001 From: Kerrick Long Date: Mon, 18 Jul 2011 12:32:30 -0500 Subject: [PATCH] Added parseURL. --- js/common.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/js/common.js b/js/common.js index e963e21..fba45b2 100644 --- a/js/common.js +++ b/js/common.js @@ -69,6 +69,41 @@ MHUtils.prototype.forEach = function (array, action) { return true; } +/** + * Parses a URL and returns a useful object. http://james.padolsey.com/javascript/parsing-urls-with-the-dom/ + * @alias MHUtils.parseURL(url) + * @param {String} url A string with a full URL to be parsed. + * @return {Object} Returns a URL object. + * @method + */ +MHUtils.prototype.parseURL = function (url) { + var a = document.createElement('a'); + a.href = url; + return { + source: url, + protocol: a.protocol.replace(':',''), + host: a.hostname, + port: a.port, + query: a.search, + params: (function(){ + var ret = {}, + seg = a.search.replace(/^\?/,'').split('&'), + len = seg.length, i = 0, s; + for (;i