Skip to content

Commit

Permalink
Add domain property (#8)
Browse files Browse the repository at this point in the history
* Add domain property

* Some typo, align comments

* fix erasing cookie if domain is specified
  • Loading branch information
web-padawan authored and andreasonny83 committed Jun 15, 2016
1 parent 8135964 commit ba0f762
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ Default value: '/'

The cookie path

### domain

type: String
Default value: ''

The cookie domain

### time

type: Number
Expand Down
28 changes: 21 additions & 7 deletions polymer-cookie.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<!--
The `polymer-cookie` element stores cookies using a web component
The best practice to use cookie in a Polyper project
The best practice to use cookie in a Polymer project
<polymer-cookie
id="test_cookie"
Expand All @@ -21,7 +21,7 @@
Note: The `params` attribute must be double quoted JSON.
The following is a siple exaple for testing your 'test_cookie' in your project:
The following is a simple example for testing your 'test_cookie' in your project:
var cookie = Polymer.dom(document).querySelector('#test_cookie');
Expand Down Expand Up @@ -60,6 +60,15 @@
reflectToAttribute: true
},

/**
* The cookie domain.
*/
domain: {
type: String,
value: '',
reflectToAttribute: true
},

/**
* The cookie path.
*/
Expand Down Expand Up @@ -108,10 +117,10 @@
reflectToAttribute: true
},

/**
* Create the cookie automatically as the element is rendered on the DOM
* @type [Boolean]
*/
/**
* Create the cookie automatically as the element is rendered on the DOM
* @type [Boolean]
*/
autoSet: {
type: Boolean,
value: false,
Expand Down Expand Up @@ -155,6 +164,7 @@
this.name, '=', this.value,
'; expires=' + expires,
this.path && '; path=' + this.path,
this.domain && "; domain=" + this.domain,
this.secure ? '; secure' : '',
';'
].join(''));
Expand All @@ -173,12 +183,16 @@
},

/**
* Erease the cookie information
* Erase the cookie information
*/
eraseCookie: function() {
var output = this.name +
'=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;';

if (this.domain) {
output += "domain=" + this.domain;
}

document.cookie = output;
}
});
Expand Down

0 comments on commit ba0f762

Please sign in to comment.