- Overview
- Documents
Macaroon is a jQuery plugin for simple access to browser cookies.
Source: formstone.it
1. INCLUDE JS FILES
<script src="jquery.js"></script> <script src="jquery.fs.macaroon.js"></script>
2. JAVASCRIPT
To create a new cookie, or update an existing one, simply pass the key and value as the first and second parameters, respectively:
// Set cookie $.macroon(key, value);
To return a cookie's value pass the key as the only parameter:
// Get Cookie var value = $.macroon(key);
To erase an existing cookie set it to null:
// Erase Cookie $.macroon(key, null);
3. OPTIONS
Options are set by passing a valid options object at initialization or to the public "defaults" method. You can also set custom options for a specific instance by attaching a data-boxer-options attribute containing a properly formatted JSON object to the target element.
NAME | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
domain | string | Cookie domain | |
expires | int | 604800000 | Time until cookie expires |
path | string | Cookie path |
4. METHODS
Methods are publicly available to all active instances, unless otherwise stated.
create
Creates a cookie
$.macaroon(key, value, options);
PARAMETER | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
key | string | Cookie key | |
value | string | Cookie value | |
opts | object | Options object |
read
Returns a cookie's value, or null
var value = $.macaroon(key);
PARAMETER | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
key | string | Cookie key |
erase
Deletes a cookie
$.macaroon(key, null);
PARAMETER | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
key | string | Cookie key |
defaults
Sets default plugin options
$.macaroon(opts);
PARAMETER | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
opts | object | {} | Options object |