This is a Drupal module wrapper for the jQuery Cookie plug-in by Klaus Hartl. This plug-in makes it possible to create a cookie with the given name and value and other optional parameters.
This is another wrapper module that is easy to use in your own modules and blocks. Also note that quite a few other em>jQuery plug-ins rely on the jQuery Cookie plug-in. In those cases all you really need to do is to enable this module and the script is loaded automatically on page load.
This demo shows how you can interact with the cookies from pretty much anywhere in your application. The sidebar block has a few menu items to trigger various events.
For this demo, the jQuery Cookie plug-in is called on page load via the $.ready() method. The buttons in the block are then also linked to the $.cookie() method, but with the calls containing various action attributes.
The block code looks something like this:
[...]
case 'view':
drupal_add_js([JS script my various callbacks], 'inline');
$output = '<[button tag] id="[button ID]">'
. '[button label]'
. '</[button tag]>';
$block['subject'] = '[my block title]';
$block['content'] = $output;
return $block;
break;
[...]
You can also try the following experiment: change the cookie contents, and navigate away from this page, come back, and the cookie contents should still hold what you set previoulsy (unless, of course, you delete the cookies within your browser).