File tree Expand file tree Collapse file tree 4 files changed +126
-3
lines changed Expand file tree Collapse file tree 4 files changed +126
-3
lines changed Original file line number Diff line number Diff line change 1
- jquery-url
2
- ==========
1
+ # $.uri()
3
2
4
- $.url() - jQuery url functions
3
+ A jQuery $.uri() method for quickly parsing a uri.
4
+
5
+
6
+ ## Examples
7
+
8
+ ``` html
9
+ http://www.domain.com/path/name?query1=test&silly=willy#test=hash&chucky=cheese
10
+ ```
11
+
12
+ ``` javascript
13
+ $ .uri (); // www.domain.com
14
+ $ .uri (' domain' ); // www.domain.com
15
+ $ .uri (' tld' ); // domain.com
16
+ $ .uri (' path' ); // /path/name/
17
+ $ .uri (' 1' ); // path
18
+ $ .uri (' 2' ); // name
19
+ $ .uri (' 3' ); // (an empty string)
20
+ $ .uri (' ?' ); // query1=test&silly=willy
21
+ $ .uri (' ?silly' ); // willy
22
+ $ .uri (' ?poo' ); // (an empty string)
23
+ $ .uri (' #' ); // test=hash&chucky=cheese
24
+ $ .uri (' #chucky' ); // cheese
25
+ $ .uri (' #poo' ); // (an empty string)
26
+ ```
27
+
28
+
29
+ ## Resources
30
+
31
+ * [ jQuery Plugin Development Boilerplate] ( http://www.websanova.com/tutorials/jquery/jquery-plugin-development-boilerplate )
32
+ * [ The Ultimate Guide to Writing jQuery Plugins] ( http://www.websanova.com/tutorials/jquery/the-ultimate-guide-to-writing-jquery-plugins )
33
+
34
+
35
+ ## License
36
+
37
+ MIT licensed
38
+
39
+ Copyright (C) 2011-2012 Websanova http://www.websanova.com
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Websanova $.uri()</ title >
6
+
7
+ < script type ="text/javascript " src ="./inc/jquery.1.8.2.min.js "> </ script >
8
+ < script type ="text/javascript " src ="./jquery-uri.js "> </ script >
9
+
10
+ < script type ="text/javascript ">
11
+
12
+ console . log ( $ . uri ( ) ) ;
13
+ console . log ( $ . uri ( 'domain' ) ) ;
14
+ console . log ( $ . uri ( 'tld' ) ) ;
15
+ console . log ( $ . uri ( 'path' ) ) ;
16
+ console . log ( $ . uri ( '1' ) ) ;
17
+ console . log ( $ . uri ( '2' ) ) ;
18
+ console . log ( $ . uri ( '3' ) ) ;
19
+ console . log ( $ . uri ( '4' ) ) ;
20
+ console . log ( $ . uri ( '?' ) ) ;
21
+ console . log ( $ . uri ( '?test' ) ) ;
22
+ console . log ( $ . uri ( '?poo' ) ) ;
23
+ console . log ( $ . uri ( '#' ) ) ;
24
+ console . log ( $ . uri ( '#this' ) ) ;
25
+ console . log ( $ . uri ( '#test' ) ) ;
26
+
27
+ </ script >
28
+ </ head >
29
+ < body >
30
+
31
+ </ body >
32
+ </ html >
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
Original file line number Diff line number Diff line change
1
+ /******************************************
2
+ * Websanova.com
3
+ *
4
+ * Resources for web entrepreneurs
5
+ *
6
+ * @author Websanova
7
+ * @copyright Copyright (c) 2012 Websanova.
8
+ * @license This websanova jQuery boilerplate is dual licensed under the MIT and GPL licenses.
9
+ * @link http://www.websanova.com
10
+ * @github http://github.com/websanova/jquery-uri
11
+ * @version 1.0.0
12
+ *
13
+ ******************************************/
14
+
15
+ jQuery . extend (
16
+ {
17
+ uri : function ( arg )
18
+ {
19
+ if ( ! arg || arg === 'domain' ) return window . location . hostname ;
20
+ else if ( arg === 'tld' ) return window . location . hostname . split ( '.' ) . slice ( - 2 ) . join ( '.' ) ;
21
+ else if ( arg === 'path' ) return window . location . pathname ;
22
+ else if ( $ . isNumeric ( arg ) ) return window . location . pathname . split ( '/' ) [ arg ] || '' ;
23
+ else if ( arg [ 0 ] === '?' || arg [ 0 ] === '#' )
24
+ {
25
+ var params = window . location . toString ( ) , param = null ;
26
+
27
+ if ( arg [ 0 ] === '?' ) params = ( params . split ( '?' ) [ 1 ] || '' ) . split ( '#' ) [ 0 ] ;
28
+ else if ( arg [ 0 ] === '#' ) params = ( params . split ( '#' ) [ 1 ] || '' ) ;
29
+
30
+ if ( ! arg [ 1 ] ) return params ;
31
+
32
+ arg = arg . substring ( 1 ) ;
33
+ params = params . split ( '&' ) ;
34
+
35
+ for ( var i = 0 , ii = params . length ; i < ii ; i ++ )
36
+ {
37
+ param = params [ i ] . split ( '=' ) ;
38
+ if ( param [ 0 ] === arg ) return param [ 1 ] ;
39
+ }
40
+ }
41
+
42
+ return '' ;
43
+ }
44
+ } ) ;
You can’t perform that action at this time.
0 commit comments