This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
angular-translate-storage-cookie.js
121 lines (109 loc) · 3.12 KB
/
angular-translate-storage-cookie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*!
* angular-translate - v2.19.1 - 2024-01-21
*
* Copyright (c) 2024 The angular-translate team, Pascal Precht; Licensed MIT
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define([], function () {
return (factory());
});
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
factory();
}
}(this, function () {
$translateCookieStorageFactory.$inject = ['$injector'];
angular.module('pascalprecht.translate')
/**
* @ngdoc object
* @name pascalprecht.translate.$translateCookieStorage
* @requires $cookieStore
*
* @description
* Abstraction layer for cookieStore. This service is used when telling angular-translate
* to use cookieStore as storage.
*
*/
.factory('$translateCookieStorage', $translateCookieStorageFactory);
function $translateCookieStorageFactory($injector) {
'use strict';
// Since AngularJS 1.4, $cookieStore is deprecated
var delegate;
if (angular.version.major === 1 && angular.version.minor >= 4) {
var $cookies = $injector.get('$cookies');
delegate = {
get : function (key) {
return $cookies.get(key);
},
put : function (key, value) {
$cookies.put(key, value, { samesite: 'lax' });
}
};
} else {
var $cookieStore = $injector.get('$cookieStore');
delegate = {
get : function (key) {
return $cookieStore.get(key);
},
put : function (key, value) {
$cookieStore.put(key, value);
}
};
}
var $translateCookieStorage = {
/**
* @ngdoc function
* @name pascalprecht.translate.$translateCookieStorage#get
* @methodOf pascalprecht.translate.$translateCookieStorage
*
* @description
* Returns an item from cookieStorage by given name.
*
* @param {string} name Item name
* @return {string} Value of item name
*/
get : function (name) {
return delegate.get(name);
},
/**
* @ngdoc function
* @name pascalprecht.translate.$translateCookieStorage#set
* @methodOf pascalprecht.translate.$translateCookieStorage
*
* @description
* Sets an item in cookieStorage by given name.
*
* @deprecated use #put
*
* @param {string} name Item name
* @param {string} value Item value
*/
set : function (name, value) {
delegate.put(name, value);
},
/**
* @ngdoc function
* @name pascalprecht.translate.$translateCookieStorage#put
* @methodOf pascalprecht.translate.$translateCookieStorage
*
* @description
* Sets an item in cookieStorage by given name.
*
* @param {string} name Item name
* @param {string} value Item value
*/
put : function (name, value) {
delegate.put(name, value);
}
};
return $translateCookieStorage;
}
$translateCookieStorageFactory.displayName = '$translateCookieStorage';
return 'pascalprecht.translate';
}));