Index: community/index.html =================================================================== diff -u -r32f9a5158ad5e1376803419c525edb989f0b3f24 -rfed2cd412158042c66c3311b5973579e75af4115 --- community/index.html (.../index.html) (revision 32f9a5158ad5e1376803419c525edb989f0b3f24) +++ community/index.html (.../index.html) (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -111,18 +111,17 @@ rel="stylesheet" /> - - - + + + + - + - + - + @@ -186,24 +185,6 @@ - - - +``` + +**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 or CommonJS module. + +## Usage + +Create session cookie: + +```javascript +$.cookie('the_cookie', 'the_value'); +``` + +Create expiring cookie, 7 days from then: + +```javascript +$.cookie('the_cookie', 'the_value', { expires: 7 }); +``` + +Create expiring cookie, valid across entire site: + +```javascript +$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); +``` + +Read cookie: + +```javascript +$.cookie('the_cookie'); // => "the_value" +$.cookie('not_existing'); // => undefined +``` + +Read all available cookies: + +```javascript +$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } +``` + +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: '/' }); +``` + +*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.* + +## Configuration + +### raw + +By default the cookie value is encoded/decoded when writing/reading, using `encodeURIComponent`/`decodeURIComponent`. Bypass this by setting raw to true: + +```javascript +$.cookie.raw = true; +``` + +### json + +Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`: + +```javascript +$.cookie.json = true; +``` + +## Cookie Options + +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 + + 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`. + +## Converters + +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: + +```javascript +$.cookie('foo', '42'); +$.cookie('foo', Number); // => 42 +``` + +Dealing with cookies that have been encoded using `escape` (3rd party cookies): + +```javascript +$.cookie.raw = true; +$.cookie('foo', unescape); +``` + +You can pass an arbitrary conversion function. + +## Contributing + +Check out the [Contributing Guidelines](CONTRIBUTING.md) + +## Authors + +[Klaus Hartl](https://github.com/carhartl) Index: reference/jquery-plugins/jquery-cookie-1.4.1/bower.json =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/bower.json (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/bower.json (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,18 @@ +{ + "name": "jquery.cookie", + "version": "1.4.1", + "main": [ + "./jquery.cookie.js" + ], + "dependencies": { + "jquery": ">=1.2" + }, + "ignore": [ + "test", + ".*", + "*.json", + "*.md", + "*.txt", + "Gruntfile.js" + ] +} Index: reference/jquery-plugins/jquery-cookie-1.4.1/component.json =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/component.json (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/component.json (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -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" + ] +} Index: reference/jquery-plugins/jquery-cookie-1.4.1/cookie.jquery.json =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/cookie.jquery.json (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/cookie.jquery.json (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,32 @@ +{ + "name": "cookie", + "version": "1.4.1", + "title": "jQuery Cookie", + "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", + "author": { + "name": "Klaus Hartl", + "url": "https://github.com/carhartl" + }, + "maintainers": [ + { + "name": "Klaus Hartl", + "url": "https://github.com/carhartl" + }, + { + "name": "Fagner Martins", + "url": "https://github.com/FagnerMartinsBrack" + } + ], + "licenses": [ + { + "type": "MIT", + "url": "https://raw.github.com/carhartl/jquery-cookie/master/MIT-LICENSE.txt" + } + ], + "dependencies": { + "jquery": ">=1.2" + }, + "bugs": "https://github.com/carhartl/jquery-cookie/issues", + "homepage": "https://github.com/carhartl/jquery-cookie", + "docs": "https://github.com/carhartl/jquery-cookie#readme" +} Index: reference/jquery-plugins/jquery-cookie-1.4.1/jquery.cookie.js =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/jquery.cookie.js (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/jquery.cookie.js (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,117 @@ +/*! + * jQuery Cookie Plugin v1.4.1 + * https://github.com/carhartl/jquery-cookie + * + * Copyright 2013 Klaus Hartl + * Released under the MIT license + */ +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // CommonJS + factory(require('jquery')); + } else { + // Browser globals + factory(jQuery); + } +}(function ($) { + + var pluses = /\+/g; + + function encode(s) { + return config.raw ? s : encodeURIComponent(s); + } + + function decode(s) { + return config.raw ? s : decodeURIComponent(s); + } + + function stringifyCookieValue(value) { + return encode(config.json ? JSON.stringify(value) : String(value)); + } + + function parseCookieValue(s) { + if (s.indexOf('"') === 0) { + // This is a quoted cookie as according to RFC2068, unescape... + s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); + } + + try { + // Replace server-side written pluses with spaces. + // If we can't decode the cookie, ignore it, it's unusable. + // 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) {} + } + + function read(s, converter) { + var value = config.raw ? s : parseCookieValue(s); + return $.isFunction(converter) ? converter(value) : value; + } + + 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.setTime(+t + days * 864e+5); + } + + return (document.cookie = [ + encode(key), '=', stringifyCookieValue(value), + options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE + options.path ? '; path=' + options.path : '', + options.domain ? '; domain=' + options.domain : '', + options.secure ? '; secure' : '' + ].join('')); + } + + // 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(). + var cookies = document.cookie ? document.cookie.split('; ') : []; + + for (var i = 0, l = cookies.length; i < l; i++) { + var parts = cookies[i].split('='); + var name = decode(parts.shift()); + var cookie = parts.join('='); + + if (key && key === name) { + // If second argument (value) is a function it's a converter... + result = read(cookie, value); + break; + } + + // Prevent storing a cookie that we couldn't decode. + if (!key && (cookie = read(cookie)) !== undefined) { + result[name] = cookie; + } + } + + return result; + }; + + 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); + }; + +})); Index: reference/jquery-plugins/jquery-cookie-1.4.1/package.json =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/package.json (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/package.json (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,50 @@ +{ + "name": "jquery.cookie", + "version": "1.4.1", + "description": "A simple, lightweight jQuery plugin for reading, writing and deleting cookies.", + "main": "jquery.cookie.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "grunt" + }, + "repository": { + "type": "git", + "url": "git://github.com/carhartl/jquery-cookie.git" + }, + "author": "Klaus Hartl", + "license": "MIT", + "gitHead": "bd3c9713222bace68d25fe2128c0f8633cad1269", + "readmeFilename": "README.md", + "devDependencies": { + "grunt": "~0.4.1", + "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-compare-size": "~0.4.0", + "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" + ] + } +} Index: reference/jquery-plugins/jquery-cookie-1.4.1/test/index.html =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/test/index.html (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/test/index.html (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,19 @@ + + + + + jquery.cookie Test Suite + + + + + + + +

jquery.cookie Test Suite

+

+
+

+
    + + Index: reference/jquery-plugins/jquery-cookie-1.4.1/test/malformed_cookie.html =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/test/malformed_cookie.html (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/test/malformed_cookie.html (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,18 @@ + + + + + + + + + + + Index: reference/jquery-plugins/jquery-cookie-1.4.1/test/server.js =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/test/server.js (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/test/server.js (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,24 @@ +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'); Index: reference/jquery-plugins/jquery-cookie-1.4.1/test/tests.js =================================================================== diff -u --- reference/jquery-plugins/jquery-cookie-1.4.1/test/tests.js (revision 0) +++ reference/jquery-plugins/jquery-cookie-1.4.1/test/tests.js (revision fed2cd412158042c66c3311b5973579e75af4115) @@ -0,0 +1,325 @@ +var lifecycle = { + teardown: function () { + $.cookie.defaults = {}; + delete $.cookie.raw; + delete $.cookie.json; + $.each($.cookie(), $.removeCookie); + } +}; + + +module('read', lifecycle); + +test('simple value', function () { + expect(1); + document.cookie = 'c=v'; + strictEqual($.cookie('c'), 'v', 'should return value'); +}); + +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', ''); + strictEqual($.cookie('c'), '', 'should return value'); +}); + +test('not existing', function () { + expect(1); + strictEqual($.cookie('whatever'), undefined, 'return undefined'); +}); + +test('RFC 2068 quoted string', function () { + expect(1); + document.cookie = 'c="v@address.com\\"\\\\\\""'; + strictEqual($.cookie('c'), 'v@address.com"\\"', 'should decode RFC 2068 quoted string'); +}); + +test('decode', function () { + expect(1); + document.cookie = encodeURIComponent(' c') + '=' + encodeURIComponent(' v'); + strictEqual($.cookie(' c'), ' v', 'should decode key and value'); +}); + +test('decode pluses to space for server side written cookie', function () { + expect(1); + document.cookie = 'c=foo+bar'; + strictEqual($.cookie('c'), 'foo bar', 'should convert pluses back to space'); +}); + +test('raw = true', function () { + expect(2); + $.cookie.raw = true; + + document.cookie = 'c=%20v'; + strictEqual($.cookie('c'), '%20v', 'should not decode value'); + + // see https://github.com/carhartl/jquery-cookie/issues/50 + $.cookie('c', 'foo=bar'); + strictEqual($.cookie('c'), 'foo=bar', 'should include the entire value'); +}); + +test('json = true', function () { + expect(1); + + if ('JSON' in window) { + $.cookie.json = true; + $.cookie('c', { foo: 'bar' }); + deepEqual($.cookie('c'), { foo: 'bar' }, 'should parse JSON'); + } else { + ok(true); + } +}); + +test('not existing with json = true', function () { + expect(1); + + if ('JSON' in window) { + $.cookie.json = true; + strictEqual($.cookie('whatever'), undefined, "won't throw exception"); + } else { + ok(true); + } +}); + +test('string with json = true', function () { + expect(1); + + if ('JSON' in window) { + $.cookie.json = true; + $.cookie('c', 'v'); + strictEqual($.cookie('c'), 'v', 'should return value'); + } else { + ok(true); + } +}); + +test('invalid JSON string with json = true', function () { + expect(1); + + if ('JSON' in window) { + $.cookie('c', 'v'); + $.cookie.json = true; + strictEqual($.cookie('c'), undefined, "won't throw exception, returns undefined"); + } else { + ok(true); + } +}); + +test('invalid URL encoding', function () { + expect(1); + document.cookie = 'bad=foo%'; + strictEqual($.cookie('bad'), undefined, "won't throw exception, returns undefined"); + // Delete manually here because it requires raw === true... + $.cookie.raw = true; + $.removeCookie('bad'); +}); + +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 = $('')[0]; + $(iframe).on('load', function () { + start(); + if (iframe.contentWindow.ok) { + strictEqual(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'); + } + }); + document.body.appendChild(iframe); +}); + +test('Call to read all when there are cookies', function () { + $.cookie('c', 'v'); + $.cookie('foo', 'bar'); + deepEqual($.cookie(), { c: 'v', foo: 'bar' }, 'returns object containing all cookies'); +}); + +test('Call to read all when there are no cookies at all', function () { + deepEqual($.cookie(), {}, 'returns empty object'); +}); + +test('Call to read all with json: true', function () { + $.cookie.json = true; + $.cookie('c', { foo: 'bar' }); + deepEqual($.cookie(), { c: { foo: 'bar' } }, 'returns JSON parsed cookies'); +}); + +test('Call to read all with a badly encoded cookie', function () { + expect(1); + 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'); +}); + + +module('write', lifecycle); + +test('String primitive', function () { + expect(1); + $.cookie('c', 'v'); + strictEqual($.cookie('c'), 'v', 'should write value'); +}); + +test('String object', function () { + expect(1); + $.cookie('c', new String('v')); + strictEqual($.cookie('c'), 'v', 'should write value'); +}); + +test('value "[object Object]"', function () { + expect(1); + $.cookie('c', '[object Object]'); + strictEqual($.cookie('c'), '[object Object]', 'should write value'); +}); + +test('number', function () { + expect(1); + $.cookie('c', 1234); + strictEqual($.cookie('c'), '1234', 'should write value'); +}); + +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(), + '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(); + sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); + strictEqual($.cookie('c', 'v', { expires: sevenDaysFromNow }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), + 'should write the cookie string with expires'); +}); + +test('return value', function () { + expect(1); + strictEqual($.cookie('c', 'v'), 'c=v', 'should return written cookie string'); +}); + +test('defaults', function () { + expect(2); + $.cookie.defaults.path = '/foo'; + ok($.cookie('c', 'v').match(/path=\/foo/), 'should use options from defaults'); + ok($.cookie('c', 'v', { path: '/bar' }).match(/path=\/bar/), 'options argument has precedence'); +}); + +test('raw = true', function () { + expect(1); + $.cookie.raw = true; + strictEqual($.cookie('c[1]', 'v[1]'), 'c[1]=v[1]', 'should not encode'); + // Delete manually here because it requires raw === true... + $.removeCookie('c[1]'); +}); + +test('json = true', function () { + expect(1); + $.cookie.json = true; + + if ('JSON' in window) { + $.cookie('c', { foo: 'bar' }); + strictEqual(document.cookie, 'c=' + encodeURIComponent(JSON.stringify({ foo: 'bar' })), 'should stringify JSON'); + } else { + ok(true); + } +}); + + +module('removeCookie', lifecycle); + +test('deletion', function () { + expect(1); + $.cookie('c', 'v'); + $.removeCookie('c'); + strictEqual(document.cookie, '', 'should delete the cookie'); +}); + +test('when sucessfully deleted', function () { + expect(1); + $.cookie('c', 'v'); + strictEqual($.removeCookie('c'), true, 'returns true'); +}); + +test('when deletion failed', function () { + expect(1); + $.cookie('c', 'v'); + + var originalCookie = $.cookie; + $.cookie = function () { + // Stub deletion... + if (arguments.length === 1) { + return originalCookie.apply(null, arguments); + } + }; + + strictEqual($.removeCookie('c'), false, 'returns false'); + + $.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: '/' }; + $.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"); +}); + +test('[] used in name', function () { + expect(1); + $.cookie.raw = true; + document.cookie = 'c[1]=foo'; + $.removeCookie('c[1]'); + strictEqual(document.cookie, '', 'delete the cookie'); +}); + + +module('conversion', lifecycle); + +test('read converter', function() { + expect(1); + $.cookie('c', '1'); + strictEqual($.cookie('c', Number), 1, 'converts read value'); +}); + +test('read converter with raw = true', function() { + expect(1); + $.cookie.raw = true; + $.cookie('c', '1'); + strictEqual($.cookie('c', Number), 1, 'does not decode, but converts read value'); +});