[Pkg-javascript-commits] [jquery-goodies] 01/09: Updated jQuery cookie

Marcelo Jorge Vieira metal at moszumanska.debian.org
Sun Jun 29 03:14:28 UTC 2014


This is an automated email from the git hooks/post-receive script.

metal pushed a commit to branch master
in repository jquery-goodies.

commit fc1bd7274de838bc398e245884f8435f0012f6b5
Author: Marcelo Jorge Vieira <metal at alucinados.com>
Date:   Sat Jun 28 21:37:57 2014 -0300

    Updated jQuery cookie
---
 cookie/CHANGELOG.md       |  8 ++++++
 cookie/MIT-LICENSE.txt    |  4 +--
 cookie/README.md          | 13 +++++++---
 cookie/bower.json         |  2 +-
 cookie/component.json     | 14 ++++++++++
 cookie/cookie.jquery.json |  2 +-
 cookie/jquery.cookie.js   | 30 ++++++++++-----------
 cookie/package.json       | 23 +++++++++++++++--
 cookie/test/tests.js      | 66 +++++++++++++++++++++++++++++++----------------
 9 files changed, 115 insertions(+), 47 deletions(-)

diff --git a/cookie/CHANGELOG.md b/cookie/CHANGELOG.md
index 467dd42..59d868f 100644
--- a/cookie/CHANGELOG.md
+++ b/cookie/CHANGELOG.md
@@ -1,6 +1,14 @@
 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).
+
+- The expires option now interpretes fractions of numbers (e.g. days) correctly.
+
 1.4.0
 -----
 - Support for AMD.
diff --git a/cookie/MIT-LICENSE.txt b/cookie/MIT-LICENSE.txt
index 8ae647b..7a631e8 100644
--- a/cookie/MIT-LICENSE.txt
+++ b/cookie/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.
diff --git a/cookie/README.md b/cookie/README.md
index 7377611..f9a7494 100644
--- a/cookie/README.md
+++ b/cookie/README.md
@@ -1,9 +1,14 @@
-# jquery.cookie [![Build Status](https://travis-ci.org/carhartl/jquery-cookie.png?branch=master)](https://travis-ci.org/carhartl/jquery-cookie)
-
-[![Selenium Test Status](https://saucelabs.com/browser-matrix/carhartl.svg)](https://saucelabs.com/u/carhartl)
+# 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)**
+
+## 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):
@@ -15,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/cookie/bower.json b/cookie/bower.json
index 8a5b5d0..2d8c25b 100644
--- a/cookie/bower.json
+++ b/cookie/bower.json
@@ -1,6 +1,6 @@
 {
   "name": "jquery.cookie",
-  "version": "1.4.0",
+  "version": "1.4.1",
   "main": [
     "./jquery.cookie.js"
   ],
diff --git a/cookie/component.json b/cookie/component.json
new file mode 100644
index 0000000..58f79d6
--- /dev/null
+++ b/cookie/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.1",
+  "keywords": [],
+  "dependencies": {},
+  "development": {},
+  "license": "MIT",
+  "main": "jquery.cookie.js",
+  "scripts": [
+    "jquery.cookie.js"
+  ]
+}
diff --git a/cookie/cookie.jquery.json b/cookie/cookie.jquery.json
index 522d5e1..69d5748 100644
--- a/cookie/cookie.jquery.json
+++ b/cookie/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/cookie/jquery.cookie.js b/cookie/jquery.cookie.js
index 9271900..c7f3a59 100644
--- a/cookie/jquery.cookie.js
+++ b/cookie/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
@@ -7,10 +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 ($) {
@@ -38,13 +41,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) {}
 	}
@@ -57,12 +55,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 = [
@@ -106,12 +105,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/cookie/package.json b/cookie/package.json
index 3942d32..d52070a 100644
--- a/cookie/package.json
+++ b/cookie/package.json
@@ -1,8 +1,8 @@
 {
   "name": "jquery.cookie",
-  "version": "1.4.0",
+  "version": "1.4.1",
   "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.",
-  "main": "Gruntfile.js",
+  "main": "jquery.cookie.js",
   "directories": {
     "test": "test"
   },
@@ -27,5 +27,24 @@
     "grunt-saucelabs": "~4.1.1",
     "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"],
+    "buildConfig": {
+      "uglify": true
+    }
+  },
+  "jam": {
+    "dependencies": {
+      "jquery": ">=1.2"
+    },
+    "main": "jquery.cookie.js",
+    "include": [
+      "jquery.cookie.js"
+    ]
   }
 }
diff --git a/cookie/test/tests.js b/cookie/test/tests.js
index c5c3171..bd32552 100644
--- a/cookie/test/tests.js
+++ b/cookie/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');
 });
 
 
@@ -189,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);
+
+	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
+	// 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();
@@ -213,7 +230,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 +256,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");
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/jquery-goodies.git



More information about the Pkg-javascript-commits mailing list