Skip to content

Commit e39cf51

Browse files
committed
Some formatting fixes and cleanup, adding to changelog
1 parent 808704f commit e39cf51

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.2
2+
---
3+
- Adding `$.removeCookie('foo')` for deleting a cookie, using `$.cookie('foo', null)` is now deprecated.
4+
15
1.1
26
---
37
- Default options.

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ Read cookie:
2828
$.cookie('the_cookie', { raw: true }); // => "the_value" not URL decoded
2929
$.cookie('not_existing'); // => null
3030

31-
Delete cookie by calling $.removeCookie:
31+
Delete cookie:
3232

33-
//returns false => No cookie found
34-
//returns true => A cookie was found
35-
$.removeCookie('the_cookie'[, options ]);
33+
// returns false => No cookie found
34+
// returns true => A cookie was found
35+
$.removeCookie('the_cookie'[, options]);
3636

3737
*Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.*
3838

@@ -60,8 +60,6 @@ If true, the cookie transmission requires a secure protocol (https). Default: `f
6060

6161
By default the cookie value is encoded/decoded when creating/reading, using `encodeURIComponent`/`decodeURIComponent`. Turn off by setting `raw: true`. Default: `false`.
6262

63-
## Changelog
64-
6563
## Development
6664

6765
- Source hosted at [GitHub](https://github.com/carhartl/jquery-cookie)

jquery.cookie.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
* http://www.opensource.org/licenses/mit-license.php
99
* http://www.opensource.org/licenses/GPL-2.0
1010
*/
11-
(function($, document, undefined) {
11+
(function ($, document, undefined) {
1212

1313
var pluses = /\+/g;
14+
1415
function raw(s) {
1516
return s;
1617
}
18+
1719
function decoded(s) {
1820
return decodeURIComponent(s.replace(pluses, ' '));
1921
}
2022

21-
$.cookie = function(key, value, options) {
23+
$.cookie = function (key, value, options) {
2224

2325
// key and at least value given, set cookie...
2426
if (value !== undefined && !/Object/.test(Object.prototype.toString.call(value))) {
@@ -53,17 +55,18 @@
5355
return decode(parts.join('='));
5456
}
5557
}
58+
5659
return null;
5760
};
5861

5962
$.cookie.defaults = {};
6063

61-
$.removeCookie = function(key, options) {
62-
if( $.cookie(key, options) !== null ) {
64+
$.removeCookie = function (key, options) {
65+
if ($.cookie(key, options) !== null) {
6366
$.cookie(key, null, options);
6467
return true;
6568
}
6669
return false;
6770
};
6871

69-
})(jQuery, document);
72+
})(jQuery, document);

test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ test('defaults', 1, function () {
120120

121121
module('delete', before);
122122

123-
test('delete', 1, function () {
123+
test('delete (deprecated)', 1, function () {
124124
document.cookie = 'c=v';
125125
$.cookie('c', null);
126-
equal(document.cookie, '', 'should delete with null as value');
126+
equal(document.cookie, '', 'should delete the cookie');
127127
});
128128

129+
129130
module('removeCookie', before);
130131

131132
test('delete', 1, function() {
@@ -136,24 +137,24 @@ test('delete', 1, function() {
136137

137138
test('return', 2, function() {
138139
equal($.removeCookie('c'), false, "should return false if a cookie wasn't found");
139-
140+
140141
document.cookie = 'c=v';
141-
equal($.removeCookie('c'), true, "should return true if the cookie was found");
142+
equal($.removeCookie('c'), true, 'should return true if the cookie was found');
142143
});
143144

144145
test('passing options', 2, function() {
145146
var oldCookie = $.cookie;
146-
147-
$.cookie = function( arg0, arg1, arg2 ) {
148-
if( arg1 === null ) {
147+
148+
$.cookie = function(arg0, arg1, arg2) {
149+
if (arg1 === null) {
149150
equal(arg2.test, 'options', 'The options should be passed');
150151
} else {
151152
equal(arg1.test, 'options', 'The options should be passed');
152153
}
153154
};
154-
155+
155156
document.cookie = 'c=v';
156157
$.removeCookie('c', { test: 'options' });
157-
158+
158159
$.cookie = oldCookie;
159-
});
160+
});

0 commit comments

Comments
 (0)