Stores and loads a Hash as a Cookie using JSON format.
var myHashCookie = new Hash.Cookie(name[, options]);
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
Saves the Hash to the cookie. If the hash is empty, removes the cookie.
myHashCookie.save();
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
Loads the cookie and assigns it to the Hash.
myHashCookie.load();
var myHashCookie = new Hash.Cookie('myCookie'); (function(){ myHashCookie.load(); if (!myHashCookie.getLength()) alert('Cookie Monster must of eaten it!'); }).periodical(5000);
This documentation is released under a Attribution-NonCommercial-ShareAlike 3.0 License.