File tree Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 1414
1515- Properly handle RFC 2068 quoted cookie values.
1616
17+ - ` $.cookie() ` returns all available cookies.
18+
17191.2.0
1820-----
1921- Adding ` $.removeCookie('foo') ` for deleting a cookie, using ` $.cookie('foo', null) ` is now deprecated.
Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ Read cookie:
2929
3030 $.cookie('the_cookie'); // => "the_value"
3131 $.cookie('not_existing'); // => null
32+
33+ Read all available cookies:
34+
35+ $.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }
3236
3337Delete cookie:
3438
Original file line number Diff line number Diff line change 5454 // read
5555 var decode = config . raw ? raw : decoded ;
5656 var cookies = document . cookie . split ( '; ' ) ;
57+ var result = key ? null : { } ;
5758 for ( var i = 0 , l = cookies . length ; i < l ; i ++ ) {
5859 var parts = cookies [ i ] . split ( '=' ) ;
59- if ( decode ( parts . shift ( ) ) === key ) {
60- var cookie = decode ( parts . join ( '=' ) ) ;
61- return config . json ? JSON . parse ( cookie ) : cookie ;
60+ var name = decode ( parts . shift ( ) ) ;
61+ var cookie = decode ( parts . join ( '=' ) ) ;
62+
63+ if ( config . json ) {
64+ cookie = JSON . parse ( cookie ) ;
65+ }
66+
67+ if ( key && key === name ) {
68+ result = cookie ;
69+ break ;
70+ }
71+
72+ if ( ! key ) {
73+ result [ name ] = cookie ;
6274 }
6375 }
6476
65- return null ;
77+ return result ;
6678 } ;
6779
6880 config . defaults = { } ;
Original file line number Diff line number Diff line change @@ -81,6 +81,17 @@ test('json: true', function () {
8181 }
8282} ) ;
8383
84+ + test ( 'no arguments' , function ( ) {
85+ document . cookie = 'x=y' ;
86+ var count = document . cookie . split ( ';' ) . length ;
87+ var cookies = $ . cookie ( ) ;
88+ equal ( typeof cookies , 'object' , 'should return object' ) ;
89+ var found = 0 ;
90+ for ( var key in cookies ) { found ++ ; }
91+ equal ( found , count , 'should contain all cookies' ) ;
92+ equal ( cookies . x , 'y' , 'should contain cookie values' ) ;
93+ } ) ;
94+
8495asyncTest ( 'malformed cookie value in IE (#88, #117)' , function ( ) {
8596 expect ( 1 ) ;
8697 // Sandbox in an iframe so that we can poke around with document.cookie.
You can’t perform that action at this time.
0 commit comments