Cookie Web Component for Polymer 1.x
Cookie Web Component for Polymer 1.x
<polymer-cookie
id="test_cookie"
name="test_cookie"
value="hello world"
time="2"
format="h">
</polymer-cookie>
<polymer-cookie
id="test_cookie2"
name="test_cookie2"
value="hello world!"
auto-set>
</polymer-cookie>
Note: The params
attribute must be double quoted JSON.
Add the library using the Javascript package manager Bower:
$ bower install --save polymer-cookie
Or clone this repository inside your project folder using Git:
$ git clone https://github.com/andreasonny83/polymer-cookie.git
Type: String
Default value: 'polymer-cookie'
Set the cookie name
type: String
Default value: ''
The cookie value
type: String
Default value: ''
The cookie path.
The path must be absolute. If not specified, defaults to the current path of the current document location.
type: String
Default value: ''
The cookie domain.
(e.g., 'example.com' or 'subdomain.example.com'). If not specified, defaults to the host portion of the current document location (but not including subdomains). Contrary to earlier specifications, leading dots in domain names are ignored. If a domain is specified, subdomains are always included.
type: Number
Default value: 1
The expiration time related to the 'format' value. Set to -1 to never expire the cookie
type: String
Default value: 'd'
The expiration format time
- 's' : seconds
- 'm' : minutes
- 'h' : hours
- 'd' : days
type: Boolean
Default value: false
Cookie to only be transmitted over secure protocol as https
type: Boolean
Default value: false
The HTTPOnly cookie attribute can help to mitigate this attack by preventing access to cookie value through Javascript. Read more about Cookies and Security.
type: Boolean
Default value: false
If set, creates the cookie as the element is rendered on the page without the need of manually invoking createCookie
Write the cookie
var cookie = Polymer.dom(document).querySelector('#user_cookie');
cookie.createCookie();
Read the cookie if any, and the returns its value
var cookie = Polymer.dom(document).querySelector('#user_cookie');
var cookie_value = cookie.readCookie();
Destroy the cookie
var cookie = Polymer.dom(document).querySelector('#user_cookie');
cookie.eraseCookie();
Install the Polymer CLI to serve the demo locally with:
$ npm install -g polymer-cli
First install all the project dependencies with:
$ bower install
Then, run Polymer serve from the repo directory with:
$ polymer serve
Then open localhost:8080/components/polymer-cookie/demo/ in your browser.
For more information about Polymer CLI have a look at the official documentation
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
A special thanks to our contributors:
Changelog available here
MIT License © Andrea SonnY