angularjs-rails 1.3.15 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/angularjs-rails/version.rb +2 -2
- data/vendor/assets/javascripts/angular-animate.js +3443 -1872
- data/vendor/assets/javascripts/angular-aria.js +89 -75
- data/vendor/assets/javascripts/angular-cookies.js +255 -141
- data/vendor/assets/javascripts/angular-loader.js +41 -17
- data/vendor/assets/javascripts/angular-message-format.js +980 -0
- data/vendor/assets/javascripts/angular-messages.js +430 -153
- data/vendor/assets/javascripts/angular-mocks.js +76 -92
- data/vendor/assets/javascripts/angular-resource.js +6 -6
- data/vendor/assets/javascripts/angular-route.js +8 -6
- data/vendor/assets/javascripts/angular-sanitize.js +32 -28
- data/vendor/assets/javascripts/angular-scenario.js +4315 -2452
- data/vendor/assets/javascripts/angular-touch.js +26 -21
- data/vendor/assets/javascripts/angular.js +4314 -2490
- data/vendor/assets/javascripts/unstable/angular2.js +24024 -0
- metadata +4 -14
- data/vendor/assets/javascripts/unstable/angular-animate.js +0 -2137
- data/vendor/assets/javascripts/unstable/angular-aria.js +0 -364
- data/vendor/assets/javascripts/unstable/angular-cookies.js +0 -206
- data/vendor/assets/javascripts/unstable/angular-loader.js +0 -405
- data/vendor/assets/javascripts/unstable/angular-messages.js +0 -401
- data/vendor/assets/javascripts/unstable/angular-mocks.js +0 -2468
- data/vendor/assets/javascripts/unstable/angular-resource.js +0 -668
- data/vendor/assets/javascripts/unstable/angular-route.js +0 -989
- data/vendor/assets/javascripts/unstable/angular-sanitize.js +0 -679
- data/vendor/assets/javascripts/unstable/angular-scenario.js +0 -37678
- data/vendor/assets/javascripts/unstable/angular-touch.js +0 -622
- data/vendor/assets/javascripts/unstable/angular.js +0 -26309
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
|
-
* @license AngularJS v1.
|
3
|
-
* (c) 2010-
|
2
|
+
* @license AngularJS v1.4.0
|
3
|
+
* (c) 2010-2015 Google, Inc. http://angularjs.org
|
4
4
|
* License: MIT
|
5
5
|
*/
|
6
6
|
(function(window, angular, undefined) {'use strict';
|
@@ -216,88 +216,101 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
|
|
216
216
|
restrict: 'A',
|
217
217
|
require: '?ngModel',
|
218
218
|
priority: 200, //Make sure watches are fired after any other directives that affect the ngModel value
|
219
|
-
|
219
|
+
compile: function(elem, attr) {
|
220
220
|
var shape = getShape(attr, elem);
|
221
|
-
var needsTabIndex = shouldAttachAttr('tabindex', 'tabindex', elem);
|
222
|
-
|
223
|
-
function ngAriaWatchModelValue() {
|
224
|
-
return ngModel.$modelValue;
|
225
|
-
}
|
226
|
-
|
227
|
-
function getRadioReaction() {
|
228
|
-
if (needsTabIndex) {
|
229
|
-
needsTabIndex = false;
|
230
|
-
return function ngAriaRadioReaction(newVal) {
|
231
|
-
var boolVal = (attr.value == ngModel.$viewValue);
|
232
|
-
elem.attr('aria-checked', boolVal);
|
233
|
-
elem.attr('tabindex', 0 - !boolVal);
|
234
|
-
};
|
235
|
-
} else {
|
236
|
-
return function ngAriaRadioReaction(newVal) {
|
237
|
-
elem.attr('aria-checked', (attr.value == ngModel.$viewValue));
|
238
|
-
};
|
239
|
-
}
|
240
|
-
}
|
241
|
-
|
242
|
-
function ngAriaCheckboxReaction(newVal) {
|
243
|
-
elem.attr('aria-checked', !ngModel.$isEmpty(ngModel.$viewValue));
|
244
|
-
}
|
245
221
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
scope.$watch(ngAriaWatchModelValue, shape === 'radio' ?
|
254
|
-
getRadioReaction() : ngAriaCheckboxReaction);
|
222
|
+
return {
|
223
|
+
pre: function(scope, elem, attr, ngModel) {
|
224
|
+
if (shape === 'checkbox' && attr.type !== 'checkbox') {
|
225
|
+
//Use the input[checkbox] $isEmpty implementation for elements with checkbox roles
|
226
|
+
ngModel.$isEmpty = function(value) {
|
227
|
+
return value === false;
|
228
|
+
};
|
255
229
|
}
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
230
|
+
},
|
231
|
+
post: function(scope, elem, attr, ngModel) {
|
232
|
+
var needsTabIndex = shouldAttachAttr('tabindex', 'tabindex', elem);
|
233
|
+
|
234
|
+
function ngAriaWatchModelValue() {
|
235
|
+
return ngModel.$modelValue;
|
260
236
|
}
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
237
|
+
|
238
|
+
function getRadioReaction() {
|
239
|
+
if (needsTabIndex) {
|
240
|
+
needsTabIndex = false;
|
241
|
+
return function ngAriaRadioReaction(newVal) {
|
242
|
+
var boolVal = (attr.value == ngModel.$viewValue);
|
243
|
+
elem.attr('aria-checked', boolVal);
|
244
|
+
elem.attr('tabindex', 0 - !boolVal);
|
245
|
+
};
|
246
|
+
} else {
|
247
|
+
return function ngAriaRadioReaction(newVal) {
|
248
|
+
elem.attr('aria-checked', (attr.value == ngModel.$viewValue));
|
249
|
+
};
|
272
250
|
}
|
273
251
|
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
elem.attr('aria-multiline', true);
|
252
|
+
|
253
|
+
function ngAriaCheckboxReaction() {
|
254
|
+
elem.attr('aria-checked', !ngModel.$isEmpty(ngModel.$viewValue));
|
278
255
|
}
|
279
|
-
break;
|
280
|
-
}
|
281
256
|
|
282
|
-
|
283
|
-
|
284
|
-
|
257
|
+
switch (shape) {
|
258
|
+
case 'radio':
|
259
|
+
case 'checkbox':
|
260
|
+
if (shouldAttachRole(shape, elem)) {
|
261
|
+
elem.attr('role', shape);
|
262
|
+
}
|
263
|
+
if (shouldAttachAttr('aria-checked', 'ariaChecked', elem)) {
|
264
|
+
scope.$watch(ngAriaWatchModelValue, shape === 'radio' ?
|
265
|
+
getRadioReaction() : ngAriaCheckboxReaction);
|
266
|
+
}
|
267
|
+
break;
|
268
|
+
case 'range':
|
269
|
+
if (shouldAttachRole(shape, elem)) {
|
270
|
+
elem.attr('role', 'slider');
|
271
|
+
}
|
272
|
+
if ($aria.config('ariaValue')) {
|
273
|
+
if (attr.min && !elem.attr('aria-valuemin')) {
|
274
|
+
elem.attr('aria-valuemin', attr.min);
|
275
|
+
}
|
276
|
+
if (attr.max && !elem.attr('aria-valuemax')) {
|
277
|
+
elem.attr('aria-valuemax', attr.max);
|
278
|
+
}
|
279
|
+
if (!elem.attr('aria-valuenow')) {
|
280
|
+
scope.$watch(ngAriaWatchModelValue, function ngAriaValueNowReaction(newVal) {
|
281
|
+
elem.attr('aria-valuenow', newVal);
|
282
|
+
});
|
283
|
+
}
|
284
|
+
}
|
285
|
+
break;
|
286
|
+
case 'multiline':
|
287
|
+
if (shouldAttachAttr('aria-multiline', 'ariaMultiline', elem)) {
|
288
|
+
elem.attr('aria-multiline', true);
|
289
|
+
}
|
290
|
+
break;
|
291
|
+
}
|
285
292
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
}, function ngAriaRequiredReaction(newVal) {
|
290
|
-
elem.attr('aria-required', !!newVal);
|
291
|
-
});
|
292
|
-
}
|
293
|
+
if (needsTabIndex) {
|
294
|
+
elem.attr('tabindex', 0);
|
295
|
+
}
|
293
296
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
297
|
+
if (ngModel.$validators.required && shouldAttachAttr('aria-required', 'ariaRequired', elem)) {
|
298
|
+
scope.$watch(function ngAriaRequiredWatch() {
|
299
|
+
return ngModel.$error.required;
|
300
|
+
}, function ngAriaRequiredReaction(newVal) {
|
301
|
+
elem.attr('aria-required', !!newVal);
|
302
|
+
});
|
303
|
+
}
|
304
|
+
|
305
|
+
if (shouldAttachAttr('aria-invalid', 'ariaInvalid', elem)) {
|
306
|
+
scope.$watch(function ngAriaInvalidWatch() {
|
307
|
+
return ngModel.$invalid;
|
308
|
+
}, function ngAriaInvalidReaction(newVal) {
|
309
|
+
elem.attr('aria-invalid', !!newVal);
|
310
|
+
});
|
311
|
+
}
|
312
|
+
}
|
313
|
+
};
|
301
314
|
}
|
302
315
|
};
|
303
316
|
}])
|
@@ -339,7 +352,8 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
|
|
339
352
|
|
340
353
|
if ($aria.config('bindKeypress') && !attr.ngKeypress && !isNodeOneOf(elem, nodeBlackList)) {
|
341
354
|
elem.on('keypress', function(event) {
|
342
|
-
|
355
|
+
var keyCode = event.which || event.keyCode;
|
356
|
+
if (keyCode === 32 || keyCode === 13) {
|
343
357
|
scope.$apply(callback);
|
344
358
|
}
|
345
359
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
|
-
* @license AngularJS v1.
|
3
|
-
* (c) 2010-
|
2
|
+
* @license AngularJS v1.4.0
|
3
|
+
* (c) 2010-2015 Google, Inc. http://angularjs.org
|
4
4
|
* License: MIT
|
5
5
|
*/
|
6
6
|
(function(window, angular, undefined) {'use strict';
|
@@ -24,183 +24,297 @@
|
|
24
24
|
|
25
25
|
angular.module('ngCookies', ['ng']).
|
26
26
|
/**
|
27
|
-
* @ngdoc
|
28
|
-
* @name $
|
29
|
-
*
|
27
|
+
* @ngdoc provider
|
28
|
+
* @name $cookiesProvider
|
30
29
|
* @description
|
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
|
-
isUndefined = angular.isUndefined;
|
58
|
-
|
59
|
-
//creates a poller fn that copies all cookies from the $browser to service & inits the service
|
60
|
-
$browser.addPollFn(function() {
|
61
|
-
var currentCookies = $browser.cookies();
|
62
|
-
if (lastBrowserCookies != currentCookies) { //relies on browser.cookies() impl
|
63
|
-
lastBrowserCookies = currentCookies;
|
64
|
-
copy(currentCookies, lastCookies);
|
65
|
-
copy(currentCookies, cookies);
|
66
|
-
if (runEval) $rootScope.$apply();
|
67
|
-
}
|
68
|
-
})();
|
69
|
-
|
70
|
-
runEval = true;
|
71
|
-
|
72
|
-
//at the end of each eval, push cookies
|
73
|
-
//TODO: this should happen before the "delayed" watches fire, because if some cookies are not
|
74
|
-
// strings or browser refuses to store some cookies, we update the model in the push fn.
|
75
|
-
$rootScope.$watch(push);
|
76
|
-
|
77
|
-
return cookies;
|
78
|
-
|
79
|
-
|
80
|
-
/**
|
81
|
-
* Pushes all the cookies from the service to the browser and verifies if all cookies were
|
82
|
-
* stored.
|
83
|
-
*/
|
84
|
-
function push() {
|
85
|
-
var name,
|
86
|
-
value,
|
87
|
-
browserCookies,
|
88
|
-
updated;
|
89
|
-
|
90
|
-
//delete any cookies deleted in $cookies
|
91
|
-
for (name in lastCookies) {
|
92
|
-
if (isUndefined(cookies[name])) {
|
93
|
-
$browser.cookies(name, undefined);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
//update all cookies updated in $cookies
|
98
|
-
for (name in cookies) {
|
99
|
-
value = cookies[name];
|
100
|
-
if (!angular.isString(value)) {
|
101
|
-
value = '' + value;
|
102
|
-
cookies[name] = value;
|
103
|
-
}
|
104
|
-
if (value !== lastCookies[name]) {
|
105
|
-
$browser.cookies(name, value);
|
106
|
-
updated = true;
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
//verify what was actually stored
|
111
|
-
if (updated) {
|
112
|
-
updated = false;
|
113
|
-
browserCookies = $browser.cookies();
|
114
|
-
|
115
|
-
for (name in cookies) {
|
116
|
-
if (cookies[name] !== browserCookies[name]) {
|
117
|
-
//delete or reset all cookies that the browser dropped from $cookies
|
118
|
-
if (isUndefined(browserCookies[name])) {
|
119
|
-
delete cookies[name];
|
120
|
-
} else {
|
121
|
-
cookies[name] = browserCookies[name];
|
122
|
-
}
|
123
|
-
updated = true;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}]).
|
129
|
-
|
30
|
+
* Use `$cookiesProvider` to change the default behavior of the {@link ngCookies.$cookies $cookies} service.
|
31
|
+
* */
|
32
|
+
provider('$cookies', [function $CookiesProvider() {
|
33
|
+
/**
|
34
|
+
* @ngdoc property
|
35
|
+
* @name $cookiesProvider#defaults
|
36
|
+
* @description
|
37
|
+
*
|
38
|
+
* Object containing default options to pass when setting cookies.
|
39
|
+
*
|
40
|
+
* The object may have following properties:
|
41
|
+
*
|
42
|
+
* - **path** - `{string}` - The cookie will be available only for this path and its
|
43
|
+
* sub-paths. By default, this would be the URL that appears in your base tag.
|
44
|
+
* - **domain** - `{string}` - The cookie will be available only for this domain and
|
45
|
+
* its sub-domains. For obvious security reasons the user agent will not accept the
|
46
|
+
* cookie if the current domain is not a sub domain or equals to the requested domain.
|
47
|
+
* - **expires** - `{string|Date}` - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT"
|
48
|
+
* or a Date object indicating the exact date/time this cookie will expire.
|
49
|
+
* - **secure** - `{boolean}` - The cookie will be available only in secured connection.
|
50
|
+
*
|
51
|
+
* Note: by default the address that appears in your <base> tag will be used as path.
|
52
|
+
* This is import so that cookies will be visible for all routes in case html5mode is enabled
|
53
|
+
*
|
54
|
+
**/
|
55
|
+
var defaults = this.defaults = {};
|
130
56
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
* @requires $cookies
|
135
|
-
*
|
136
|
-
* @description
|
137
|
-
* Provides a key-value (string-object) storage, that is backed by session cookies.
|
138
|
-
* Objects put or retrieved from this storage are automatically serialized or
|
139
|
-
* deserialized by angular's toJson/fromJson.
|
140
|
-
*
|
141
|
-
* Requires the {@link ngCookies `ngCookies`} module to be installed.
|
142
|
-
*
|
143
|
-
* @example
|
144
|
-
*
|
145
|
-
* ```js
|
146
|
-
* angular.module('cookieStoreExample', ['ngCookies'])
|
147
|
-
* .controller('ExampleController', ['$cookieStore', function($cookieStore) {
|
148
|
-
* // Put cookie
|
149
|
-
* $cookieStore.put('myFavorite','oatmeal');
|
150
|
-
* // Get cookie
|
151
|
-
* var favoriteCookie = $cookieStore.get('myFavorite');
|
152
|
-
* // Removing a cookie
|
153
|
-
* $cookieStore.remove('myFavorite');
|
154
|
-
* }]);
|
155
|
-
* ```
|
156
|
-
*/
|
157
|
-
factory('$cookieStore', ['$cookies', function($cookies) {
|
57
|
+
function calcOptions(options) {
|
58
|
+
return options ? angular.extend({}, defaults, options) : defaults;
|
59
|
+
}
|
158
60
|
|
61
|
+
/**
|
62
|
+
* @ngdoc service
|
63
|
+
* @name $cookies
|
64
|
+
*
|
65
|
+
* @description
|
66
|
+
* Provides read/write access to browser's cookies.
|
67
|
+
*
|
68
|
+
* BREAKING CHANGE: `$cookies` no longer exposes properties that represent the
|
69
|
+
* current browser cookie values. Now you must use the get/put/remove/etc. methods
|
70
|
+
* as described below.
|
71
|
+
*
|
72
|
+
* Requires the {@link ngCookies `ngCookies`} module to be installed.
|
73
|
+
*
|
74
|
+
* @example
|
75
|
+
*
|
76
|
+
* ```js
|
77
|
+
* angular.module('cookiesExample', ['ngCookies'])
|
78
|
+
* .controller('ExampleController', ['$cookies', function($cookies) {
|
79
|
+
* // Retrieving a cookie
|
80
|
+
* var favoriteCookie = $cookies.get('myFavorite');
|
81
|
+
* // Setting a cookie
|
82
|
+
* $cookies.put('myFavorite', 'oatmeal');
|
83
|
+
* }]);
|
84
|
+
* ```
|
85
|
+
*/
|
86
|
+
this.$get = ['$$cookieReader', '$$cookieWriter', function($$cookieReader, $$cookieWriter) {
|
159
87
|
return {
|
160
88
|
/**
|
161
89
|
* @ngdoc method
|
162
|
-
* @name $
|
90
|
+
* @name $cookies#get
|
163
91
|
*
|
164
92
|
* @description
|
165
93
|
* Returns the value of given cookie key
|
166
94
|
*
|
167
95
|
* @param {string} key Id to use for lookup.
|
168
|
-
* @returns {
|
96
|
+
* @returns {string} Raw cookie value.
|
169
97
|
*/
|
170
98
|
get: function(key) {
|
171
|
-
|
99
|
+
return $$cookieReader()[key];
|
100
|
+
},
|
101
|
+
|
102
|
+
/**
|
103
|
+
* @ngdoc method
|
104
|
+
* @name $cookies#getObject
|
105
|
+
*
|
106
|
+
* @description
|
107
|
+
* Returns the deserialized value of given cookie key
|
108
|
+
*
|
109
|
+
* @param {string} key Id to use for lookup.
|
110
|
+
* @returns {Object} Deserialized cookie value.
|
111
|
+
*/
|
112
|
+
getObject: function(key) {
|
113
|
+
var value = this.get(key);
|
172
114
|
return value ? angular.fromJson(value) : value;
|
173
115
|
},
|
174
116
|
|
175
117
|
/**
|
176
118
|
* @ngdoc method
|
177
|
-
* @name $
|
119
|
+
* @name $cookies#getAll
|
120
|
+
*
|
121
|
+
* @description
|
122
|
+
* Returns a key value object with all the cookies
|
123
|
+
*
|
124
|
+
* @returns {Object} All cookies
|
125
|
+
*/
|
126
|
+
getAll: function() {
|
127
|
+
return $$cookieReader();
|
128
|
+
},
|
129
|
+
|
130
|
+
/**
|
131
|
+
* @ngdoc method
|
132
|
+
* @name $cookies#put
|
178
133
|
*
|
179
134
|
* @description
|
180
135
|
* Sets a value for given cookie key
|
181
136
|
*
|
182
137
|
* @param {string} key Id for the `value`.
|
138
|
+
* @param {string} value Raw value to be stored.
|
139
|
+
* @param {Object=} options Options object.
|
140
|
+
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}
|
141
|
+
*/
|
142
|
+
put: function(key, value, options) {
|
143
|
+
$$cookieWriter(key, value, calcOptions(options));
|
144
|
+
},
|
145
|
+
|
146
|
+
/**
|
147
|
+
* @ngdoc method
|
148
|
+
* @name $cookies#putObject
|
149
|
+
*
|
150
|
+
* @description
|
151
|
+
* Serializes and sets a value for given cookie key
|
152
|
+
*
|
153
|
+
* @param {string} key Id for the `value`.
|
183
154
|
* @param {Object} value Value to be stored.
|
155
|
+
* @param {Object=} options Options object.
|
156
|
+
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}
|
184
157
|
*/
|
185
|
-
|
186
|
-
|
158
|
+
putObject: function(key, value, options) {
|
159
|
+
this.put(key, angular.toJson(value), options);
|
187
160
|
},
|
188
161
|
|
189
162
|
/**
|
190
163
|
* @ngdoc method
|
191
|
-
* @name $
|
164
|
+
* @name $cookies#remove
|
192
165
|
*
|
193
166
|
* @description
|
194
167
|
* Remove given cookie
|
195
168
|
*
|
196
169
|
* @param {string} key Id of the key-value pair to delete.
|
170
|
+
* @param {Object=} options Options object.
|
171
|
+
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}
|
197
172
|
*/
|
198
|
-
remove: function(key) {
|
199
|
-
|
173
|
+
remove: function(key, options) {
|
174
|
+
$$cookieWriter(key, undefined, calcOptions(options));
|
200
175
|
}
|
201
176
|
};
|
177
|
+
}];
|
178
|
+
}]);
|
179
|
+
|
180
|
+
angular.module('ngCookies').
|
181
|
+
/**
|
182
|
+
* @ngdoc service
|
183
|
+
* @name $cookieStore
|
184
|
+
* @deprecated
|
185
|
+
* @requires $cookies
|
186
|
+
*
|
187
|
+
* @description
|
188
|
+
* Provides a key-value (string-object) storage, that is backed by session cookies.
|
189
|
+
* Objects put or retrieved from this storage are automatically serialized or
|
190
|
+
* deserialized by angular's toJson/fromJson.
|
191
|
+
*
|
192
|
+
* Requires the {@link ngCookies `ngCookies`} module to be installed.
|
193
|
+
*
|
194
|
+
* <div class="alert alert-danger">
|
195
|
+
* **Note:** The $cookieStore service is deprecated.
|
196
|
+
* Please use the {@link ngCookies.$cookies `$cookies`} service instead.
|
197
|
+
* </div>
|
198
|
+
*
|
199
|
+
* @example
|
200
|
+
*
|
201
|
+
* ```js
|
202
|
+
* angular.module('cookieStoreExample', ['ngCookies'])
|
203
|
+
* .controller('ExampleController', ['$cookieStore', function($cookieStore) {
|
204
|
+
* // Put cookie
|
205
|
+
* $cookieStore.put('myFavorite','oatmeal');
|
206
|
+
* // Get cookie
|
207
|
+
* var favoriteCookie = $cookieStore.get('myFavorite');
|
208
|
+
* // Removing a cookie
|
209
|
+
* $cookieStore.remove('myFavorite');
|
210
|
+
* }]);
|
211
|
+
* ```
|
212
|
+
*/
|
213
|
+
factory('$cookieStore', ['$cookies', function($cookies) {
|
214
|
+
|
215
|
+
return {
|
216
|
+
/**
|
217
|
+
* @ngdoc method
|
218
|
+
* @name $cookieStore#get
|
219
|
+
*
|
220
|
+
* @description
|
221
|
+
* Returns the value of given cookie key
|
222
|
+
*
|
223
|
+
* @param {string} key Id to use for lookup.
|
224
|
+
* @returns {Object} Deserialized cookie value, undefined if the cookie does not exist.
|
225
|
+
*/
|
226
|
+
get: function(key) {
|
227
|
+
return $cookies.getObject(key);
|
228
|
+
},
|
229
|
+
|
230
|
+
/**
|
231
|
+
* @ngdoc method
|
232
|
+
* @name $cookieStore#put
|
233
|
+
*
|
234
|
+
* @description
|
235
|
+
* Sets a value for given cookie key
|
236
|
+
*
|
237
|
+
* @param {string} key Id for the `value`.
|
238
|
+
* @param {Object} value Value to be stored.
|
239
|
+
*/
|
240
|
+
put: function(key, value) {
|
241
|
+
$cookies.putObject(key, value);
|
242
|
+
},
|
243
|
+
|
244
|
+
/**
|
245
|
+
* @ngdoc method
|
246
|
+
* @name $cookieStore#remove
|
247
|
+
*
|
248
|
+
* @description
|
249
|
+
* Remove given cookie
|
250
|
+
*
|
251
|
+
* @param {string} key Id of the key-value pair to delete.
|
252
|
+
*/
|
253
|
+
remove: function(key) {
|
254
|
+
$cookies.remove(key);
|
255
|
+
}
|
256
|
+
};
|
257
|
+
|
258
|
+
}]);
|
259
|
+
|
260
|
+
/**
|
261
|
+
* @name $$cookieWriter
|
262
|
+
* @requires $document
|
263
|
+
*
|
264
|
+
* @description
|
265
|
+
* This is a private service for writing cookies
|
266
|
+
*
|
267
|
+
* @param {string} name Cookie name
|
268
|
+
* @param {string=} value Cookie value (if undefined, cookie will be deleted)
|
269
|
+
* @param {Object=} options Object with options that need to be stored for the cookie.
|
270
|
+
*/
|
271
|
+
function $$CookieWriter($document, $log, $browser) {
|
272
|
+
var cookiePath = $browser.baseHref();
|
273
|
+
var rawDocument = $document[0];
|
274
|
+
|
275
|
+
function buildCookieString(name, value, options) {
|
276
|
+
var path, expires;
|
277
|
+
options = options || {};
|
278
|
+
expires = options.expires;
|
279
|
+
path = angular.isDefined(options.path) ? options.path : cookiePath;
|
280
|
+
if (value === undefined) {
|
281
|
+
expires = 'Thu, 01 Jan 1970 00:00:00 GMT';
|
282
|
+
value = '';
|
283
|
+
}
|
284
|
+
if (angular.isString(expires)) {
|
285
|
+
expires = new Date(expires);
|
286
|
+
}
|
287
|
+
|
288
|
+
var str = encodeURIComponent(name) + '=' + encodeURIComponent(value);
|
289
|
+
str += path ? ';path=' + path : '';
|
290
|
+
str += options.domain ? ';domain=' + options.domain : '';
|
291
|
+
str += expires ? ';expires=' + expires.toUTCString() : '';
|
292
|
+
str += options.secure ? ';secure' : '';
|
293
|
+
|
294
|
+
// per http://www.ietf.org/rfc/rfc2109.txt browser must allow at minimum:
|
295
|
+
// - 300 cookies
|
296
|
+
// - 20 cookies per unique domain
|
297
|
+
// - 4096 bytes per cookie
|
298
|
+
var cookieLength = str.length + 1;
|
299
|
+
if (cookieLength > 4096) {
|
300
|
+
$log.warn("Cookie '" + name +
|
301
|
+
"' possibly not set or overflowed because it was too large (" +
|
302
|
+
cookieLength + " > 4096 bytes)!");
|
303
|
+
}
|
304
|
+
|
305
|
+
return str;
|
306
|
+
}
|
307
|
+
|
308
|
+
return function(name, value, options) {
|
309
|
+
rawDocument.cookie = buildCookieString(name, value, options);
|
310
|
+
};
|
311
|
+
}
|
312
|
+
|
313
|
+
$$CookieWriter.$inject = ['$document', '$log', '$browser'];
|
202
314
|
|
203
|
-
|
315
|
+
angular.module('ngCookies').provider('$$cookieWriter', function $$CookieWriterProvider() {
|
316
|
+
this.$get = $$CookieWriter;
|
317
|
+
});
|
204
318
|
|
205
319
|
|
206
320
|
})(window, window.angular);
|