6
6
*
7
7
* See the README for details.
8
8
**/
9
- /*jshint jquery:true */
10
- /*global window:true */
11
9
define ( [
12
10
"jquery"
13
11
] , function ( $ ) {
12
+ $ . parseQuery = function ( options ) {
14
13
15
- $ . parseQuery = function ( options ) {
16
14
var config = { query : window . location . search || "" } ,
17
15
params = { } ;
18
16
@@ -22,30 +20,27 @@ define([
22
20
$ . extend ( config , $ . parseQuery , options ) ;
23
21
config . query = config . query . replace ( / ^ \? / , '' ) ;
24
22
25
- $ . each ( config . query . split ( config . separator ) , function ( i , param ) {
26
- var pair = param . split ( '=' ) ,
27
- key = config . decode ( pair . shift ( ) , null ) . toString ( ) ,
28
- value = config . decode ( pair . length ? pair . join ( '=' ) : null , key ) ;
29
-
30
- if ( config . array_keys ( key ) ) {
31
- params [ key ] = params [ key ] || [ ] ;
32
- params [ key ] . push ( value ) ;
33
- } else {
34
- params [ key ] = value ;
35
- }
36
- } ) ;
37
-
23
+ if ( config . query . length > 0 ) {
24
+ $ . each ( config . query . split ( config . separator ) , function ( i , param ) {
25
+ var pair = param . split ( '=' ) ,
26
+ key = config . decode ( pair . shift ( ) , null ) . toString ( ) ,
27
+ value = config . decode ( pair . length ? pair . join ( '=' ) : null , key ) ;
28
+
29
+ if ( config . array_keys . test ? config . array_keys . test ( key ) : config . array_keys ( key ) ) {
30
+ params [ key ] = params [ key ] || [ ] ;
31
+ params [ key ] . push ( value ) ;
32
+ } else {
33
+ params [ key ] = value ;
34
+ }
35
+ } ) ;
36
+ }
38
37
return params ;
39
38
} ;
40
-
41
- $ . parseQuery . decode = $ . parseQuery . default_decode = function ( string ) {
42
- return decodeURIComponent ( ( string || "" ) . replace ( '+' , ' ' ) ) ;
39
+ $ . parseQuery . decode = $ . parseQuery . default_decode = function ( string ) {
40
+ return decodeURIComponent ( ( string || "" ) . replace ( / \+ / g, ' ' ) ) ;
43
41
} ;
44
-
45
- $ . parseQuery . array_keys = function ( ) {
42
+ $ . parseQuery . array_keys = function ( ) {
46
43
return false ;
47
44
} ;
48
-
49
45
$ . parseQuery . separator = "&" ;
50
-
51
46
} ) ;
0 commit comments