From fd254ddffcda4d21ffb15f41da5eeea62bf51cc9 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 12 Oct 2012 15:46:31 +0200 Subject: [PATCH 001/130] Fixing IE issue, where cookie values were not read correctly because of duplicate occurrences of "; ", fixes #88, fixes #117. --- jquery.cookie.js | 3 ++- sandbox.html | 18 ++++++++++++++++++ test.js | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 sandbox.html diff --git a/jquery.cookie.js b/jquery.cookie.js index b188c19..2d4c05a 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -48,7 +48,8 @@ // read var decode = config.raw ? raw : decoded; var cookies = document.cookie.split('; '); - for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) { + for (var i = 0, l = cookies.length; i < l; i++) { + var parts = cookies[i].split('='); if (decode(parts.shift()) === key) { var cookie = decode(parts.join('=')); return config.json ? JSON.parse(cookie) : cookie; diff --git a/sandbox.html b/sandbox.html new file mode 100644 index 0000000..c8c4514 --- /dev/null +++ b/sandbox.html @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/test.js b/test.js index 334c4c2..ad71381 100644 --- a/test.js +++ b/test.js @@ -67,6 +67,24 @@ test('json: true', 1, function () { } }); +asyncTest('malformed cookie value in IE (#88, #117)', 1, function() { + // Sandbox in an iframe so that we can poke around with document.cookie. + var iframe = document.createElement('iframe'); + iframe.onload = function() { + start(); + if (iframe.contentWindow.ok) { + equal(iframe.contentWindow.testValue, 'two', 'reads all cookie values, skipping duplicate occurences of "; "'); + } else { + // Skip the test where we can't stub document.cookie using + // Object.defineProperty. Seems to work fine in + // Chrome, Firefox and IE 8+. + ok(true, 'N/A'); + } + }; + iframe.src = '/sandbox.html'; + document.body.appendChild(iframe) +}); + module('write', before); From 75a4882f8f96200724e59c4295bf068c3d3bd8d7 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 12 Oct 2012 15:46:59 +0200 Subject: [PATCH 002/130] Adding line for consistency --- test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test.js b/test.js index ad71381..46b67f2 100644 --- a/test.js +++ b/test.js @@ -155,6 +155,7 @@ test('json: true', 1, function () { } }); + module('delete', before); test('delete (deprecated)', 1, function () { From 892e6f0049747a35441d0ab47d1cba450b27c4c9 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 12 Oct 2012 15:48:28 +0200 Subject: [PATCH 003/130] Removing trailing whitespace --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 46b67f2..67349e1 100644 --- a/test.js +++ b/test.js @@ -185,7 +185,7 @@ test('with options', 2, function() { $.cookie = function(arg0, arg1, arg2) { if (arg1 === null) { - equal(arg2.foo, 'bar', 'should pass options when deleting cookie'); + equal(arg2.foo, 'bar', 'should pass options when deleting cookie'); } else { // see https://github.com/carhartl/jquery-cookie/issues/99 equal(arguments.length, 1, "should look up cookie instead of writing a new"); From 523c40740293de1299823e5a85a1df703802c54d Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 13 Oct 2012 12:56:16 +0300 Subject: [PATCH 004/130] Adding semicolon --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 67349e1..82f7a5e 100644 --- a/test.js +++ b/test.js @@ -82,7 +82,7 @@ asyncTest('malformed cookie value in IE (#88, #117)', 1, function() { } }; iframe.src = '/sandbox.html'; - document.body.appendChild(iframe) + document.body.appendChild(iframe); }); From d176f577d563e0237aa52b91c5a05ce3e6d5fbcb Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 15 Oct 2012 12:49:41 +0200 Subject: [PATCH 005/130] Adding note about not to include the plugin directly from GitHub, seems necessary. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 28be5dc..a964987 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ Include script *after* the jQuery library (unless you are packaging scripts some +**Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and such being blocked +in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). GitHub is not a CDN. + ## Usage Create session cookie: From b7edc7c6b1a2273540b7ccff94a51725ae683781 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 15 Oct 2012 12:51:42 +0200 Subject: [PATCH 006/130] Fixing typo, more explanation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a964987..301e356 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Include script *after* the jQuery library (unless you are packaging scripts some -**Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and such being blocked -in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). GitHub is not a CDN. +**Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked +in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN. ## Usage From 4b1433316b6b02924d134aeec20a55fe258c64d2 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 7 Nov 2012 15:10:19 +0100 Subject: [PATCH 007/130] Adding a note about a potential path + filename issue in Internet Explorer... --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 301e356..a1809a9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jquery.cookie + # jquery.cookie A simple, lightweight jQuery plugin for reading, writing and deleting cookies. @@ -42,30 +42,50 @@ Delete cookie: ## Configuration +### raw + By default the cookie value is encoded/decoded when writing/reading, using `encodeURIComponent`/`decodeURIComponent`. Bypass this by setting raw to true: $.cookie.raw = true; +### json + Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`: $.cookie.json = true; ## Cookie Options +### expires + Cookie attributes can be set globally by setting properties of the `$.cookie.defaults` object or individually for each call to `$.cookie()` by passing a plain object to the options argument. Per-call options override the default options. expires: 365 Define lifetime of the cookie. Value can be a `Number` which will be interpreted as days from time of creation or a `Date` object. If omitted, the cookie becomes a session cookie. +### path + path: '/' Define the path where the cookie is valid. *By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior).* If you want to make it available for instance across the entire domain use `path: '/'`. Default: path of page where the cookie was created. +**Note regarding Internet Explorer:** + +> Due to an obscure bug in the underlying WinINET InternetGetCookie implementation, IE’s document.cookie will not return a cookie if it was set with a path attribute containing a filename. + +(From [Internet Explorer Cookie Internals (FAQ)](http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx)) + +This means one cannot set a path using `path: window.location.pathname` in case such pathname contains a filename like so: `/check.html` (or at least, such cookie cannot be read correctly). + +### domain + domain: 'example.com' Define the domain where the cookie is valid. Default: domain of page where the cookie was created. +### secure + secure: true If true, the cookie transmission requires a secure protocol (https). Default: `false`. From 04f99cbfb06fa7c3f88692caf2ffae4be173d958 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 7 Nov 2012 15:13:21 +0100 Subject: [PATCH 008/130] Fixing first headline markdown --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1809a9..765950e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - # jquery.cookie +# jquery.cookie A simple, lightweight jQuery plugin for reading, writing and deleting cookies. From 75a5a29bc2183a4429dcb36bbea18e98cfe14e8a Mon Sep 17 00:00:00 2001 From: Fagner Brack Date: Mon, 21 Jan 2013 18:13:25 -0200 Subject: [PATCH 009/130] Remove expect from tests arguments --- test.js | 57 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/test.js b/test.js index 82f7a5e..26bd49b 100644 --- a/test.js +++ b/test.js @@ -14,38 +14,45 @@ var before = { module('read', before); -test('simple value', 1, function () { +test('simple value', function () { + expect(1); document.cookie = 'c=v'; equal($.cookie('c'), 'v', 'should return value'); }); -test('empty value', 1, function () { +test('empty value', function () { + expect(1); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, which // resulted in a bug while reading such a cookie. $.cookie('c', ''); equal($.cookie('c'), '', 'should return value'); }); -test('not existing', 1, function () { +test('not existing', function () { + expect(1); equal($.cookie('whatever'), null, 'should return null'); }); -test('decode', 1, function () { +test('decode', function () { + expect(1); document.cookie = encodeURIComponent(' c') + '=' + encodeURIComponent(' v'); equal($.cookie(' c'), ' v', 'should decode key and value'); }); -test('decode pluses to space for server side written cookie', 1, function () { +test('decode pluses to space for server side written cookie', function () { + expect(1); document.cookie = 'c=foo+bar' equal($.cookie('c'), 'foo bar', 'should convert pluses back to space'); }); -test('[] used in name', 1, function () { +test('[] used in name', function () { + expect(1); document.cookie = 'c[999]=foo'; equal($.cookie('c[999]'), 'foo', 'should return value'); }); -test('raw: true', 2, function () { +test('raw: true', function () { + expect(2); $.cookie.raw = true; document.cookie = 'c=%20v'; @@ -56,7 +63,8 @@ test('raw: true', 2, function () { equal($.cookie('c'), 'foo=bar', 'should include the entire value'); }); -test('json: true', 1, function () { +test('json: true', function () { + expect(1); $.cookie.json = true; if ('JSON' in window) { @@ -67,7 +75,8 @@ test('json: true', 1, function () { } }); -asyncTest('malformed cookie value in IE (#88, #117)', 1, function() { +asyncTest('malformed cookie value in IE (#88, #117)', function() { + expect(1); // Sandbox in an iframe so that we can poke around with document.cookie. var iframe = document.createElement('iframe'); iframe.onload = function() { @@ -88,58 +97,68 @@ asyncTest('malformed cookie value in IE (#88, #117)', 1, function() { module('write', before); -test('String primitive', 1, function () { +test('String primitive', function () { + expect(1); $.cookie('c', 'v'); equal($.cookie('c'), 'v', 'should write value'); }); -test('String object', 1, function () { +test('String object', function () { + expect(1); $.cookie('c', new String('v')); equal($.cookie('c'), 'v', 'should write value'); }); -test('value "[object Object]"', 1, function () { +test('value "[object Object]"', function () { + expect(1); $.cookie('c', '[object Object]'); equal($.cookie('c'), '[object Object]', 'should write value'); }); -test('number', 1, function () { +test('number', function () { + expect(1); $.cookie('c', 1234); equal($.cookie('c'), '1234', 'should write value'); }); -test('expires option as days from now', 1, function() { +test('expires option as days from now', function() { + expect(1); var sevenDaysFromNow = new Date(); sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); equal($.cookie('c', 'v', { expires: 7 }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), 'should write the cookie string with expires'); }); -test('expires option as Date instance', 1, function() { +test('expires option as Date instance', function() { + expect(1); var sevenDaysFromNow = new Date(); sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); equal($.cookie('c', 'v', { expires: sevenDaysFromNow }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), 'should write the cookie string with expires'); }); -test('invalid expires option (in the past)', 1, function() { +test('invalid expires option (in the past)', function() { + expect(1); var yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); $.cookie('c', 'v', { expires: yesterday }); equal($.cookie('c'), null, 'should not save already expired cookie'); }); -test('return value', 1, function () { +test('return value', function () { + expect(1); equal($.cookie('c', 'v'), 'c=v', 'should return written cookie string'); }); -test('defaults', 2, function () { +test('defaults', function () { + expect(2); $.cookie.defaults.path = '/'; ok($.cookie('c', 'v').match(/path=\//), 'should use options from defaults'); ok($.cookie('c', 'v', { path: '/foo' }).match(/path=\/foo/), 'options argument has precedence'); }); -test('raw: true', 1, function () { +test('raw: true', function () { + expect(1); $.cookie.raw = true; equal($.cookie('c', ' v').split('=')[1], ' v', 'should not encode'); }); From 0f5a49023fb89db11bc10c47391e376b9140e005 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 22 Jan 2013 11:58:05 +0100 Subject: [PATCH 010/130] Fixing version numbers in the changelog --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e47d325..0cd9602 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -1.3 (wip) ---- +HEAD +---- - Configuration options: `raw`, `json`. Replaces raw option, becomes config: ```javascript @@ -8,8 +8,8 @@ $.cookie.json = true; // automatically JSON stringify/parse value ``` Thus the default options now cleanly contain cookie attributes only. -1.2 ---- +1.2.0 +----- - Adding `$.removeCookie('foo')` for deleting a cookie, using `$.cookie('foo', null)` is now deprecated. 1.1 From 3ae56dc91ed604fa75b8517a3c38ee3438123720 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 22 Jan 2013 12:57:58 +0100 Subject: [PATCH 011/130] Removing licensing under GPL Version 2 (following the jQuery library itself here), also adding the MIT license to the repository. Closes #139. --- CHANGELOG.md | 16 ++++++++++------ MIT-LICENSE.txt | 20 ++++++++++++++++++++ jquery.cookie.js | 8 +++----- 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 MIT-LICENSE.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cd9602..b139fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,15 @@ HEAD ---- - Configuration options: `raw`, `json`. Replaces raw option, becomes config: -```javascript -$.cookie.raw = true; // bypass encoding/decoding the cookie value -$.cookie.json = true; // automatically JSON stringify/parse value -``` -Thus the default options now cleanly contain cookie attributes only. + ```javascript + $.cookie.raw = true; // bypass encoding/decoding the cookie value + $.cookie.json = true; // automatically JSON stringify/parse value + ``` + + Thus the default options now cleanly contain cookie attributes only. + +- Removing licensing under GPL Version 2, the plugin is now released under MIT License only +(following the jQuery library itself here). 1.2.0 ----- @@ -14,4 +18,4 @@ Thus the default options now cleanly contain cookie attributes only. 1.1 --- -- Default options. +- Adding default options. diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt new file mode 100644 index 0000000..8ae647b --- /dev/null +++ b/MIT-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright 2013 Klaus Hartl + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/jquery.cookie.js b/jquery.cookie.js index 2d4c05a..98ee5f5 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -1,11 +1,9 @@ /*! - * jQuery Cookie Plugin v1.3 + * jQuery Cookie Plugin v1.3.0 * https://github.com/carhartl/jquery-cookie * - * Copyright 2011, Klaus Hartl - * Dual licensed under the MIT or GPL Version 2 licenses. - * http://www.opensource.org/licenses/mit-license.php - * http://www.opensource.org/licenses/GPL-2.0 + * Copyright 2013 Klaus Hartl + * Released under the MIT license */ (function ($, document, undefined) { From 793946a420524ee9e9e818dfa19b8a00632d20f6 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 23 Jan 2013 11:12:13 +0100 Subject: [PATCH 012/130] Updating jQuery and QUnit --- test.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.html b/test.html index 90daad6..bf5a08f 100644 --- a/test.html +++ b/test.html @@ -3,9 +3,9 @@ jquery.cookie Test Suite - - - + + + From a2e985946f4b33aa39f4da6acf696efa3ef29c94 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 23 Jan 2013 11:39:47 +0100 Subject: [PATCH 013/130] Adding jQuery plugin package manifest --- cookie.jquery.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cookie.jquery.json diff --git a/cookie.jquery.json b/cookie.jquery.json new file mode 100644 index 0000000..8b21841 --- /dev/null +++ b/cookie.jquery.json @@ -0,0 +1,19 @@ +{ + "name": "cookie", + "version": "1.2.0", + "title": "jQuery Cookie", + "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies", + "author": "Klaus Hartl", + "licenses": [ + { + "type": "MIT", + "url": "https://raw.github.com/carhartl/jquery-cookie/master/MIT-LICENSE.txt" + } + ], + "dependencies": { + "jquery": ">=1.0" + }, + "bugs": "https://github.com/carhartl/jquery-cookie/issues", + "homepage": "https://github.com/carhartl/jquery-cookie", + "docs": "https://github.com/carhartl/jquery-cookie" +} From bebed17cae2bb74489c6e1d8629995e52d8e8e05 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 23 Jan 2013 11:53:08 +0100 Subject: [PATCH 014/130] Fixing author property --- cookie.jquery.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cookie.jquery.json b/cookie.jquery.json index 8b21841..7950cb6 100644 --- a/cookie.jquery.json +++ b/cookie.jquery.json @@ -3,7 +3,10 @@ "version": "1.2.0", "title": "jQuery Cookie", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies", - "author": "Klaus Hartl", + "author": { + "name": "Klaus Hartl", + "url": "https://github.com/carhartl" + }, "licenses": [ { "type": "MIT", From 3ec7c95dca01fa6368f083defe329c544cba47b4 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 23 Jan 2013 11:53:58 +0100 Subject: [PATCH 015/130] Adding a component.json for bower, closes #115 --- component.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 component.json diff --git a/component.json b/component.json new file mode 100644 index 0000000..91ceea7 --- /dev/null +++ b/component.json @@ -0,0 +1,10 @@ +{ + "name": "jquery.cookie", + "version": "1.2.0", + "main": [ + "./jquery.cookie.js" + ], + "dependencies": { + "jquery": ">=1.0" + } +} From ff9dfc634e91a7cbd32a27596efa1fb0199c2d0c Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 23 Jan 2013 12:59:39 +0100 Subject: [PATCH 016/130] Handle RFC 2068 quoted cookie values properly, closes #57 --- CHANGELOG.md | 2 ++ jquery.cookie.js | 10 +++++++++- test.js | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b139fbf..8a9d441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ HEAD - Removing licensing under GPL Version 2, the plugin is now released under MIT License only (following the jQuery library itself here). +- Properly handle RFC 2068 quoted cookie values. + 1.2.0 ----- - Adding `$.removeCookie('foo')` for deleting a cookie, using `$.cookie('foo', null)` is now deprecated. diff --git a/jquery.cookie.js b/jquery.cookie.js index 98ee5f5..8ed3f69 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -14,8 +14,16 @@ } function decoded(s) { - return decodeURIComponent(s.replace(pluses, ' ')); + return unRfc2068(decodeURIComponent(s.replace(pluses, ' '))); } + + function unRfc2068(value) { + if (value.indexOf('"') === 0) { + // This is a quoted cookie as according to RFC2068, unescape + value = value.slice(1, -1).replace('\\"', '"').replace('\\\\', '\\'); + } + return value; + }; var config = $.cookie = function (key, value, options) { diff --git a/test.js b/test.js index 26bd49b..3c33379 100644 --- a/test.js +++ b/test.js @@ -33,6 +33,12 @@ test('not existing', function () { equal($.cookie('whatever'), null, 'should return null'); }); +test('rfc2068 quoted string', function () { + expect(1); + document.cookie = 'c="v@address.com\\"\\\\"'; + equal($.cookie('c'), 'v@address.com"\\', 'should decode rfc2068 quoted string'); +}); + test('decode', function () { expect(1); document.cookie = encodeURIComponent(' c') + '=' + encodeURIComponent(' v'); From 57cd3ddd2f32e373ec7da79049b1d58acbb7de27 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 24 Jan 2013 14:23:39 +0100 Subject: [PATCH 017/130] Adding missing var statement, missing semicolons --- test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index 3c33379..9441cc0 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ var before = { setup: function () { - cookies = document.cookie.split('; ') + var cookies = document.cookie.split('; '); for (var i = 0, c; (c = (cookies)[i]) && (c = c.split('=')[0]); i++) { document.cookie = c + '=; expires=' + new Date(0).toUTCString(); } @@ -47,7 +47,7 @@ test('decode', function () { test('decode pluses to space for server side written cookie', function () { expect(1); - document.cookie = 'c=foo+bar' + document.cookie = 'c=foo+bar'; equal($.cookie('c'), 'foo bar', 'should convert pluses back to space'); }); From c32ed09760ae336e66ba6acc18b9f4b556d7565a Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 24 Jan 2013 16:20:01 +0100 Subject: [PATCH 018/130] Calling $.cookie without arguments returns all available cookies as object... --- CHANGELOG.md | 2 ++ README.md | 4 ++++ jquery.cookie.js | 20 ++++++++++++++++---- test.js | 11 +++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a9d441..3395654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ HEAD - Properly handle RFC 2068 quoted cookie values. +- `$.cookie()` returns all available cookies. + 1.2.0 ----- - Adding `$.removeCookie('foo')` for deleting a cookie, using `$.cookie('foo', null)` is now deprecated. diff --git a/README.md b/README.md index 765950e..01b6b4e 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ Read cookie: $.cookie('the_cookie'); // => "the_value" $.cookie('not_existing'); // => null + +Read all available cookies: + + $.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } Delete cookie: diff --git a/jquery.cookie.js b/jquery.cookie.js index 8ed3f69..2887ea6 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -54,15 +54,27 @@ // read var decode = config.raw ? raw : decoded; var cookies = document.cookie.split('; '); + var result = key ? null : {}; for (var i = 0, l = cookies.length; i < l; i++) { var parts = cookies[i].split('='); - if (decode(parts.shift()) === key) { - var cookie = decode(parts.join('=')); - return config.json ? JSON.parse(cookie) : cookie; + var name = decode(parts.shift()); + var cookie = decode(parts.join('=')); + + if (config.json) { + cookie = JSON.parse(cookie); + } + + if (key && key === name) { + result = cookie; + break; + } + + if (!key) { + result[name] = cookie; } } - return null; + return result; }; config.defaults = {}; diff --git a/test.js b/test.js index 9441cc0..1eed4be 100644 --- a/test.js +++ b/test.js @@ -81,6 +81,17 @@ test('json: true', function () { } }); ++test('no arguments', function () { + document.cookie = 'x=y'; + var count = document.cookie.split(';').length; + var cookies = $.cookie(); + equal(typeof cookies, 'object', 'should return object'); + var found = 0; + for (var key in cookies) { found++; } + equal(found, count, 'should contain all cookies'); + equal(cookies.x, 'y', 'should contain cookie values'); +}); + asyncTest('malformed cookie value in IE (#88, #117)', function() { expect(1); // Sandbox in an iframe so that we can poke around with document.cookie. From e15880942eaf152716b4fc978c348b42e08045b8 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 24 Jan 2013 17:26:39 +0100 Subject: [PATCH 019/130] Forgot to update jQuery in the sandbox - could probably pull from top... --- sandbox.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandbox.html b/sandbox.html index c8c4514..1f65de7 100644 --- a/sandbox.html +++ b/sandbox.html @@ -2,7 +2,7 @@ - + - - + +

jquery.cookie Test Suite

diff --git a/sandbox.html b/test/sandbox.html similarity index 100% rename from sandbox.html rename to test/sandbox.html diff --git a/server.js b/test/server.js similarity index 90% rename from server.js rename to test/server.js index 8136795..8d2e712 100644 --- a/server.js +++ b/test/server.js @@ -21,4 +21,4 @@ http.createServer(function(request, response) { }); }).listen(8124, '0.0.0.0'); -console.log('Test suite at http://0.0.0.0:8124/test.html'); +console.log('Test suite at http://0.0.0.0:8124/test/index.html'); diff --git a/test.js b/test/tests.js similarity index 100% rename from test.js rename to test/tests.js From 014706b2665c665df3a692ddc8e9cae5c20be830 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 25 Jan 2013 22:18:30 +0100 Subject: [PATCH 037/130] Fixing path to jquery.cookie.js --- test/sandbox.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sandbox.html b/test/sandbox.html index 1f65de7..b4a3f78 100644 --- a/test/sandbox.html +++ b/test/sandbox.html @@ -3,7 +3,7 @@ - + +```html + +``` **Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN. @@ -19,32 +21,44 @@ The plugin can also be loaded as AMD module. Create session cookie: - $.cookie('the_cookie', 'the_value'); +```javascript +$.cookie('the_cookie', 'the_value'); +``` Create expiring cookie, 7 days from then: - $.cookie('the_cookie', 'the_value', { expires: 7 }); +```javascript +$.cookie('the_cookie', 'the_value', { expires: 7 }); +``` Create expiring cookie, valid across entire site: - $.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); +```javascript +$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); +``` Read cookie: - $.cookie('the_cookie'); // => "the_value" - $.cookie('not_existing'); // => undefined +```javascript +$.cookie('the_cookie'); // => "the_value" +$.cookie('not_existing'); // => undefined +``` Read all available cookies: - $.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } +```javascript +$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } +``` Delete cookie: - // Returns true when cookie was found, false when no cookie was found... - $.removeCookie('the_cookie'); +```javascript +// Returns true when cookie was found, false when no cookie was found... +$.removeCookie('the_cookie'); - // Same path as when the cookie was written... - $.removeCookie('the_cookie', { path: '/' }); +// Same path as when the cookie was written... +$.removeCookie('the_cookie', { path: '/' }); +``` *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.* @@ -54,13 +68,17 @@ Delete cookie: By default the cookie value is encoded/decoded when writing/reading, using `encodeURIComponent`/`decodeURIComponent`. Bypass this by setting raw to true: - $.cookie.raw = true; +```javascript +$.cookie.raw = true; +``` ### json Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`: - $.cookie.json = true; +```javascript +$.cookie.json = true; +``` ## Cookie Options From 3caf209abe30a856789d0ceb464c297dfdbe670e Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 5 Oct 2013 20:24:16 +0200 Subject: [PATCH 077/130] Preparing for 1.4.0 release --- CHANGELOG.md | 3 +++ README.md | 2 +- bower.json | 2 +- cookie.jquery.json | 2 +- jquery.cookie.js | 2 +- package.json | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 246232d..467dd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ HEAD ----- + +1.4.0 +----- - Support for AMD. - Removed deprecated method `$.cookie('name', null)` for deleting a cookie, diff --git a/README.md b/README.md index a5ad9f3..7377611 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ If true, the cookie transmission requires a secure protocol (https). Default: `f ## Converters -Provide a conversion function as optional last argument for reading, in order to change the cookie's value +Provide a conversion function as optional last argument for reading, in order to change the cookie's value to a different representation on the fly. Example for parsing a value into a number: diff --git a/bower.json b/bower.json index dd91171..8a5b5d0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.3.1", + "version": "1.4.0", "main": [ "./jquery.cookie.js" ], diff --git a/cookie.jquery.json b/cookie.jquery.json index 9267e69..522d5e1 100644 --- a/cookie.jquery.json +++ b/cookie.jquery.json @@ -1,6 +1,6 @@ { "name": "cookie", - "version": "1.3.1", + "version": "1.4.0", "title": "jQuery Cookie", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "author": { diff --git a/jquery.cookie.js b/jquery.cookie.js index d1b32c1..9271900 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -1,5 +1,5 @@ /*! - * jQuery Cookie Plugin v1.3.1 + * jQuery Cookie Plugin v1.4.0 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Klaus Hartl diff --git a/package.json b/package.json index 761f17a..3942d32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.3.1", + "version": "1.4.0", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "main": "Gruntfile.js", "directories": { From 0ae9f7eec0f56c677c826094eb126060a50b93b6 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 16 Oct 2013 12:17:58 +0200 Subject: [PATCH 078/130] Fix return value for $.removeCookie() in case cookie deletion failed for whatever reason. Closes #224. --- jquery.cookie.js | 11 +++++----- test/tests.js | 54 ++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 9271900..72d3cd2 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -106,12 +106,13 @@ config.defaults = {}; $.removeCookie = function (key, options) { - if ($.cookie(key) !== undefined) { - // Must not alter options, thus extending a fresh object... - $.cookie(key, '', $.extend({}, options, { expires: -1 })); - return true; + if ($.cookie(key) === undefined) { + return false; } - return false; + + // Must not alter options, thus extending a fresh object... + $.cookie(key, '', $.extend({}, options, { expires: -1 })); + return !$.cookie(key); }; })); diff --git a/test/tests.js b/test/tests.js index c5c3171..8f75b42 100644 --- a/test/tests.js +++ b/test/tests.js @@ -110,7 +110,9 @@ test('invalid URL encoding', function () { expect(1); document.cookie = 'bad=foo%'; strictEqual($.cookie('bad'), undefined, "won't throw exception, returns undefined"); - document.cookie = 'bad=foo'; // Allow to be deleted... + // Delete manually here because it requires raw === true... + $.cookie.raw = true; + $.removeCookie('bad'); }); asyncTest('malformed cookie value in IE (#88, #117)', function () { @@ -152,6 +154,9 @@ test('Call to read all with a badly encoded cookie', function () { document.cookie = 'bad=foo%'; document.cookie = 'good=foo'; deepEqual($.cookie(), { good: 'foo' }, 'returns object containing all decodable cookies'); + // Delete manually here because it requires raw === true... + $.cookie.raw = true; + $.removeCookie('bad'); }); @@ -213,7 +218,8 @@ test('raw = true', function () { expect(1); $.cookie.raw = true; strictEqual($.cookie('c[1]', 'v[1]'), 'c[1]=v[1]', 'should not encode'); - $.each($.cookie(), $.removeCookie); + // Delete manually here because it requires raw === true... + $.removeCookie('c[1]'); }); test('json = true', function () { @@ -238,42 +244,46 @@ test('deletion', function () { strictEqual(document.cookie, '', 'should delete the cookie'); }); -test('return', function () { - expect(2); - strictEqual($.removeCookie('c'), false, "return false if the cookie wasn't found"); - +test('when sucessfully deleted', function () { + expect(1); $.cookie('c', 'v'); - strictEqual($.removeCookie('c'), true, 'return true if the cookie was found'); + strictEqual($.removeCookie('c'), true, 'returns true'); }); -test('with options', function () { - expect(3); - var originalCookie = $.cookie; - var callCount = 0; +test('when deletion failed', function () { + expect(1); + $.cookie('c', 'v'); + var originalCookie = $.cookie; $.cookie = function () { - callCount++; - if (callCount === 1) { - // see https://github.com/carhartl/jquery-cookie/issues/99 - strictEqual(arguments.length, 1, 'look up cookie instead of accidently writing a new'); - return 'cookie'; // act as if a cookie was found... - } - if (callCount === 2) { - strictEqual(arguments[2].foo, 'bar', 'pass along options when deleting cookie'); + // Stub deletion... + if (arguments.length === 1) { + return originalCookie.apply(null, arguments); } }; - $.removeCookie('c', { foo: 'bar' }); - strictEqual(callCount, 2); + strictEqual($.removeCookie('c'), false, 'returns false'); $.cookie = originalCookie; }); -test('passing options reference', function () { +test('when cookie does not exist', function () { + expect(1); + strictEqual($.removeCookie('c'), false, 'returns false'); +}); + +test('with options', function () { expect(1); var options = { path: '/' }; $.cookie('c', 'v', options); + $.removeCookie('c', options); + strictEqual(document.cookie, '', 'should delete the cookie'); +}); +test('passing options reference', function () { + expect(1); + var options = { path: '/' }; + $.cookie('c', 'v', options); $.removeCookie('c', options); deepEqual(options, { path: '/' }, "won't alter options object"); }); From 3ab35ab43ef4aed1c3d463ce8e0a86c914b0d260 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 24 Oct 2013 23:13:32 +0200 Subject: [PATCH 079/130] Using a single try/catch block instead of two. --- jquery.cookie.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 72d3cd2..6aee051 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -38,13 +38,8 @@ try { // Replace server-side written pluses with spaces. // If we can't decode the cookie, ignore it, it's unusable. - s = decodeURIComponent(s.replace(pluses, ' ')); - } catch(e) { - return; - } - - try { // If we can't parse the cookie, ignore it, it's unusable. + s = decodeURIComponent(s.replace(pluses, ' ')); return config.json ? JSON.parse(s) : s; } catch(e) {} } From 7984c941e06b071eaf3eac9cfbd171decd3b75b2 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 30 Oct 2013 16:20:01 +0100 Subject: [PATCH 080/130] Adding Code Climate badge. Closes #228. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7377611..dfa1586 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) +# jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) [![Selenium Test Status](https://saucelabs.com/browser-matrix/carhartl.svg)](https://saucelabs.com/u/carhartl) From 8947f435c39b209d1ef4c46284702c2e0d03678b Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 30 Oct 2013 16:41:28 +0100 Subject: [PATCH 081/130] Using correctly set up Sauce Labs account (one for open source). Should fix badge not showing up. --- .travis.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b84117..b65fdbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,5 @@ before_script: script: grunt ci --verbose env: global: - - secure: FjCPTpIs6l6zTvXqH9rPTXqeRCpNa0cmz2Glio8fmOhbdeNbAdQTZGPChe8wTqIQ4wRQUtg4BPZjYx4+ibhj530/QW+736d9UUX5MhixCbm9r6EzRuljlo0wGRsLRa3pHIKyxq18bdilBSYaPrbekpLSyCKM/3wJa34k8LNKdrg= - - secure: dJU6/DdQkuhVNSuaR1OswON7cHjRR7mDv0szIZ1rY/TRNoL6GrDr7XGpeQAtV+6Pqu1RJWb1V0VHoPble6imYqWtiq9LZu8UtU/ImKkZWZxFgMyDDJEli4Lw/+p1UMBNf7jXM3v8t9aOA0eHTwX7IA++paNIdehBOyNI8x3t6Ng= + - secure: HRae0kyIDDuhonvMi2SfEl1WJb4K/wX8WmzT9YkxFbmWwLjiOMkmqyuEyi76DbTC1cb9o7WwGVgbP1DhSm6n6m0Lz+PSzpprBN4QZuJc56jcc+tBA6gM81hyUufaTT0yUWz112Bu06kWIAs44w5PtG0FYZR0CuIN8fQvZi8fXCQ= + - secure: c+M5ECIfxDcVrr+ZlqgpGjv8kVM/hxiz3ACMCn4ZkDiaeq4Rw0wWIGZYL6aV5fhsoHgzEQ/XQPca8xKs3Umr7R3b6Vr3AEyFnW+LP67K/1Qbz4Pi3PvhDH/h4rvK7fOoTqTDCVVDEH3v4pefsz2VaKemG4iBKxrcof5aR4Rjopk= diff --git a/README.md b/README.md index dfa1586..1c1f068 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) -[![Selenium Test Status](https://saucelabs.com/browser-matrix/carhartl.svg)](https://saucelabs.com/u/carhartl) +[![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) A simple, lightweight jQuery plugin for reading, writing and deleting cookies. From ac265dcb3bd0d18252396a0ce6db5c4a4c420069 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 31 Oct 2013 09:09:15 +0100 Subject: [PATCH 082/130] Moving build status matrix below description. [ci skip] --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c1f068..e409147 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) -[![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) - A simple, lightweight jQuery plugin for reading, writing and deleting cookies. +## Build Status Matrix + +[![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) + ## Installation Include script *after* the jQuery library (unless you are packaging scripts somehow else): From 580416a8b08e33d819a92fca7f4caa8d9ca6527c Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 26 Nov 2013 16:51:36 +0200 Subject: [PATCH 083/130] add jspm package.json config --- package.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/package.json b/package.json index 3942d32..2553b83 100644 --- a/package.json +++ b/package.json @@ -27,5 +27,12 @@ "grunt-saucelabs": "~4.1.1", "grunt-contrib-connect": "~0.5.0", "gzip-js": "~0.3.0" + }, + "jspm": { + "main": "jquery.cookie", + "files": ["jquery.cookie.js"], + "buildConfig": { + "uglify": true + } } } From ecb597b65e4c477baa2b30a2a5a67fdaee9870ea Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 29 Nov 2013 22:54:53 +0100 Subject: [PATCH 084/130] Allow fractions of a day for expires option. Closes #246. --- jquery.cookie.js | 3 ++- test/tests.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 6aee051..6412847 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -52,12 +52,13 @@ var config = $.cookie = function (key, value, options) { // Write + if (value !== undefined && !$.isFunction(value)) { options = $.extend({}, config.defaults, options); if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new Date(); - t.setDate(t.getDate() + days); + t.setTime(+t + days * 864e+5); } return (document.cookie = [ diff --git a/test/tests.js b/test/tests.js index 8f75b42..f1c357a 100644 --- a/test/tests.js +++ b/test/tests.js @@ -194,6 +194,18 @@ test('expires option as days from now', function () { 'should write the cookie string with expires'); }); +test('expires option as fraction of a day', function () { + expect(1); + + now = new Date().getTime(); + expires = Date.parse($.cookie('c', 'v', { expires: 0.5 })); + + // When we were using Date.setDate() fractions have been ignored + // and expires resulted in the current date. Allow 1000 milliseconds + // difference for execution time. + ok(expires > now + 1000, 'should write expires attribute with the correct date'); +}); + test('expires option as Date instance', function () { expect(1); var sevenDaysFromNow = new Date(); From fbb0117ff06f7d7410c4243af8906e64d3ad27de Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 30 Nov 2013 14:06:17 +0100 Subject: [PATCH 085/130] Date.parse works a bit different in Firefox and IE and Webkit. Also fixing the creation of global variables in the test. --- test/tests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests.js b/test/tests.js index f1c357a..bd32552 100644 --- a/test/tests.js +++ b/test/tests.js @@ -197,8 +197,8 @@ test('expires option as days from now', function () { test('expires option as fraction of a day', function () { expect(1); - now = new Date().getTime(); - expires = Date.parse($.cookie('c', 'v', { expires: 0.5 })); + var now = new Date().getTime(); + var expires = Date.parse($.cookie('c', 'v', { expires: 0.5 }).replace(/.+expires=/, '')); // When we were using Date.setDate() fractions have been ignored // and expires resulted in the current date. Allow 1000 milliseconds From d24eb23c3f045fe96e9e2993529a91478a97fca8 Mon Sep 17 00:00:00 2001 From: "Bruno Winck, Kneaver" Date: Fri, 27 Dec 2013 15:21:37 +0530 Subject: [PATCH 086/130] Add component.json to support component.io --- component.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 component.json diff --git a/component.json b/component.json new file mode 100644 index 0000000..5e6ae45 --- /dev/null +++ b/component.json @@ -0,0 +1,14 @@ +{ + "name": "jquery.cookie", + "repo": "carhartl/jquery-cookie", + "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies", + "version": "1.4.0", + "keywords": [], + "dependencies": {}, + "development": {}, + "license": "MIT", + "main": "jquery.cookie.js", + "scripts": [ + "jquery.cookie.js" + ] +} \ No newline at end of file From 3646a0de3e271641a3e232d39e29e71bdab16850 Mon Sep 17 00:00:00 2001 From: Colin Rymer Date: Tue, 28 Jan 2014 11:02:28 -0500 Subject: [PATCH 087/130] add jamjs support --- package.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/package.json b/package.json index 2553b83..721ca67 100644 --- a/package.json +++ b/package.json @@ -34,5 +34,14 @@ "buildConfig": { "uglify": true } + }, + "jam": { + "dependencies": { + "jquery": ">=1.2" + }, + "main": "jquery.cookie.js", + "include": [ + "jquery.cookie.js" + ] } } From 433a10696e71f1584662cae507c404f4bfbb9526 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 28 Jan 2014 21:03:09 +0100 Subject: [PATCH 088/130] Adding note about the documentation in master vs latest release --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e409147..6def3e1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ A simple, lightweight jQuery plugin for reading, writing and deleting cookies. +**If you're viewing this at https://github.com/carhartl/jquery-cookie, you're reading the documentation for the master branch. +[View documentation for the latest release (1.4.0).](https://github.com/carhartl/jquery-cookie/tree/v1.4.0)** + ## Build Status Matrix [![Selenium Test Status](https://saucelabs.com/browser-matrix/jquery-cookie.svg)](https://saucelabs.com/u/jquery-cookie) From 92c3fd0ad5cfa45ff03914969912fad4c4a9861a Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Mon, 10 Feb 2014 15:48:51 -0700 Subject: [PATCH 089/130] Fix package.json main property This allows tools like volo to know which file to include in a dependent's lib directory. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2553b83..07395f5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery.cookie", "version": "1.4.0", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", - "main": "Gruntfile.js", + "main": "jquery.cookie.js", "directories": { "test": "test" }, From 5421819450666bada6d1aed655cfaf4e85a4f88b Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Mon, 10 Feb 2014 15:51:36 -0700 Subject: [PATCH 090/130] Download hint for volo --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 2553b83..9324fee 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ "grunt-contrib-connect": "~0.5.0", "gzip-js": "~0.3.0" }, + "volo": { + "url": "https://raw.github.com/carhartl/jquery-cookie/v{version}/jquery.cookie.js" + }, "jspm": { "main": "jquery.cookie", "files": ["jquery.cookie.js"], From 6e175cd71e0d4cf8b64739b3128ddef5a33c938a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gasto=CC=81n=20Omar=20Sa=CC=81nchez=20Rui=CC=81z?= Date: Tue, 11 Feb 2014 21:36:39 -0600 Subject: [PATCH 091/130] Add CommonJS support --- .jshintrc | 3 ++- README.md | 2 +- jquery.cookie.js | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.jshintrc b/.jshintrc index b0af059..a37f48c 100644 --- a/.jshintrc +++ b/.jshintrc @@ -11,6 +11,7 @@ "undef": true, "globals": { "define": true, - "jQuery": true + "jQuery": true, + "require": true } } diff --git a/README.md b/README.md index 6def3e1..536b5a0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Include script *after* the jQuery library (unless you are packaging scripts some **Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN. -The plugin can also be loaded as AMD module. +The plugin can also be loaded as AMD or CommonJS module. ## Usage diff --git a/jquery.cookie.js b/jquery.cookie.js index 6412847..2f84144 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -9,6 +9,9 @@ if (typeof define === 'function' && define.amd) { // AMD. Register as anonymous module. define(['jquery'], factory); + } else if (typeof exports === 'object') { + // CommonJS + factory(require('jquery')); } else { // Browser globals. factory(jQuery); From 187c874c6727f4c9518e6565e1b742192de80bb5 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 28 Feb 2014 20:08:17 +0100 Subject: [PATCH 092/130] Write comments in a consistent manner --- jquery.cookie.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index 2f84144..211da5c 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -7,13 +7,13 @@ */ (function (factory) { if (typeof define === 'function' && define.amd) { - // AMD. Register as anonymous module. + // AMD define(['jquery'], factory); } else if (typeof exports === 'object') { // CommonJS factory(require('jquery')); } else { - // Browser globals. + // Browser globals factory(jQuery); } }(function ($) { From 5b12a4e11dd167d6227cb866ee6e88134cdae813 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 28 Feb 2014 20:34:35 +0100 Subject: [PATCH 093/130] Adding missing newline at the end --- component.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component.json b/component.json index 5e6ae45..6b7122a 100644 --- a/component.json +++ b/component.json @@ -11,4 +11,4 @@ "scripts": [ "jquery.cookie.js" ] -} \ No newline at end of file +} From 8f641ded8a1f6b7697161e258592c9d388d15485 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 4 Mar 2014 09:55:57 +0100 Subject: [PATCH 094/130] Updating changelog, preparing for next release --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 467dd42..80511c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ HEAD ----- +- Added support for CommonJS. + +- Added support for package managers: Jam (http://jamjs.org), volo (http://volojs.org), Component (http://component.io), jspm (http://jspm.io). + +- The expires option now interpretes fractions of numbers (e.g. days) correctly. + 1.4.0 ----- - Support for AMD. From 9481ec9eb649e10cd8650d58c0170a36b2da10e7 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 4 Mar 2014 09:58:05 +0100 Subject: [PATCH 095/130] Removing newline --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80511c2..e72e6d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ HEAD ----- - - Added support for CommonJS. - Added support for package managers: Jam (http://jamjs.org), volo (http://volojs.org), Component (http://component.io), jspm (http://jspm.io). From 38b998b9780e52da3952ab57572c36f46280a79a Mon Sep 17 00:00:00 2001 From: Nicholas Van de walle Date: Fri, 14 Mar 2014 09:00:09 -0700 Subject: [PATCH 096/130] Update MIT-LICENSE.txt Updated your license to the current year. --- MIT-LICENSE.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt index 8ae647b..7a631e8 100644 --- a/MIT-LICENSE.txt +++ b/MIT-LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2013 Klaus Hartl +Copyright 2014 Klaus Hartl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 7f88a4e631aba8a8c688fd8999ce6b9bcfd50718 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sun, 27 Apr 2014 22:07:15 +0200 Subject: [PATCH 097/130] Preparing for 1.4.1 release --- CHANGELOG.md | 3 +++ README.md | 2 +- bower.json | 2 +- component.json | 2 +- cookie.jquery.json | 2 +- jquery.cookie.js | 2 +- package.json | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e72e6d2..59d868f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ HEAD ----- + +1.4.1 +----- - Added support for CommonJS. - Added support for package managers: Jam (http://jamjs.org), volo (http://volojs.org), Component (http://component.io), jspm (http://jspm.io). diff --git a/README.md b/README.md index 536b5a0..f9a7494 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A simple, lightweight jQuery plugin for reading, writing and deleting cookies. **If you're viewing this at https://github.com/carhartl/jquery-cookie, you're reading the documentation for the master branch. -[View documentation for the latest release (1.4.0).](https://github.com/carhartl/jquery-cookie/tree/v1.4.0)** +[View documentation for the latest release (1.4.1).](https://github.com/carhartl/jquery-cookie/tree/v1.4.1)** ## Build Status Matrix diff --git a/bower.json b/bower.json index 8a5b5d0..2d8c25b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.4.0", + "version": "1.4.1", "main": [ "./jquery.cookie.js" ], diff --git a/component.json b/component.json index 6b7122a..58f79d6 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "jquery.cookie", "repo": "carhartl/jquery-cookie", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies", - "version": "1.4.0", + "version": "1.4.1", "keywords": [], "dependencies": {}, "development": {}, diff --git a/cookie.jquery.json b/cookie.jquery.json index 522d5e1..69d5748 100644 --- a/cookie.jquery.json +++ b/cookie.jquery.json @@ -1,6 +1,6 @@ { "name": "cookie", - "version": "1.4.0", + "version": "1.4.1", "title": "jQuery Cookie", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "author": { diff --git a/jquery.cookie.js b/jquery.cookie.js index 211da5c..c7f3a59 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -1,5 +1,5 @@ /*! - * jQuery Cookie Plugin v1.4.0 + * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Klaus Hartl diff --git a/package.json b/package.json index e5493d1..d52070a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.cookie", - "version": "1.4.0", + "version": "1.4.1", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", "main": "jquery.cookie.js", "directories": { From 120dc4cd1bbac59a1b6ce4e80a158b54cda68b81 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 28 Apr 2014 21:59:21 +0200 Subject: [PATCH 098/130] Updating Sauce Labs browsers to test in CI, closes #288 --- Gruntfile.js | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9c30c00..acd3c77 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -65,35 +65,80 @@ module.exports = function (grunt) { build: process.env.TRAVIS_JOB_ID, concurrency: 3, browsers: [ + // iOS { - browserName: 'safari', - platform: 'OS X 10.8' + browserName: 'iphone', + platform: 'OS X 10.9', + version: '7.1' }, { - browserName: 'firefox', - platform: 'Windows 7' + browserName: 'ipad', + platform: 'OS X 10.9', + version: '7.1' }, + // Android { - browserName: 'firefox', - platform: 'Windows XP' + browserName: 'android', + platform: 'Linux', + version: '4.3' }, + // OS X { - browserName: 'firefox', - platform: 'Linux' + browserName: 'safari', + platform: 'OS X 10.9', + version: '7' }, { - browserName: 'chrome', - platform: 'Windows 7' + browserName: 'safari', + platform: 'OS X 10.8', + version: '6' + }, + // Windows + { + browserName: 'internet explorer', + platform: 'Windows 8.1', + version: '11' }, { browserName: 'internet explorer', platform: 'Windows 8', version: '10' }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '11' + }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '10' + }, { browserName: 'internet explorer', platform: 'Windows 7', version: '9' + }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '8' + }, + { + browserName: 'firefox', + platform: 'Windows 7', + version: '28' + }, + { + browserName: 'chrome', + platform: 'Windows 7', + version: '34' + }, + // Linux + { + browserName: 'firefox', + platform: 'Linux', + version: '28' } ], testname: 'jquery.cookie qunit tests' From 288af0659a8371fa1128133f1205eac3afb4633a Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 6 May 2014 09:54:31 +0200 Subject: [PATCH 099/130] Updating to use latest Firefox for Sauce Labs CI --- Gruntfile.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index acd3c77..cb0df23 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -93,6 +93,11 @@ module.exports = function (grunt) { platform: 'OS X 10.8', version: '6' }, + { + browserName: 'firefox', + platform: 'OS X 10.9', + version: '28' + }, // Windows { browserName: 'internet explorer', @@ -127,7 +132,7 @@ module.exports = function (grunt) { { browserName: 'firefox', platform: 'Windows 7', - version: '28' + version: '29' }, { browserName: 'chrome', @@ -138,7 +143,7 @@ module.exports = function (grunt) { { browserName: 'firefox', platform: 'Linux', - version: '28' + version: '29' } ], testname: 'jquery.cookie qunit tests' From e2a881c9694a39b57cb7eff8a4f64ebd6a144456 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Tue, 6 May 2014 10:03:30 +0200 Subject: [PATCH 100/130] Update jQuery used in the tests --- test/index.html | 2 +- test/malformed_cookie.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.html b/test/index.html index 1a6016b..2c0aec1 100644 --- a/test/index.html +++ b/test/index.html @@ -4,7 +4,7 @@ jquery.cookie Test Suite - + diff --git a/test/malformed_cookie.html b/test/malformed_cookie.html index b4a3f78..3aab83f 100644 --- a/test/malformed_cookie.html +++ b/test/malformed_cookie.html @@ -2,7 +2,7 @@ - + - + From e9fe5559e4b69aedf6a916a3e27e2a8cfda6f079 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 21:51:57 +0200 Subject: [PATCH 102/130] Use `grunt connect:server:keepalive` to start a server, removing the one in test. Closes #287. --- CONTRIBUTING.md | 6 +++--- test/server.js | 24 ------------------------ 2 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 test/server.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f174678..50ef6d5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,7 @@ We use the following tools for development: - [Qunit](http://qunitjs.com/) for tests. -- [NodeJS](http://nodejs.org/download/) required to run grunt and the test server only. +- [NodeJS](http://nodejs.org/download/) required to run grunt. - [Grunt](http://gruntjs.com/getting-started) for task management. ###Getting started @@ -39,11 +39,11 @@ You should see a green message in the console: You can also run the tests in the browser. Start a test server from the project root: - $ node test/server.js + $ grunt connect:server:keepalive Open the following URL in a browser: - $ open http://0.0.0.0:8124/test/index.html + $ open http://127.0.0.1:9999/test/index.html _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/test/server.js b/test/server.js deleted file mode 100644 index 8d2e712..0000000 --- a/test/server.js +++ /dev/null @@ -1,24 +0,0 @@ -var http = require('http'); -var url = require('url'); -var path = require('path'); -var fs = require('fs'); - -http.createServer(function(request, response) { - var uri = url.parse(request.url).pathname; - var filename = path.join(process.cwd(), uri); - - fs.readFile(filename, 'binary', function(err, file) { - if (err) { - response.writeHead(500, { 'Content-Type': 'text/plain' }); - response.write(err + '\n'); - response.end(); - return; - } - - response.writeHead(200, filename.match(/\.js$/) ? { 'Content-Type': 'text/javascript' } : {}); - response.write(file, 'utf-8'); - response.end(); - }); -}).listen(8124, '0.0.0.0'); - -console.log('Test suite at http://0.0.0.0:8124/test/index.html'); From c5ad0163f0259553b6933f3ef72f80c80db5fa9c Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 22:07:54 +0200 Subject: [PATCH 103/130] Fixing indentation in the yaml --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b65fdbd..d479758 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: node_js node_js: -- 0.8 + - 0.8 before_script: -- npm install -g grunt-cli + - npm install -g grunt-cli script: grunt ci --verbose env: global: - - secure: HRae0kyIDDuhonvMi2SfEl1WJb4K/wX8WmzT9YkxFbmWwLjiOMkmqyuEyi76DbTC1cb9o7WwGVgbP1DhSm6n6m0Lz+PSzpprBN4QZuJc56jcc+tBA6gM81hyUufaTT0yUWz112Bu06kWIAs44w5PtG0FYZR0CuIN8fQvZi8fXCQ= - - secure: c+M5ECIfxDcVrr+ZlqgpGjv8kVM/hxiz3ACMCn4ZkDiaeq4Rw0wWIGZYL6aV5fhsoHgzEQ/XQPca8xKs3Umr7R3b6Vr3AEyFnW+LP67K/1Qbz4Pi3PvhDH/h4rvK7fOoTqTDCVVDEH3v4pefsz2VaKemG4iBKxrcof5aR4Rjopk= + - secure: HRae0kyIDDuhonvMi2SfEl1WJb4K/wX8WmzT9YkxFbmWwLjiOMkmqyuEyi76DbTC1cb9o7WwGVgbP1DhSm6n6m0Lz+PSzpprBN4QZuJc56jcc+tBA6gM81hyUufaTT0yUWz112Bu06kWIAs44w5PtG0FYZR0CuIN8fQvZi8fXCQ= + - secure: c+M5ECIfxDcVrr+ZlqgpGjv8kVM/hxiz3ACMCn4ZkDiaeq4Rw0wWIGZYL6aV5fhsoHgzEQ/XQPca8xKs3Umr7R3b6Vr3AEyFnW+LP67K/1Qbz4Pi3PvhDH/h4rvK7fOoTqTDCVVDEH3v4pefsz2VaKemG4iBKxrcof5aR4Rjopk= From da0e4ac0904eab8bc609c10620e19bb1abc0aa91 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 22:08:42 +0200 Subject: [PATCH 104/130] Updating node version to use in CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d479758..bfd8ca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 0.8 + - 0.10 before_script: - npm install -g grunt-cli script: grunt ci --verbose From 1f14c0053ea8f1a77144871ffdc2334a1ea5bbae Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 23:22:54 +0200 Subject: [PATCH 105/130] Adding a connect:tests task, to automatically open tests in the default browser. Updating grunt-contrib-connect. --- CONTRIBUTING.md | 6 ++---- Gruntfile.js | 17 ++++++++++++++--- package.json | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 50ef6d5..7bcfcfa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,11 +39,9 @@ You should see a green message in the console: You can also run the tests in the browser. Start a test server from the project root: - $ grunt connect:server:keepalive + $ grunt connect:tests -Open the following URL in a browser: - - $ open http://127.0.0.1:9999/test/index.html +This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser. _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/Gruntfile.js b/Gruntfile.js index cb0df23..bf0e538 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -49,12 +49,23 @@ module.exports = function (grunt) { } }, connect: { - server: { + all: { options: { base: '.', - directory: 'test', + directory: 'test' + } + }, + saucelabs: { + options: { port: 9999 } + }, + tests: { + options: { + open: 'http://127.0.0.1:9998/test/index.html', + keepalive: true, + port: 9998 + } } }, 'saucelabs-qunit': { @@ -160,6 +171,6 @@ module.exports = function (grunt) { } grunt.registerTask('default', ['jshint', 'qunit', 'uglify', 'compare_size']); - grunt.registerTask('saucelabs', ['connect', 'saucelabs-qunit']); + grunt.registerTask('saucelabs', ['connect:saucelabs', 'saucelabs-qunit']); grunt.registerTask('ci', ['jshint', 'qunit', 'saucelabs']); }; diff --git a/package.json b/package.json index d52070a..b56857e 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "grunt-contrib-watch": "~0.3.0", "grunt-compare-size": "~0.4.0", "grunt-saucelabs": "~4.1.1", - "grunt-contrib-connect": "~0.5.0", + "grunt-contrib-connect": "~0.7.1", "gzip-js": "~0.3.0" }, "volo": { From f2b6b252b01cb24a5619744730022d860d3215e1 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 9 May 2014 23:49:19 +0200 Subject: [PATCH 106/130] Enable livereload for test suite when opened in the browser via grunt task --- CONTRIBUTING.md | 2 +- Gruntfile.js | 6 +++++- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7bcfcfa..7ad0146 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ Start a test server from the project root: $ grunt connect:tests -This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser. +This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser, with livereload enabled. _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/Gruntfile.js b/Gruntfile.js index bf0e538..9751c56 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,6 +29,9 @@ module.exports = function (grunt) { } }, watch: { + options: { + livereload: true + }, files: [ 'jquery.cookie.js', 'test/tests.js' @@ -62,9 +65,10 @@ module.exports = function (grunt) { }, tests: { options: { + port: 9998, open: 'http://127.0.0.1:9998/test/index.html', keepalive: true, - port: 9998 + livereload: true } } }, diff --git a/package.json b/package.json index b56857e..e865106 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "grunt-contrib-jshint": "~0.4.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-qunit": "~0.2.0", - "grunt-contrib-watch": "~0.3.0", + "grunt-contrib-watch": "~0.6.1", "grunt-compare-size": "~0.4.0", "grunt-saucelabs": "~4.1.1", "grunt-contrib-connect": "~0.7.1", From e3a19c3e6dbd7c3ebd4a350bee7d8de1dd4dafed Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Thu, 29 May 2014 00:08:05 +0200 Subject: [PATCH 107/130] Improving Readme --- README.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f9a7494..0a6f08e 100644 --- a/README.md +++ b/README.md @@ -27,42 +27,47 @@ The plugin can also be loaded as AMD or CommonJS module. Create session cookie: ```javascript -$.cookie('the_cookie', 'the_value'); +$.cookie('name', 'value'); ``` Create expiring cookie, 7 days from then: ```javascript -$.cookie('the_cookie', 'the_value', { expires: 7 }); +$.cookie('name', 'value', { expires: 7 }); ``` Create expiring cookie, valid across entire site: ```javascript -$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); +$.cookie('name', 'value', { expires: 7, path: '/' }); ``` Read cookie: ```javascript -$.cookie('the_cookie'); // => "the_value" -$.cookie('not_existing'); // => undefined +$.cookie('name'); // => "value" +$.cookie('nothing'); // => undefined ``` Read all available cookies: ```javascript -$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } +$.cookie(); // => { "name": "value" } ``` Delete cookie: ```javascript -// Returns true when cookie was found, false when no cookie was found... -$.removeCookie('the_cookie'); - -// Same path as when the cookie was written... -$.removeCookie('the_cookie', { path: '/' }); +// Returns true when cookie was successfully deleted, otherwise false +$.removeCookie('name'); // => true +$.removeCookie('nothing'); // => false + +// Need to use the same attributes (path, domain) as what the cookie was written with +$.cookie('name', 'value', { path: '/' }); +// This won't work! +$.removeCookie('name'); // => false +// This will work! +$.removeCookie('name', { path: '/' }); // => true ``` *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.* From f81174035cc52298efb5a31afc86026516ad29ca Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 21:45:19 +0200 Subject: [PATCH 108/130] Updating grunt-saucelabs package. Required a workaround for exposing test results to the Sauce Labs API. --- Gruntfile.js | 5 +---- package.json | 2 +- test/tests.js | 8 ++++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9751c56..5b44abb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,9 +76,7 @@ module.exports = function (grunt) { all: { options: { urls: ['http://127.0.0.1:9999/test/index.html'], - tunnelTimeout: 5, build: process.env.TRAVIS_JOB_ID, - concurrency: 3, browsers: [ // iOS { @@ -160,8 +158,7 @@ module.exports = function (grunt) { platform: 'Linux', version: '29' } - ], - testname: 'jquery.cookie qunit tests' + ] } } } diff --git a/package.json b/package.json index e865106..46c89b5 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "grunt-contrib-qunit": "~0.2.0", "grunt-contrib-watch": "~0.6.1", "grunt-compare-size": "~0.4.0", - "grunt-saucelabs": "~4.1.1", + "grunt-saucelabs": "~7.0.0", "grunt-contrib-connect": "~0.7.1", "gzip-js": "~0.3.0" }, diff --git a/test/tests.js b/test/tests.js index bd32552..008f121 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,3 +1,11 @@ +// Required for exposing test results to the Sauce Labs API. +// Can be removed when the following issue is fixed: +// https://github.com/axemclion/grunt-saucelabs/issues/84 +QUnit.done(function (details) { + window.global_test_results = details; +}); + + var lifecycle = { teardown: function () { $.cookie.defaults = {}; From 18fc9a124d377aaea6f90daa29084ad16571ab9b Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:07:01 +0200 Subject: [PATCH 109/130] Also ignore logs of the form log.1 etc. (created by Sauce Labs) --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index afea911..15812b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules build .sizecache.json -*.log \ No newline at end of file +*.log* From 1a98e9ce0c330d420b70887a02805bb67d0945d8 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:13:00 +0200 Subject: [PATCH 110/130] Removing obsolete options for the connect task --- Gruntfile.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 5b44abb..2f0906e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -52,12 +52,6 @@ module.exports = function (grunt) { } }, connect: { - all: { - options: { - base: '.', - directory: 'test' - } - }, saucelabs: { options: { port: 9999 From 1c710ecf3f3e32c47c8ccf632ac3a8156a4c43f9 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:35:42 +0200 Subject: [PATCH 111/130] Updating grunt-contrib-jshint package. --- Gruntfile.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 2f0906e..3bc12c6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -15,7 +15,7 @@ module.exports = function (grunt) { 'jquery.cookie.js' ], options: { - jshintrc: '.jshintrc' + jshintrc: true } }, uglify: { diff --git a/package.json b/package.json index 46c89b5..b15b7ad 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "readmeFilename": "README.md", "devDependencies": { "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.4.0", + "grunt-contrib-jshint": "~0.10.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-qunit": "~0.2.0", "grunt-contrib-watch": "~0.6.1", From a5aa50fb369bb1b21ba9f928a7da525c6d204061 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Fri, 30 May 2014 22:57:13 +0200 Subject: [PATCH 112/130] Minimal html for QUnit --- test/index.html | 11 ++++------- test/malformed_cookie.html | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/index.html b/test/index.html index 814f60c..841310b 100644 --- a/test/index.html +++ b/test/index.html @@ -1,19 +1,16 @@ - + jquery.cookie Test Suite - + -

jquery.cookie Test Suite

-

-
-

-
    +
    +
    diff --git a/test/malformed_cookie.html b/test/malformed_cookie.html index 3aab83f..17e8db8 100644 --- a/test/malformed_cookie.html +++ b/test/malformed_cookie.html @@ -1,4 +1,4 @@ - + From 3f1f88b72503e7f993508b2caf37b1d4c0d39f4b Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 31 May 2014 00:00:56 +0200 Subject: [PATCH 113/130] Also lint tests. For this, moving jshint options into Gruntfile... Updated options as well. --- .jshintrc | 17 ----------------- Gruntfile.js | 54 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 25 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index a37f48c..0000000 --- a/.jshintrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "boss": true, - "browser": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "expr": true, - "evil": true, - "newcap": true, - "noarg": true, - "undef": true, - "globals": { - "define": true, - "jQuery": true, - "require": true - } -} diff --git a/Gruntfile.js b/Gruntfile.js index 3bc12c6..b90568b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,3 @@ -/*jshint node: true */ - 'use strict'; module.exports = function (grunt) { @@ -10,12 +8,52 @@ module.exports = function (grunt) { all: ['test/index.html'] }, jshint: { - files: [ - 'Gruntfile.js', - 'jquery.cookie.js' - ], options: { - jshintrc: true + curly: true, + eqeqeq: true, + expr: true, + // maxlen: 130, + newcap: true, + noarg: true, + nonbsp: true, + trailing: true, + undef: true, + unused: true + }, + grunt: { + options: { + node: true, + quotmark: 'single' + }, + files: { + src: ['Gruntfile.js'] + } + }, + source: { + options: { + browser: true, + camelcase: true, + jquery: true, + quotmark: 'single', + globals: { + define: true, + require: true + }, + }, + files: { + src: ['jquery.cookie.js'] + } + }, + tests: { + options: { + browser: true, + jquery: true, + qunit: true, + '-W053': true + }, + files: { + src: ['test/**/*.js'] + } } }, uglify: { @@ -34,7 +72,7 @@ module.exports = function (grunt) { }, files: [ 'jquery.cookie.js', - 'test/tests.js' + 'test/**/*.js' ], tasks: 'default' }, From 14557ed5dec32c317bbd426f20e5287a8b9c0f8f Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Mon, 2 Jun 2014 07:40:12 +0200 Subject: [PATCH 114/130] Simplifying test server url... --- CONTRIBUTING.md | 2 +- Gruntfile.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7ad0146..608c33e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ Start a test server from the project root: $ grunt connect:tests -This will automatically open the tests at http://127.0.0.1:9998/test/index.html in the default browser, with livereload enabled. +This will automatically open the test suite at http://127.0.0.1:9998 in the default browser, with livereload enabled. _Note: we recommend cleaning all the browser cookies before running the tests, that can avoid false positive failures._ diff --git a/Gruntfile.js b/Gruntfile.js index b90568b..fd08089 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -92,13 +92,15 @@ module.exports = function (grunt) { connect: { saucelabs: { options: { - port: 9999 + port: 9999, + base: ['.', 'test'] } }, tests: { options: { port: 9998, - open: 'http://127.0.0.1:9998/test/index.html', + base: ['.', 'test'], + open: 'http://127.0.0.1:9998', keepalive: true, livereload: true } @@ -107,7 +109,7 @@ module.exports = function (grunt) { 'saucelabs-qunit': { all: { options: { - urls: ['http://127.0.0.1:9999/test/index.html'], + urls: ['http://127.0.0.1:9999'], build: process.env.TRAVIS_JOB_ID, browsers: [ // iOS From be47cde2a75446930784fde3e15263974599fd16 Mon Sep 17 00:00:00 2001 From: Krinke Date: Sat, 12 Jul 2014 11:23:00 -0300 Subject: [PATCH 115/130] Invalid cookie value should not be a getter Closes gh-308. Closes gh-309. --- jquery.cookie.js | 2 +- test/tests.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/jquery.cookie.js b/jquery.cookie.js index c7f3a59..be1c097 100644 --- a/jquery.cookie.js +++ b/jquery.cookie.js @@ -56,7 +56,7 @@ // Write - if (value !== undefined && !$.isFunction(value)) { + if (arguments.length > 1 && !$.isFunction(value)) { options = $.extend({}, config.defaults, options); if (typeof options.expires === 'number') { diff --git a/test/tests.js b/test/tests.js index 008f121..c016bce 100644 --- a/test/tests.js +++ b/test/tests.js @@ -194,6 +194,18 @@ test('number', function () { strictEqual($.cookie('c'), '1234', 'should write value'); }); +test('null', function () { + expect(1); + $.cookie('c', null); + strictEqual($.cookie('c'), 'null', 'should write value'); +}); + +test('undefined', function () { + expect(1); + $.cookie('c', undefined); + strictEqual($.cookie('c'), 'undefined', 'should write value'); +}); + test('expires option as days from now', function () { expect(1); var sevenDaysFromNow = new Date(); From b106a0e23640281321cf7ced832f6dc8fb88a085 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 14 Jul 2014 21:54:20 +0200 Subject: [PATCH 116/130] Move JSHint config to jshintrc files Follows-up 3f1f88b725. Also: * Moved jquery.cookie.js to src/ directory to allow using a separate configuration for it (also complements /build, and other jQuery plugin repositories). * Simplified Grunt configuration. --- .jshintignore | 2 + .jshintrc | 12 +++++ Gruntfile.js | 61 ++++-------------------- bower.json | 2 +- component.json | 4 +- src/.jshintrc | 12 +++++ jquery.cookie.js => src/jquery.cookie.js | 0 test/.jshintrc | 9 ++++ test/index.html | 2 +- test/malformed_cookie.html | 2 +- 10 files changed, 49 insertions(+), 57 deletions(-) create mode 100644 .jshintignore create mode 100644 .jshintrc create mode 100644 src/.jshintrc rename jquery.cookie.js => src/jquery.cookie.js (100%) create mode 100644 test/.jshintrc diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..e3fbd98 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,2 @@ +build +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..fd016db --- /dev/null +++ b/.jshintrc @@ -0,0 +1,12 @@ +{ + "curly": true, + "eqeqeq": true, + "expr": true, + // "maxlen": 130, + "newcap": true, + "noarg": true, + "nonbsp": true, + "trailing": true, + "undef": true, + "unused": true +} diff --git a/Gruntfile.js b/Gruntfile.js index fd08089..5ac9db5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,3 +1,4 @@ +/*jshint node:true, quotmark:single */ 'use strict'; module.exports = function (grunt) { @@ -5,56 +6,15 @@ module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), qunit: { - all: ['test/index.html'] + all: 'test/index.html' }, jshint: { options: { - curly: true, - eqeqeq: true, - expr: true, - // maxlen: 130, - newcap: true, - noarg: true, - nonbsp: true, - trailing: true, - undef: true, - unused: true + jshintrc: true }, - grunt: { - options: { - node: true, - quotmark: 'single' - }, - files: { - src: ['Gruntfile.js'] - } - }, - source: { - options: { - browser: true, - camelcase: true, - jquery: true, - quotmark: 'single', - globals: { - define: true, - require: true - }, - }, - files: { - src: ['jquery.cookie.js'] - } - }, - tests: { - options: { - browser: true, - jquery: true, - qunit: true, - '-W053': true - }, - files: { - src: ['test/**/*.js'] - } - } + grunt: 'Gruntfile.js', + source: 'src/**/*.js', + tests: 'test/**/*.js' }, uglify: { options: { @@ -62,7 +22,7 @@ module.exports = function (grunt) { }, build: { files: { - 'build/jquery.cookie-<%= pkg.version %>.min.js': 'jquery.cookie.js' + 'build/jquery.cookie-<%= pkg.version %>.min.js': 'src/jquery.cookie.js' } } }, @@ -70,16 +30,13 @@ module.exports = function (grunt) { options: { livereload: true }, - files: [ - 'jquery.cookie.js', - 'test/**/*.js' - ], + files: '{src,test}/**/*.js', tasks: 'default' }, compare_size: { files: [ 'build/jquery.cookie-<%= pkg.version %>.min.js', - 'jquery.cookie.js' + 'src/jquery.cookie.js' ], options: { compress: { diff --git a/bower.json b/bower.json index 2d8c25b..3862b74 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "jquery.cookie", "version": "1.4.1", "main": [ - "./jquery.cookie.js" + "src/jquery.cookie.js" ], "dependencies": { "jquery": ">=1.2" diff --git a/component.json b/component.json index 58f79d6..0fad480 100644 --- a/component.json +++ b/component.json @@ -7,8 +7,8 @@ "dependencies": {}, "development": {}, "license": "MIT", - "main": "jquery.cookie.js", + "main": "src/jquery.cookie.js", "scripts": [ - "jquery.cookie.js" + "src/jquery.cookie.js" ] } diff --git a/src/.jshintrc b/src/.jshintrc new file mode 100644 index 0000000..dcdf6d6 --- /dev/null +++ b/src/.jshintrc @@ -0,0 +1,12 @@ +{ + "browser": true, + "camelcase": true, + "jquery": true, + "quotmark": "single", + "globals": { + "define": true, + "require": true + }, + + "extends": "../.jshintrc" +} diff --git a/jquery.cookie.js b/src/jquery.cookie.js similarity index 100% rename from jquery.cookie.js rename to src/jquery.cookie.js diff --git a/test/.jshintrc b/test/.jshintrc new file mode 100644 index 0000000..bc52b0a --- /dev/null +++ b/test/.jshintrc @@ -0,0 +1,9 @@ +{ + "browser": true, + "jquery": true, + "qunit": true, + + "-W053": true, + + "extends": "../.jshintrc" +} diff --git a/test/index.html b/test/index.html index 841310b..ade6830 100644 --- a/test/index.html +++ b/test/index.html @@ -6,7 +6,7 @@ - + diff --git a/test/malformed_cookie.html b/test/malformed_cookie.html index 17e8db8..74178d4 100644 --- a/test/malformed_cookie.html +++ b/test/malformed_cookie.html @@ -3,7 +3,7 @@ - + try { Object.defineProperty(document, "cookie", { get: function() { return "first=one; ; second=two"; } }); From afc813b033a653999a4d01c11d33626cec346e9f Mon Sep 17 00:00:00 2001 From: Jason Strimpel Date: Tue, 15 Jul 2014 16:32:45 -0700 Subject: [PATCH 117/130] updated main property value --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b15b7ad..1cd08a6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery.cookie", "version": "1.4.1", "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", - "main": "jquery.cookie.js", + "main": "src/jquery.cookie.js", "directories": { "test": "test" }, From ae467e55ff0ff31d4fe61f92e96cb2377d3e70ad Mon Sep 17 00:00:00 2001 From: Tom Taylor Date: Wed, 16 Jul 2014 01:05:42 +0100 Subject: [PATCH 118/130] Removed vars, whitespace, 2 bytes saved gzip --- src/jquery.cookie.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/jquery.cookie.js b/src/jquery.cookie.js index be1c097..648a9dd 100644 --- a/src/jquery.cookie.js +++ b/src/jquery.cookie.js @@ -75,19 +75,20 @@ // Read - var result = key ? undefined : {}; + var result = key ? undefined : {}, // To prevent the for loop in the first place assign an empty array // in case there are no cookies at all. Also prevents odd result when // calling $.cookie(). - var cookies = document.cookie ? document.cookie.split('; ') : []; + cookies = document.cookie ? document.cookie.split('; ') : [], + i = 0, l = cookies.length; - for (var i = 0, l = cookies.length; i < l; i++) { - var parts = cookies[i].split('='); - var name = decode(parts.shift()); - var cookie = parts.join('='); + for (; i < l; i++) { + var parts = cookies[i].split('='), + name = decode(parts.shift()), + cookie = parts.join('='); - if (key && key === name) { + if (key === name) { // If second argument (value) is a function it's a converter... result = read(cookie, value); break; From 9ed982ae82b8204b2d2129f16555cb0b120850ee Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 16 Jul 2014 07:26:57 +0200 Subject: [PATCH 119/130] Fixing references for a couple of package managers after moving plugin into src. See b106a0e23640281321cf7ced832f6dc8fb88a085. --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1cd08a6..38abffe 100644 --- a/package.json +++ b/package.json @@ -29,11 +29,11 @@ "gzip-js": "~0.3.0" }, "volo": { - "url": "https://raw.github.com/carhartl/jquery-cookie/v{version}/jquery.cookie.js" + "url": "https://raw.github.com/carhartl/jquery-cookie/v{version}/src/jquery.cookie.js" }, "jspm": { "main": "jquery.cookie", - "files": ["jquery.cookie.js"], + "files": ["src/jquery.cookie.js"], "buildConfig": { "uglify": true } @@ -42,9 +42,9 @@ "dependencies": { "jquery": ">=1.2" }, - "main": "jquery.cookie.js", + "main": "src/jquery.cookie.js", "include": [ - "jquery.cookie.js" + "src/jquery.cookie.js" ] } } From aeb793d27286c7f0b915c3aaee24c3b7d04d71fd Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 16 Jul 2014 07:30:01 +0200 Subject: [PATCH 120/130] Updating copyright --- src/jquery.cookie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.cookie.js b/src/jquery.cookie.js index be1c097..feb62e9 100644 --- a/src/jquery.cookie.js +++ b/src/jquery.cookie.js @@ -2,7 +2,7 @@ * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * - * Copyright 2013 Klaus Hartl + * Copyright 2006, 2014 Klaus Hartl * Released under the MIT license */ (function (factory) { From f12dce392ae87bcc50ee76d57ab8e59f60f522d6 Mon Sep 17 00:00:00 2001 From: Konstantinos Vaggelakos Date: Wed, 26 Nov 2014 01:56:27 +0100 Subject: [PATCH 121/130] Commonjs export fix and jshint updates --- .jshintrc | 5 ++++- src/jquery.cookie.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.jshintrc b/.jshintrc index fd016db..f3ae239 100644 --- a/.jshintrc +++ b/.jshintrc @@ -8,5 +8,8 @@ "nonbsp": true, "trailing": true, "undef": true, - "unused": true + "unused": true, + "globals": { + "module": true + } } diff --git a/src/jquery.cookie.js b/src/jquery.cookie.js index feb62e9..2b076a7 100644 --- a/src/jquery.cookie.js +++ b/src/jquery.cookie.js @@ -11,7 +11,7 @@ define(['jquery'], factory); } else if (typeof exports === 'object') { // CommonJS - factory(require('jquery')); + module.exports = factory(require('jquery')); } else { // Browser globals factory(jQuery); From 17884203d14afc4eb4954cb8f584c269901756be Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 18 Mar 2015 21:15:56 +0100 Subject: [PATCH 122/130] Moving around jshint configuration to where it belongs --- .jshintrc | 5 +---- src/.jshintrc | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.jshintrc b/.jshintrc index f3ae239..fd016db 100644 --- a/.jshintrc +++ b/.jshintrc @@ -8,8 +8,5 @@ "nonbsp": true, "trailing": true, "undef": true, - "unused": true, - "globals": { - "module": true - } + "unused": true } diff --git a/src/.jshintrc b/src/.jshintrc index dcdf6d6..241dd9f 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -5,6 +5,7 @@ "quotmark": "single", "globals": { "define": true, + "module": true, "require": true }, From 8b28ab2091e966b78f8d901df02e317e00bcde6b Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 18 Mar 2015 21:17:11 +0100 Subject: [PATCH 123/130] Improving comments somewhat --- src/jquery.cookie.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.cookie.js b/src/jquery.cookie.js index 2b076a7..8deb387 100644 --- a/src/jquery.cookie.js +++ b/src/jquery.cookie.js @@ -7,10 +7,10 @@ */ (function (factory) { if (typeof define === 'function' && define.amd) { - // AMD + // AMD (Register as an anonymous module) define(['jquery'], factory); } else if (typeof exports === 'object') { - // CommonJS + // Node/CommonJS module.exports = factory(require('jquery')); } else { // Browser globals From 07e593d8fb8913867e357b6ddee3f7f6a05c35e7 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 18 Mar 2015 21:34:39 +0100 Subject: [PATCH 124/130] Trying to improve readability a bit --- src/jquery.cookie.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jquery.cookie.js b/src/jquery.cookie.js index 5b0f45d..3f5a205 100644 --- a/src/jquery.cookie.js +++ b/src/jquery.cookie.js @@ -76,12 +76,12 @@ // Read var result = key ? undefined : {}, - - // To prevent the for loop in the first place assign an empty array - // in case there are no cookies at all. Also prevents odd result when - // calling $.cookie(). + // To prevent the for loop in the first place assign an empty array + // in case there are no cookies at all. Also prevents odd result when + // calling $.cookie(). cookies = document.cookie ? document.cookie.split('; ') : [], - i = 0, l = cookies.length; + i = 0, + l = cookies.length; for (; i < l; i++) { var parts = cookies[i].split('='), From 41b1bad52a029e75f68676024a559dd0142fcb67 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 18 Mar 2015 22:04:51 +0100 Subject: [PATCH 125/130] Fix computation of the expires date to consider a local daylight saving time change Avoid being too clever, using Date.setTime() that is. Fixes #331. --- src/jquery.cookie.js | 2 +- test/tests.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jquery.cookie.js b/src/jquery.cookie.js index 3f5a205..393c01d 100644 --- a/src/jquery.cookie.js +++ b/src/jquery.cookie.js @@ -61,7 +61,7 @@ if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new Date(); - t.setTime(+t + days * 864e+5); + t.setMilliseconds(t.getMilliseconds() + days * 864e+5); } return (document.cookie = [ diff --git a/test/tests.js b/test/tests.js index c016bce..5f1a1f1 100644 --- a/test/tests.js +++ b/test/tests.js @@ -209,8 +209,8 @@ test('undefined', function () { test('expires option as days from now', function () { expect(1); var sevenDaysFromNow = new Date(); - sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); - strictEqual($.cookie('c', 'v', { expires: 7 }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), + sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 21); + strictEqual($.cookie('c', 'v', { expires: 21 }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), 'should write the cookie string with expires'); }); From 4527b3725ce7b61066e6aa12bbe8d20c0371a1d7 Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Wed, 18 Mar 2015 22:26:54 +0100 Subject: [PATCH 126/130] Fix removing cookies in sub paths When trying to remove a cookie in a sub path (defined via path), we can't first try to read the cookie in a guard clause, it won't be readable and thus the removal was not even attempted. So I'm removing the guard clause entirely. On second thought its return value was also wrong anyway: when attempting to remove a non-existing cookie, after the removal it still doesn't exist and the removeCookie() should therefore return false. Closes #336. --- src/jquery.cookie.js | 4 ---- test/tests.js | 10 +++++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/jquery.cookie.js b/src/jquery.cookie.js index 393c01d..8218817 100644 --- a/src/jquery.cookie.js +++ b/src/jquery.cookie.js @@ -106,10 +106,6 @@ config.defaults = {}; $.removeCookie = function (key, options) { - if ($.cookie(key) === undefined) { - return false; - } - // Must not alter options, thus extending a fresh object... $.cookie(key, '', $.extend({}, options, { expires: -1 })); return !$.cookie(key); diff --git a/test/tests.js b/test/tests.js index 5f1a1f1..68b47cc 100644 --- a/test/tests.js +++ b/test/tests.js @@ -282,6 +282,11 @@ test('when sucessfully deleted', function () { strictEqual($.removeCookie('c'), true, 'returns true'); }); +test('when cookie does not exist', function () { + expect(1); + strictEqual($.removeCookie('c'), true, 'returns true'); +}); + test('when deletion failed', function () { expect(1); $.cookie('c', 'v'); @@ -299,11 +304,6 @@ test('when deletion failed', function () { $.cookie = originalCookie; }); -test('when cookie does not exist', function () { - expect(1); - strictEqual($.removeCookie('c'), false, 'returns false'); -}); - test('with options', function () { expect(1); var options = { path: '/' }; From 6d5b9190b446b68e13b45d0b7d78c7ba4a62cb65 Mon Sep 17 00:00:00 2001 From: Fagner Brack Date: Thu, 9 Apr 2015 03:48:53 -0300 Subject: [PATCH 127/130] Add notice --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 0a6f08e..4633b97 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +# IMPORTANT! + +This project is being moved to [Javascript Cookie](https://github.com/js-cookie/js-cookie), an implementation of jquery-cookie without jQuery. + +For more information check [the discussion](https://github.com/carhartl/jquery-cookie/issues/349). + +New issues should be opened in [js-cookie bug tracker](https://github.com/js-cookie/js-cookie/issues). + # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) A simple, lightweight jQuery plugin for reading, writing and deleting cookies. From 06e4e3a1d189bb18356c3aa337b055166a52916e Mon Sep 17 00:00:00 2001 From: Klaus Hartl Date: Sat, 18 Apr 2015 09:58:51 +0200 Subject: [PATCH 128/130] Correct spelling --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4633b97..47198c6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IMPORTANT! -This project is being moved to [Javascript Cookie](https://github.com/js-cookie/js-cookie), an implementation of jquery-cookie without jQuery. +This project is being moved to [JavaScript Cookie](https://github.com/js-cookie/js-cookie), an implementation of jquery-cookie without jQuery. For more information check [the discussion](https://github.com/carhartl/jquery-cookie/issues/349). From 636c27d72cc1e4eec53fade4f74f4b35570cd6b8 Mon Sep 17 00:00:00 2001 From: Fagner Brack Date: Sat, 25 Apr 2015 11:10:33 -0300 Subject: [PATCH 129/130] Make the notice clearer and more direct Also provide the latest backwards compatible release link in the bold section --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 47198c6..59ebd16 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,13 @@ # IMPORTANT! -This project is being moved to [JavaScript Cookie](https://github.com/js-cookie/js-cookie), an implementation of jquery-cookie without jQuery. - -For more information check [the discussion](https://github.com/carhartl/jquery-cookie/issues/349). - -New issues should be opened in [js-cookie bug tracker](https://github.com/js-cookie/js-cookie/issues). +This project was moved to https://github.com/js-cookie/js-cookie, check [the discussion](https://github.com/carhartl/jquery-cookie/issues/349). # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) A simple, lightweight jQuery plugin for reading, writing and deleting cookies. -**If you're viewing this at https://github.com/carhartl/jquery-cookie, you're reading the documentation for the master branch. -[View documentation for the latest release (1.4.1).](https://github.com/carhartl/jquery-cookie/tree/v1.4.1)** +**If you're viewing this, you're reading the documentation for the old repository. +[View documentation for the latest backwards compatible release (1.5.1).](https://github.com/js-cookie/js-cookie/tree/v1.5.1)** ## Build Status Matrix From d72bb07e29962330db61aae1eda07f6312419840 Mon Sep 17 00:00:00 2001 From: Fagner Brack Date: Wed, 27 May 2015 12:36:08 -0300 Subject: [PATCH 130/130] Make it clear where to open new issues It was added in https://github.com/carhartl/jquery-cookie/commit/6d5b9190b446b68e13b45d0b7d78c7ba4a62cb65 but removed in https://github.com/carhartl/jquery-cookie/commit/636c27d72cc1e4eec53fade4f74f4b35570cd6b8. Adding it again since 2 new issues were created after the removal: gh-362, gh-363 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 59ebd16..3100800 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This project was moved to https://github.com/js-cookie/js-cookie, check [the discussion](https://github.com/carhartl/jquery-cookie/issues/349). +New issues should be opened at https://github.com/js-cookie/js-cookie/issues + # jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://codeclimate.com/github/carhartl/jquery-cookie.png)](https://codeclimate.com/github/carhartl/jquery-cookie) A simple, lightweight jQuery plugin for reading, writing and deleting cookies.