Skip to content

Commit

Permalink
feat(interal): LocalStorage item name as prop (#41)
Browse files Browse the repository at this point in the history
Allow variable name for storage item. Default remains 'cookie:accepted', but user can change it.
Could be use for multiple cookie law components, or if text/law changed for refreshes
  • Loading branch information
Keiwen authored and apertureless committed Aug 28, 2018
1 parent cbe26ad commit 26c5266
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/CookieLaw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
buttonClass: {
type: String,
default: 'Cookie__button'
},
storageName: {
type: String,
default: 'cookie:accepted'
}
},
data () {
Expand Down Expand Up @@ -108,16 +112,16 @@
methods: {
setVisited () {
if (this.supportsLocalStorage) {
localStorage.setItem('cookie:accepted', true)
localStorage.setItem(this.storageName, true)
} else {
Cookie.set('cookie:accepted', true)
Cookie.set(this.storageName, true)
}
},
getVisited () {
if (this.supportsLocalStorage) {
return localStorage.getItem('cookie:accepted')
return localStorage.getItem(this.storageName)
} else {
return Cookie.get('cookie:accepted')
return Cookie.get(this.storageName)
}
},
accept () {
Expand Down

0 comments on commit 26c5266

Please sign in to comment.