formstone
Version:
Library of modular front end components.
1 lines • 6.51 kB
JSON
{"main":["cookie.js"],"options":[{"name":"domain","type":"string","description":"Cookie domain"},{"name":"expires","type":"int","default":"604800000","description":"Time until cookie expires"},{"name":"path","type":"string","description":"Cookie path"}],"events":[],"methods":[{"name":"create","description":"Creates a cookie.","params":[{"name":"key","type":"string","description":"Cookie key"},{"name":"value","type":"string","description":"Cookie value"},{"name":"options","type":"object","description":"Options object"}],"examples":["$.cookie(key, value, options);"]},{"name":"erase","description":"Deletes a cookie.","params":[{"name":"key","type":"string","description":"Cookie key"}],"examples":["$.cookie(key, null);"]},{"name":"read","description":"Returns a cookie's value, or null.","params":[{"name":"key","type":"string","description":"Cookie key"}],"return":{"type":"string | null","description":"Cookie's value, or null"},"examples":["var value = $.cookie(key);"]}],"name":"Cookie","type":"utility","description":"A jQuery plugin for simple access to browser cookies.","dependencies":["jQuery","core.js"],"use":"### Basic\n\nTo create a new cookie, or update an existing one, simply pass the `key` and `value` as the first and second parameters, respectively:\n\n```javascript\n// Set cookie\n$.cookie(key, value);\n```\n\nTo return a cookie's value pass the `key` as the only parameter:\n\n```javascript\n// Get Cookie\nvar value = $.cookie(key);\n```\n\nTo erase an existing cookie, set it to `null`:\n\n```javascript\n// Erase Cookie\n$.cookie(key, null);\n```","demo":"<!-- START: FIRSTDEMO -->\r\n\r\n<script>\r\n var $demoForm,\r\n $demoOutput;\r\n\r\n Formstone.Ready(function() {\r\n $demoForm = $(\".demo_form\");\r\n $demoOutput = $(\".demo_output\");\r\n\r\n $demoForm.on(\"click.cookie\", \".set\", setCookie)\r\n .on(\"click.cookie\", \".get\", getCookie)\r\n .on(\"click.cookie\", \".erase\", eraseCookie);\r\n });\r\n\r\n function setCookie(e) {\r\n killEvent(e);\r\n\r\n var key = $demoForm.find(\"[name=set_key]\").val(),\r\n value = $demoForm.find(\"[name=set_value]\").val();\r\n\r\n $.cookie(key, value);\r\n\r\n output(\"Set\", key + \" = \" + value);\r\n }\r\n\r\n function getCookie(e) {\r\n killEvent(e);\r\n\r\n var key = $demoForm.find(\"[name=get_key]\").val(),\r\n value = $.cookie(key);\r\n\r\n output(\"Get\", key + \" = \" + value);\r\n }\r\n\r\n function eraseCookie(e) {\r\n killEvent(e);\r\n\r\n var key = $demoForm.find(\"[name=erase_key]\").val();\r\n\r\n $.cookie(key, null);\r\n\r\n output(\"Erase\", key);\r\n }\r\n\r\n function output(label, value) {\r\n $demoOutput.prepend('<strong>' + label + ': </strong>' + value + '</span><br>');\r\n }\r\n\r\n function killEvent(e) {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n }\r\n</script>\r\n\r\n<form action=\"#\" medthod=\"GET\" class=\"fs-row form demo_form\">\r\n <div class=\"fs-cell fs-xs-full fs-sm-third fs-md-third fs-lg-third\">\r\n <h4 class=\"no_margin_top\">Set Cookie</h4>\r\n <div class=\"fs-row\">\r\n <div class=\"fs-cell fs-xs-half\">\r\n <label class=\"form_label\">Key</label>\r\n <input type=\"text\" name=\"set_key\" value=\"foo\" class=\"form_input\">\r\n </div>\r\n <div class=\"fs-cell fs-xs-half\">\r\n <label class=\"form_label\">Value</label>\r\n <input type=\"text\" name=\"set_value\" value=\"bar\" class=\"form_input\">\r\n </div>\r\n </div>\r\n <input type=\"submit\" class=\"button form_button set\" value=\"Set\">\r\n </div>\r\n <div class=\"fs-cell fs-xs-full fs-sm-third fs-md-third fs-lg-third\">\r\n <h4 class=\"no_margin_top\">Get Cookie</h4>\r\n <label class=\"form_label\">Key</label>\r\n <input type=\"text\" name=\"get_key\" value=\"foo\" class=\"form_input\">\r\n <input type=\"submit\" class=\"button form_button get\" value=\"Get\">\r\n </div>\r\n <div class=\"fs-cell fs-xs-full fs-sm-third fs-md-third fs-lg-third\">\r\n <h4 class=\"no_margin_top\">Erase Cookie</h4>\r\n <label class=\"form_label\">Key</label>\r\n <input type=\"text\" name=\"erase_key\" value=\"foo\" class=\"form_input\">\r\n <input type=\"submit\" class=\"button form_button erase\" value=\"Erase\">\r\n </div>\r\n</form>\r\n<div class=\"demo_output form_textarea\"></div>\r\n\r\n<!-- END: FIRSTDEMO -->","document":"# Cookie\n\nA jQuery plugin for simple access to browser cookies.\n\n<!-- HEADER END -->\n\n<!-- NAV START -->\n\n* [Use](#use)\n* [Options](#options)\n* [Methods](#methods)\n\n<!-- NAV END -->\n\n<!-- DEMO BUTTON -->\n\n<a name=\"use\"></a>\n\n## Using Cookie\n\n\n#### Main\n\n```markup\ncookie.js\n```\n\n\n#### Dependencies\n\n```markup\njQuery\ncore.js\n```\n\n### Basic\n\nTo create a new cookie, or update an existing one, simply pass the `key` and `value` as the first and second parameters, respectively:\n\n```javascript\n// Set cookie\n$.cookie(key, value);\n```\n\nTo return a cookie's value pass the `key` as the only parameter:\n\n```javascript\n// Get Cookie\nvar value = $.cookie(key);\n```\n\nTo erase an existing cookie, set it to `null`:\n\n```javascript\n// Erase Cookie\n$.cookie(key, null);\n```\n\n\n<a name=\"options\"></a>\n\n## Options\n\nSet instance options by passing a valid object at initialization, or to the public `defaults` method.\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| `domain` | `string` | | Cookie domain |\n| `expires` | `int` | `604800000` | Time until cookie expires |\n| `path` | `string` | | Cookie path |\n\n<hr>\n<a name=\"methods\"></a>\n\n## Methods\n\nMethods are publicly available, unless otherwise stated.\n\n### create\n\nCreates a cookie.\n\n```javascript\n$.cookie(key, value, options);\n```\n\n#### Parameters\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| `key` | `string` | | Cookie key |\n| `value` | `string` | | Cookie value |\n| `options` | `object` | | Options object |\n\n### erase\n\nDeletes a cookie.\n\n```javascript\n$.cookie(key, null);\n```\n\n#### Parameters\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| `key` | `string` | | Cookie key |\n\n### read\n\nReturns a cookie's value, or null.\n\n```javascript\nvar value = $.cookie(key);\n```\n\n#### Parameters\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| `key` | `string` | | Cookie key |\n\n"}