|
8 | 8 | * @license This websanova jQuery boilerplate is dual licensed under the MIT and GPL licenses.
|
9 | 9 | * @link http://www.websanova.com
|
10 | 10 | * @github http://github.com/websanova/jquery-uri
|
11 |
| - * @version 1.2.0 |
| 11 | + * @version 1.3.0 |
12 | 12 | *
|
13 | 13 | ******************************************/
|
14 | 14 |
|
15 | 15 | jQuery.extend(
|
16 | 16 | {
|
17 | 17 | uri: function(arg)
|
18 | 18 | {
|
19 |
| - if(!arg) return window.location.toString(); |
20 |
| - else if(arg === 'domain') return window.location.hostname; |
21 |
| - else if(arg === 'host') return window.location.hostname.split('.').slice(-2).join('.'); |
22 |
| - else if(arg === 'tld') return window.location.hostname.split('.').slice(-1).join('.'); |
23 |
| - else if(arg === 'sub') |
24 |
| - { |
25 |
| - var domain = window.location.hostname.split('.'); |
26 |
| - |
27 |
| - if(domain.length < 3) return ''; |
28 |
| - else return domain.slice(0, domain.length - 2).join('.'); |
29 |
| - } |
30 |
| - else if(arg === 'path') return window.location.pathname; |
31 |
| - else if($.isNumeric(arg)) |
32 |
| - { |
33 |
| - var path = window.location.pathname.split('/'); |
34 |
| - |
35 |
| - arg = parseInt(arg); |
36 |
| - return path[arg < 0 ? path.length + arg : arg] || ''; |
37 |
| - } |
38 |
| - else if(arg === 'file') return window.location.pathname.split('/').slice(-1); |
39 |
| - else if(arg === 'filename') return window.location.pathname.split('/').slice(-1)[0].split('.')[0]; |
40 |
| - else if(arg === 'fileext') return window.location.pathname.split('/').slice(-1)[0].split('.')[1] || ''; |
| 19 | + var _l = window.location, |
| 20 | + _ls = _l.toString(), |
| 21 | + _h = _l.hostname, |
| 22 | + _hs = _h.split('.'), |
| 23 | + _p = _l.pathname, |
| 24 | + _ps = _p.split('/'); |
| 25 | + |
| 26 | + if(!arg) return _ls; |
| 27 | + else if(arg === 'domain') return _h; |
| 28 | + else if(arg === 'host') return _hs.slice(-2).join('.'); |
| 29 | + else if(arg === 'tld') return _hs.slice(-1).join('.'); |
| 30 | + else if(arg === 'sub') return _hs.slice(0, _hs.length - 2).join('.'); |
| 31 | + else if(arg === 'path') return _p; |
| 32 | + else if($.isNumeric(arg)){ arg = parseInt(arg); return _ps[arg < 0 ? _ps.length + arg : arg] || ''; } |
| 33 | + else if(arg === 'file') return _ps.slice(-1); |
| 34 | + else if(arg === 'filename') return _ps.slice(-1)[0].split('.')[0]; |
| 35 | + else if(arg === 'fileext') return _ps.slice(-1)[0].split('.')[1] || ''; |
41 | 36 | else if(arg[0] === '?' || arg[0] === '#')
|
42 | 37 | {
|
43 |
| - var params = window.location.toString(), param = null; |
| 38 | + var params = _ls, param = null; |
44 | 39 |
|
45 | 40 | if(arg[0] === '?') params = (params.split('?')[1] || '').split('#')[0];
|
46 | 41 | else if(arg[0] === '#') params = (params.split('#')[1] || '');
|
|
0 commit comments