Created
May 10, 2011 11:45
-
-
Save joshnesbitt/964322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function HostInformation(target, opts){ | |
| var opts = opts || {}, | |
| output = {}, | |
| target = target.location || target; | |
| this.host = function() | |
| { | |
| return target.host; | |
| } | |
| this.fullHost = function() | |
| { | |
| return this.protocol() + "//" + this.host(); | |
| } | |
| this.path = function() | |
| { | |
| return target.pathname; | |
| } | |
| this.protocol = function() | |
| { | |
| return target.protocol; | |
| } | |
| this.port = function() | |
| { | |
| return target.port || "8080" | |
| } | |
| this.hash = function() | |
| { | |
| return target.hash.replace('#', ''); | |
| } | |
| this.query = function() | |
| { | |
| var q = target.search.replace('?', ''); | |
| if(q === '') | |
| return {}; | |
| var obj = {}, | |
| parts = q.split('&'); | |
| for(i in parts){ | |
| if(typeof parts[i] === 'string'){ | |
| o = parts[i].split("="); | |
| obj[o[0]] = o[1]; | |
| } | |
| } | |
| return obj; | |
| } | |
| this.subdomain = function() | |
| { | |
| return this.host().split(".")[0]; | |
| } | |
| for(key in this) | |
| if(typeof this[key] === 'function') | |
| output[key] = this[key](); | |
| return output; | |
| } | |
| var info = new HostInformation(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment