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