Skip to content

Commit

Permalink
Cleaned up code (Under 1Kb minified)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nova committed Oct 27, 2012
1 parent ce1fce9 commit d09ad5d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -5,7 +5,7 @@
<title>Websanova $.uri()</title>

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

<script type="text/javascript">

Expand Down
43 changes: 19 additions & 24 deletions jquery-uri.js
Expand Up @@ -8,39 +8,34 @@
* @license This websanova jQuery boilerplate is dual licensed under the MIT and GPL licenses.
* @link http://www.websanova.com
* @github http://github.com/websanova/jquery-uri
* @version 1.2.0
* @version 1.3.0
*
******************************************/

jQuery.extend(
{
uri: function(arg)
{
if(!arg) return window.location.toString();
else if(arg === 'domain') return window.location.hostname;
else if(arg === 'host') return window.location.hostname.split('.').slice(-2).join('.');
else if(arg === 'tld') return window.location.hostname.split('.').slice(-1).join('.');
else if(arg === 'sub')
{
var domain = window.location.hostname.split('.');

if(domain.length < 3) return '';
else return domain.slice(0, domain.length - 2).join('.');
}
else if(arg === 'path') return window.location.pathname;
else if($.isNumeric(arg))
{
var path = window.location.pathname.split('/');

arg = parseInt(arg);
return path[arg < 0 ? path.length + arg : arg] || '';
}
else if(arg === 'file') return window.location.pathname.split('/').slice(-1);
else if(arg === 'filename') return window.location.pathname.split('/').slice(-1)[0].split('.')[0];
else if(arg === 'fileext') return window.location.pathname.split('/').slice(-1)[0].split('.')[1] || '';
var _l = window.location,
_ls = _l.toString(),
_h = _l.hostname,
_hs = _h.split('.'),
_p = _l.pathname,
_ps = _p.split('/');

if(!arg) return _ls;
else if(arg === 'domain') return _h;
else if(arg === 'host') return _hs.slice(-2).join('.');
else if(arg === 'tld') return _hs.slice(-1).join('.');
else if(arg === 'sub') return _hs.slice(0, _hs.length - 2).join('.');
else if(arg === 'path') return _p;
else if($.isNumeric(arg)){ arg = parseInt(arg); return _ps[arg < 0 ? _ps.length + arg : arg] || ''; }
else if(arg === 'file') return _ps.slice(-1);
else if(arg === 'filename') return _ps.slice(-1)[0].split('.')[0];
else if(arg === 'fileext') return _ps.slice(-1)[0].split('.')[1] || '';
else if(arg[0] === '?' || arg[0] === '#')
{
var params = window.location.toString(), param = null;
var params = _ls, param = null;

if(arg[0] === '?') params = (params.split('?')[1] || '').split('#')[0];
else if(arg[0] === '#') params = (params.split('#')[1] || '');
Expand Down
1 change: 1 addition & 0 deletions jquery-uri.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d09ad5d

Please sign in to comment.