PgwJS
Powered by Pagawa.com

PgwCookie - Cookie plugin for jQuery / Zepto

Download

Current version: 1.4
To download or fork this project, please visit our GitHub repository
And of course, you will need Jquery or Zepto to use this cookies manager plugin.
jquery zepto.js

Example

To create a cookie "myCookie" with the value "test":
$.pgwCookie({ name: 'myCookie', value: 'test' });
To read the cookie "myCookie":
$.pgwCookie({ name: 'myCookie' });
To remove the cookie "myCookie":
$.pgwCookie({ name: 'myCookie', value: null });

Documentation

PgwCookie is a function to read, write and delete all your cookies, created by itself, via the server or other plugins.

Plugin options

Important: If you create cookies with one or more parameters ("path", "domain", "secure", "json" and/or "raw"), you should provide the same parameters for an update or a deletion.
Name (required for all actions) - This parameter must be a string.
name: 'myCookie'
Value (required for a creation or a deletion) - This parameter must be a string, an object (when the JSON option is activated) or "null" for a deletion.
value: 'test'  |  value: { test: 'example' }  |  value: null
Path (optional) - If you send this parameter, it must be a string. The default value is "/".
path: '/test'
Domain (optional) - If you send this parameter, it must be a string (root domain name or subdomain) without the scheme (http:// or https://).
domain: 'example.com'  |  domain: 'test.domain.com'
Expires (optional) - If this parameter is sent, it must be a number of minutes before the expiration.
expires: 60
Secure (optional) - If you send this parameter, the cookie will be set for secure pages (HTTPS).
secure: true
Json (optional) - If you send this parameter, the Value parameter must be an object for a creation. You will get this object with the syntax of reading.
json: true
Raw (optional) - If this parameter is sent, the cookie value during the registration and the reading, will not be formatted with encode/decodeURIComponent.
raw: true

Cookie usages

You will find below 2 examples, the first with the default configuration, and the second one with the JSON encoding activated.
Simple use
// Set a cookie "userName" with a string
$.pgwCookie({ name: 'userName', value: 'John Doe' });

// Get "userName"
$.pgwCookie({ name: 'userName' }); // Will output: "John Doe"

// Update "userName"
$.pgwCookie({ name: 'userName', value: 'Doe John' }); // The value is now: "Doe John"

// Remove "userName"
$.pgwCookie({ name: 'userName', value: null });
Use with JSON encoding
// Set a cookie "userData" with an object
$.pgwCookie({ name: 'userData', json: true, value: { id: 12345, name: 'John Doe' } });

// Get "userData"
var userData = $.pgwCookie({ name: 'userData', json: true }); // Will output: { "id": 12345, "name": "John Doe" }
console.log(userData.name); // Will print: "John Doe" 

// Update "userData"
$.pgwCookie({ name: 'userData', json: true, value: { id: 54321, name: 'Doe John' } });

// Remove "userData"
$.pgwCookie({ name: 'userData', value: null });
jquery / zepto responsive slider - jquery / zepto responsive menu - jquery / zepto responsive modal / dialog - jquery / zepto cookie plugin