Skip to content

Commit d09ad5d

Browse files
author
Nova
committed
Cleaned up code (Under 1Kb minified)
1 parent ce1fce9 commit d09ad5d

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Websanova $.uri()</title>
66

77
<script type="text/javascript" src="./inc/jquery.1.8.2.min.js"></script>
8-
<script type="text/javascript" src="./jquery-uri.js"></script>
8+
<script type="text/javascript" src="./jquery-uri.min.js"></script>
99

1010
<script type="text/javascript">
1111

jquery-uri.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,34 @@
88
* @license This websanova jQuery boilerplate is dual licensed under the MIT and GPL licenses.
99
* @link http://www.websanova.com
1010
* @github http://github.com/websanova/jquery-uri
11-
* @version 1.2.0
11+
* @version 1.3.0
1212
*
1313
******************************************/
1414

1515
jQuery.extend(
1616
{
1717
uri: function(arg)
1818
{
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] || '';
4136
else if(arg[0] === '?' || arg[0] === '#')
4237
{
43-
var params = window.location.toString(), param = null;
38+
var params = _ls, param = null;
4439

4540
if(arg[0] === '?') params = (params.split('?')[1] || '').split('#')[0];
4641
else if(arg[0] === '#') params = (params.split('#')[1] || '');

jquery-uri.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)