ember-tribe 1.2.7 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Service from '@ember/service';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
import { tracked } from '@glimmer/tracking';
|
|
4
|
+
|
|
5
|
+
export default class CookiesService extends Service {
|
|
6
|
+
|
|
7
|
+
@tracked days = 365;
|
|
8
|
+
|
|
9
|
+
@action
|
|
10
|
+
setCookie(name, value) {
|
|
11
|
+
var expires = "";
|
|
12
|
+
|
|
13
|
+
var date = new Date();
|
|
14
|
+
date.setTime(date.getTime() + (this.days*24*60*60*1000));
|
|
15
|
+
expires = "; expires=" + date.toUTCString();
|
|
16
|
+
|
|
17
|
+
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@action
|
|
21
|
+
getCookie(name) {
|
|
22
|
+
var nameEQ = name + "=";
|
|
23
|
+
var ca = document.cookie.split(';');
|
|
24
|
+
for(var i=0;i < ca.length;i++) {
|
|
25
|
+
var c = ca[i];
|
|
26
|
+
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
|
27
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@action
|
|
33
|
+
eraseCookie(name) {
|
|
34
|
+
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
35
|
+
}
|
|
36
|
+
}
|