Skip to content

Commit 35377d7

Browse files
committed
README instead of inline documentation
1 parent 3b456a1 commit 35377d7

2 files changed

Lines changed: 57 additions & 50 deletions

File tree

‎README‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
2+
3+
== Usage
4+
5+
// Create session cookie...
6+
$.cookie('the_cookie', 'the_value');
7+
8+
// Create expiring cookie, 7 days from then...
9+
$.cookie('the_cookie', 'the_value', { expires: 7 });
10+
11+
// Create expiring cookie, valid across entire page...
12+
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
13+
14+
// Read cookie...
15+
$.cookie('the_cookie'); // => 'the_value'
16+
$.cookie('not_existing'); // => null
17+
18+
// Delete cookie by passing null as value...
19+
$.cookie('the_cookie', null);
20+
21+
== Options
22+
23+
expires: 365
24+
25+
Define lifetimew of the cookie. Value can be a `Number` (which will be interpreted as days from creation) or a `Date` object.
26+
If omitted, the cookie becomes a session cookie.
27+
28+
path: '/',
29+
30+
Default: path of page where the cookie was created. Define the path where cookie is valid. *Note:* By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior).
31+
If you want to make it available for instance across the entire page use `path: '/'`.
32+
33+
If you want to delete a cookie with a particular path, you need to include that path in the call.
34+
35+
domain: 'example.com'
36+
37+
Default: domain of page where the cookie was created.
38+
39+
secure: true
40+
41+
Default: false. If true, the cookie transmission requires a secure protocol (https).
42+
43+
raw: true
44+
45+
Default: false. By default the cookie is encoded/decoded when creating/reading, using `encodeURIComponent`/`decodeURIComponent`.
46+
Turn off by setting `raw: true`.
47+
48+
== Development
49+
50+
- Source hosted at {GitHub}[https://github.com/carhartl/jquery-cookie]
51+
- Report issues, questions, feature requests on {GitHub Issues}[https://github.com/carhartl/jquery-cookie/issues]
52+
53+
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change you make.
54+
55+
== Authors
56+
57+
{Klaus Hartl}[https://github.com/carhartl]

‎jquery.cookie.js‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*jslint browser: true */ /*global jQuery: true */
2-
31
/**
42
* jQuery Cookie plugin
53
*
@@ -9,54 +7,6 @@
97
* http://www.gnu.org/licenses/gpl.html
108
*
119
*/
12-
13-
// TODO JsDoc
14-
15-
/**
16-
* Create a cookie with the given key and value and other optional parameters.
17-
*
18-
* @example $.cookie('the_cookie', 'the_value');
19-
* @desc Set the value of a cookie.
20-
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
21-
* @desc Create a cookie with all available options.
22-
* @example $.cookie('the_cookie', 'the_value');
23-
* @desc Create a session cookie.
24-
* @example $.cookie('the_cookie', null);
25-
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
26-
* used when the cookie was set.
27-
*
28-
* @param String key The key of the cookie.
29-
* @param String value The value of the cookie.
30-
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
31-
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
32-
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
33-
* If set to null or omitted, the cookie will be a session cookie and will not be retained
34-
* when the the browser exits.
35-
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
36-
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
37-
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
38-
* require a secure protocol (like HTTPS).
39-
* @type undefined
40-
*
41-
* @name $.cookie
42-
* @cat Plugins/Cookie
43-
* @author Klaus Hartl/klaus.hartl@stilbuero.de
44-
*/
45-
46-
/**
47-
* Get the value of a cookie with the given key.
48-
*
49-
* @example $.cookie('the_cookie');
50-
* @desc Get the value of a cookie.
51-
*
52-
* @param String key The key of the cookie.
53-
* @return The value of the cookie.
54-
* @type String
55-
*
56-
* @name $.cookie
57-
* @cat Plugins/Cookie
58-
* @author Klaus Hartl/klaus.hartl@stilbuero.de
59-
*/
6010
jQuery.cookie = function (key, value, options) {
6111

6212
// key and at least value given, set cookie...

0 commit comments

Comments
 (0)