Skip to content
Browse files

Some formatting fixes and cleanup, adding to changelog

  • Loading branch information...
1 parent 808704f commit e39cf517cc1bd2aec5950587f7abefa3a4662d29 @carhartl committed
Showing with 27 additions and 21 deletions.
  1. +4 −0 CHANGELOG.md
  2. +4 −6 README.md
  3. +8 −5 jquery.cookie.js
  4. +11 −10 test.js
View
4 CHANGELOG.md
@@ -1,3 +1,7 @@
+1.2
+---
+- Adding `$.removeCookie('foo')` for deleting a cookie, using `$.cookie('foo', null)` is now deprecated.
+
1.1
---
- Default options.
View
10 README.md
@@ -28,11 +28,11 @@ Read cookie:
$.cookie('the_cookie', { raw: true }); // => "the_value" not URL decoded
$.cookie('not_existing'); // => null
-Delete cookie by calling $.removeCookie:
+Delete cookie:
- //returns false => No cookie found
- //returns true => A cookie was found
- $.removeCookie('the_cookie'[, options ]);
+ // returns false => No cookie found
+ // returns true => A cookie was found
+ $.removeCookie('the_cookie'[, options]);
*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.*
@@ -60,8 +60,6 @@ If true, the cookie transmission requires a secure protocol (https). Default: `f
By default the cookie value is encoded/decoded when creating/reading, using `encodeURIComponent`/`decodeURIComponent`. Turn off by setting `raw: true`. Default: `false`.
-## Changelog
-
## Development
- Source hosted at [GitHub](https://github.com/carhartl/jquery-cookie)
View
13 jquery.cookie.js
@@ -8,17 +8,19 @@
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/GPL-2.0
*/
-(function($, document, undefined) {
+(function ($, document, undefined) {
var pluses = /\+/g;
+
function raw(s) {
return s;
}
+
function decoded(s) {
return decodeURIComponent(s.replace(pluses, ' '));
}
- $.cookie = function(key, value, options) {
+ $.cookie = function (key, value, options) {
// key and at least value given, set cookie...
if (value !== undefined && !/Object/.test(Object.prototype.toString.call(value))) {
@@ -53,17 +55,18 @@
return decode(parts.join('='));
}
}
+
return null;
};
$.cookie.defaults = {};
- $.removeCookie = function(key, options) {
- if( $.cookie(key, options) !== null ) {
+ $.removeCookie = function (key, options) {
+ if ($.cookie(key, options) !== null) {
$.cookie(key, null, options);
return true;
}
return false;
};
-})(jQuery, document);
+})(jQuery, document);
View
21 test.js
@@ -120,12 +120,13 @@ test('defaults', 1, function () {
module('delete', before);
-test('delete', 1, function () {
+test('delete (deprecated)', 1, function () {
document.cookie = 'c=v';
$.cookie('c', null);
- equal(document.cookie, '', 'should delete with null as value');
+ equal(document.cookie, '', 'should delete the cookie');
});
+
module('removeCookie', before);
test('delete', 1, function() {
@@ -136,24 +137,24 @@ test('delete', 1, function() {
test('return', 2, function() {
equal($.removeCookie('c'), false, "should return false if a cookie wasn't found");
-
+
document.cookie = 'c=v';
- equal($.removeCookie('c'), true, "should return true if the cookie was found");
+ equal($.removeCookie('c'), true, 'should return true if the cookie was found');
});
test('passing options', 2, function() {
var oldCookie = $.cookie;
-
- $.cookie = function( arg0, arg1, arg2 ) {
- if( arg1 === null ) {
+
+ $.cookie = function(arg0, arg1, arg2) {
+ if (arg1 === null) {
equal(arg2.test, 'options', 'The options should be passed');
} else {
equal(arg1.test, 'options', 'The options should be passed');
}
};
-
+
document.cookie = 'c=v';
$.removeCookie('c', { test: 'options' });
-
+
$.cookie = oldCookie;
-});
+});

0 comments on commit e39cf51

Please sign in to comment.
Something went wrong with that request. Please try again.