Hash. Cookie.js

Stores and loads an Hash as a cookie using Json format.

Summary
Hash. Cookie.jsStores and loads an Hash as a cookie using Json format.
Hash. CookieInherits all the methods from Hash, additional methods are save and load.
Properties
saveSaves the Hash to the cookie.
loadLoads the cookie and assigns it to the Hash.

Hash. Cookie

Inherits all the methods from Hash, additional methods are save and load.  Hash json string has a limit of 4kb (4096byte), so be careful with your Hash size.  Creating a new instance automatically loads the data from the Cookie into the Hash.  If the Hash is emptied, the cookie is also removed.

Arguments

namethe key (name) for the cookie
optionsoptions are identical to Cookie and are simply passed along to it.  In addition, it has the autoSave option, to save the cookie at every operation. defaults to true.

Example

var fruits = new Hash.Cookie('myCookieName', {duration: 3600});
fruits.extend({
    'lemon': 'yellow',
    'apple': 'red'
});
fruits.set('melon', 'green');
fruits.get('lemon'); // yellow
 
// ... on another page ... values load automatically
 
var fruits = new Hash.Cookie('myCookieName', {duration: 365});
fruits.get('melon'); // green
 
fruits.erase(); // delete cookie
Summary
Properties
saveSaves the Hash to the cookie.
loadLoads the cookie and assigns it to the Hash.

Properties

save

Saves the Hash to the cookie.  If the hash is empty, removes the cookie.

Returns

Returns false when the JSON string cookie is too long (4kb), otherwise true.

Example

var login = new Hash.Cookie('userstatus', {autoSave: false});
 
login.extend({
    'username': 'John',
    'credentials': [4, 7, 9]
});
login.set('last_message', 'User logged in!');
 
login.save(); // finally save the Hash

load

Loads the cookie and assigns it to the Hash.

It wraps an object that it uses internally as a map.
Class for creating, getting, and removing cookies.

Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi