material_raingular 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/lib/assets/javascripts/ajax_errors.js.coffee +13 -0
- data/lib/assets/javascripts/dateconverter.coffee +23 -0
- data/lib/assets/javascripts/directives/ngauthorize.js.coffee +8 -0
- data/lib/assets/javascripts/directives/ngautocomplete.js.coffee +135 -0
- data/lib/assets/javascripts/directives/ngboolean.js.coffee +34 -0
- data/lib/assets/javascripts/directives/ngchangeonblur.js.coffee +19 -0
- data/lib/assets/javascripts/directives/ngcreate.js.coffee +27 -0
- data/lib/assets/javascripts/directives/ngdestroy.js.coffee +24 -0
- data/lib/assets/javascripts/directives/ngdownload.js.coffee +8 -0
- data/lib/assets/javascripts/directives/ngdrag.js.coffee +122 -0
- data/lib/assets/javascripts/directives/ngfade.js.coffee +21 -0
- data/lib/assets/javascripts/directives/ngload.js.coffee +16 -0
- data/lib/assets/javascripts/directives/ngmatches.js.coffee +14 -0
- data/lib/assets/javascripts/directives/ngpopup.js.coffee +37 -0
- data/lib/assets/javascripts/directives/ngrepeatlist.js.coffee +52 -0
- data/lib/assets/javascripts/directives/ngslide.js.coffee +82 -0
- data/lib/assets/javascripts/directives/ngswipe.js.coffee +60 -0
- data/lib/assets/javascripts/directives/ngupdate.js.coffee +62 -0
- data/lib/assets/javascripts/directives/ngupload.js.coffee +127 -0
- data/lib/assets/javascripts/directives/ngwatchcontent.js.coffee +13 -0
- data/lib/assets/javascripts/directives/ngwatchshow.js.coffee +15 -0
- data/lib/assets/javascripts/directives/table.js.coffee +43 -0
- data/lib/assets/javascripts/directives/textarea.coffee +11 -0
- data/lib/assets/javascripts/directives/video.js.coffee +10 -0
- data/lib/assets/javascripts/factory_name.js.coffee +9 -0
- data/lib/assets/javascripts/material_raingular.js.coffee +17 -0
- data/lib/material_raingular/version.rb +3 -0
- data/lib/material_raingular.rb +8 -0
- data/lib/tasks/material_raingular.rake +42 -0
- data/material_raingular.gemspec +25 -0
- data/vendor/assets/angular/.jshintrc +181 -0
- data/vendor/assets/angular/angular-animate.js +3708 -0
- data/vendor/assets/angular/angular-aria.js +378 -0
- data/vendor/assets/angular/angular-cookies.js +320 -0
- data/vendor/assets/angular/angular-loader.js +429 -0
- data/vendor/assets/angular/angular-material.min.css +6 -0
- data/vendor/assets/angular/angular-material.min.js +14 -0
- data/vendor/assets/angular/angular-message-format.js +980 -0
- data/vendor/assets/angular/angular-messages.js +678 -0
- data/vendor/assets/angular/angular-resource.js +668 -0
- data/vendor/assets/angular/angular-route.js +991 -0
- data/vendor/assets/angular/angular-sanitize.js +683 -0
- data/vendor/assets/angular/angular-touch.js +627 -0
- data/vendor/assets/angular/angular.js +28133 -0
- metadata +139 -0
@@ -0,0 +1,378 @@
|
|
1
|
+
/**
|
2
|
+
* @license AngularJS v1.4.0
|
3
|
+
* (c) 2010-2015 Google, Inc. http://angularjs.org
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
(function(window, angular, undefined) {'use strict';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @ngdoc module
|
10
|
+
* @name ngAria
|
11
|
+
* @description
|
12
|
+
*
|
13
|
+
* The `ngAria` module provides support for common
|
14
|
+
* [<abbr title="Accessible Rich Internet Applications">ARIA</abbr>](http://www.w3.org/TR/wai-aria/)
|
15
|
+
* attributes that convey state or semantic information about the application for users
|
16
|
+
* of assistive technologies, such as screen readers.
|
17
|
+
*
|
18
|
+
* <div doc-module-components="ngAria"></div>
|
19
|
+
*
|
20
|
+
* ## Usage
|
21
|
+
*
|
22
|
+
* For ngAria to do its magic, simply include the module as a dependency. The directives supported
|
23
|
+
* by ngAria are:
|
24
|
+
* `ngModel`, `ngDisabled`, `ngShow`, `ngHide`, `ngClick`, `ngDblClick`, and `ngMessages`.
|
25
|
+
*
|
26
|
+
* Below is a more detailed breakdown of the attributes handled by ngAria:
|
27
|
+
*
|
28
|
+
* | Directive | Supported Attributes |
|
29
|
+
* |---------------------------------------------|----------------------------------------------------------------------------------------|
|
30
|
+
* | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
|
31
|
+
* | {@link ng.directive:ngShow ngShow} | aria-hidden |
|
32
|
+
* | {@link ng.directive:ngHide ngHide} | aria-hidden |
|
33
|
+
* | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
|
34
|
+
* | {@link module:ngMessages ngMessages} | aria-live |
|
35
|
+
* | {@link ng.directive:ngModel ngModel} | aria-checked, aria-valuemin, aria-valuemax, aria-valuenow, aria-invalid, aria-required, input roles |
|
36
|
+
* | {@link ng.directive:ngClick ngClick} | tabindex, keypress event, button role |
|
37
|
+
*
|
38
|
+
* Find out more information about each directive by reading the
|
39
|
+
* {@link guide/accessibility ngAria Developer Guide}.
|
40
|
+
*
|
41
|
+
* ##Example
|
42
|
+
* Using ngDisabled with ngAria:
|
43
|
+
* ```html
|
44
|
+
* <md-checkbox ng-disabled="disabled">
|
45
|
+
* ```
|
46
|
+
* Becomes:
|
47
|
+
* ```html
|
48
|
+
* <md-checkbox ng-disabled="disabled" aria-disabled="true">
|
49
|
+
* ```
|
50
|
+
*
|
51
|
+
* ##Disabling Attributes
|
52
|
+
* It's possible to disable individual attributes added by ngAria with the
|
53
|
+
* {@link ngAria.$ariaProvider#config config} method. For more details, see the
|
54
|
+
* {@link guide/accessibility Developer Guide}.
|
55
|
+
*/
|
56
|
+
/* global -ngAriaModule */
|
57
|
+
var ngAriaModule = angular.module('ngAria', ['ng']).
|
58
|
+
provider('$aria', $AriaProvider);
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @ngdoc provider
|
62
|
+
* @name $ariaProvider
|
63
|
+
*
|
64
|
+
* @description
|
65
|
+
*
|
66
|
+
* Used for configuring the ARIA attributes injected and managed by ngAria.
|
67
|
+
*
|
68
|
+
* ```js
|
69
|
+
* angular.module('myApp', ['ngAria'], function config($ariaProvider) {
|
70
|
+
* $ariaProvider.config({
|
71
|
+
* ariaValue: true,
|
72
|
+
* tabindex: false
|
73
|
+
* });
|
74
|
+
* });
|
75
|
+
*```
|
76
|
+
*
|
77
|
+
* ## Dependencies
|
78
|
+
* Requires the {@link ngAria} module to be installed.
|
79
|
+
*
|
80
|
+
*/
|
81
|
+
function $AriaProvider() {
|
82
|
+
var config = {
|
83
|
+
ariaHidden: true,
|
84
|
+
ariaChecked: true,
|
85
|
+
ariaDisabled: true,
|
86
|
+
ariaRequired: true,
|
87
|
+
ariaInvalid: true,
|
88
|
+
ariaMultiline: true,
|
89
|
+
ariaValue: true,
|
90
|
+
tabindex: true,
|
91
|
+
bindKeypress: true
|
92
|
+
};
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @ngdoc method
|
96
|
+
* @name $ariaProvider#config
|
97
|
+
*
|
98
|
+
* @param {object} config object to enable/disable specific ARIA attributes
|
99
|
+
*
|
100
|
+
* - **ariaHidden** – `{boolean}` – Enables/disables aria-hidden tags
|
101
|
+
* - **ariaChecked** – `{boolean}` – Enables/disables aria-checked tags
|
102
|
+
* - **ariaDisabled** – `{boolean}` – Enables/disables aria-disabled tags
|
103
|
+
* - **ariaRequired** – `{boolean}` – Enables/disables aria-required tags
|
104
|
+
* - **ariaInvalid** – `{boolean}` – Enables/disables aria-invalid tags
|
105
|
+
* - **ariaMultiline** – `{boolean}` – Enables/disables aria-multiline tags
|
106
|
+
* - **ariaValue** – `{boolean}` – Enables/disables aria-valuemin, aria-valuemax and aria-valuenow tags
|
107
|
+
* - **tabindex** – `{boolean}` – Enables/disables tabindex tags
|
108
|
+
* - **bindKeypress** – `{boolean}` – Enables/disables keypress event binding on `<div>` and
|
109
|
+
* `<li>` elements with ng-click
|
110
|
+
*
|
111
|
+
* @description
|
112
|
+
* Enables/disables various ARIA attributes
|
113
|
+
*/
|
114
|
+
this.config = function(newConfig) {
|
115
|
+
config = angular.extend(config, newConfig);
|
116
|
+
};
|
117
|
+
|
118
|
+
function watchExpr(attrName, ariaAttr, negate) {
|
119
|
+
return function(scope, elem, attr) {
|
120
|
+
var ariaCamelName = attr.$normalize(ariaAttr);
|
121
|
+
if (config[ariaCamelName] && !attr[ariaCamelName]) {
|
122
|
+
scope.$watch(attr[attrName], function(boolVal) {
|
123
|
+
if (negate) {
|
124
|
+
boolVal = !boolVal;
|
125
|
+
}
|
126
|
+
elem.attr(ariaAttr, boolVal);
|
127
|
+
});
|
128
|
+
}
|
129
|
+
};
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* @ngdoc service
|
134
|
+
* @name $aria
|
135
|
+
*
|
136
|
+
* @description
|
137
|
+
* @priority 200
|
138
|
+
*
|
139
|
+
* The $aria service contains helper methods for applying common
|
140
|
+
* [ARIA](http://www.w3.org/TR/wai-aria/) attributes to HTML directives.
|
141
|
+
*
|
142
|
+
* ngAria injects common accessibility attributes that tell assistive technologies when HTML
|
143
|
+
* elements are enabled, selected, hidden, and more. To see how this is performed with ngAria,
|
144
|
+
* let's review a code snippet from ngAria itself:
|
145
|
+
*
|
146
|
+
*```js
|
147
|
+
* ngAriaModule.directive('ngDisabled', ['$aria', function($aria) {
|
148
|
+
* return $aria.$$watchExpr('ngDisabled', 'aria-disabled');
|
149
|
+
* }])
|
150
|
+
*```
|
151
|
+
* Shown above, the ngAria module creates a directive with the same signature as the
|
152
|
+
* traditional `ng-disabled` directive. But this ngAria version is dedicated to
|
153
|
+
* solely managing accessibility attributes. The internal `$aria` service is used to watch the
|
154
|
+
* boolean attribute `ngDisabled`. If it has not been explicitly set by the developer,
|
155
|
+
* `aria-disabled` is injected as an attribute with its value synchronized to the value in
|
156
|
+
* `ngDisabled`.
|
157
|
+
*
|
158
|
+
* Because ngAria hooks into the `ng-disabled` directive, developers do not have to do
|
159
|
+
* anything to enable this feature. The `aria-disabled` attribute is automatically managed
|
160
|
+
* simply as a silent side-effect of using `ng-disabled` with the ngAria module.
|
161
|
+
*
|
162
|
+
* The full list of directives that interface with ngAria:
|
163
|
+
* * **ngModel**
|
164
|
+
* * **ngShow**
|
165
|
+
* * **ngHide**
|
166
|
+
* * **ngClick**
|
167
|
+
* * **ngDblclick**
|
168
|
+
* * **ngMessages**
|
169
|
+
* * **ngDisabled**
|
170
|
+
*
|
171
|
+
* Read the {@link guide/accessibility ngAria Developer Guide} for a thorough explanation of each
|
172
|
+
* directive.
|
173
|
+
*
|
174
|
+
*
|
175
|
+
* ## Dependencies
|
176
|
+
* Requires the {@link ngAria} module to be installed.
|
177
|
+
*/
|
178
|
+
this.$get = function() {
|
179
|
+
return {
|
180
|
+
config: function(key) {
|
181
|
+
return config[key];
|
182
|
+
},
|
183
|
+
$$watchExpr: watchExpr
|
184
|
+
};
|
185
|
+
};
|
186
|
+
}
|
187
|
+
|
188
|
+
|
189
|
+
ngAriaModule.directive('ngShow', ['$aria', function($aria) {
|
190
|
+
return $aria.$$watchExpr('ngShow', 'aria-hidden', true);
|
191
|
+
}])
|
192
|
+
.directive('ngHide', ['$aria', function($aria) {
|
193
|
+
return $aria.$$watchExpr('ngHide', 'aria-hidden', false);
|
194
|
+
}])
|
195
|
+
.directive('ngModel', ['$aria', function($aria) {
|
196
|
+
|
197
|
+
function shouldAttachAttr(attr, normalizedAttr, elem) {
|
198
|
+
return $aria.config(normalizedAttr) && !elem.attr(attr);
|
199
|
+
}
|
200
|
+
|
201
|
+
function shouldAttachRole(role, elem) {
|
202
|
+
return !elem.attr('role') && (elem.attr('type') === role) && (elem[0].nodeName !== 'INPUT');
|
203
|
+
}
|
204
|
+
|
205
|
+
function getShape(attr, elem) {
|
206
|
+
var type = attr.type,
|
207
|
+
role = attr.role;
|
208
|
+
|
209
|
+
return ((type || role) === 'checkbox' || role === 'menuitemcheckbox') ? 'checkbox' :
|
210
|
+
((type || role) === 'radio' || role === 'menuitemradio') ? 'radio' :
|
211
|
+
(type === 'range' || role === 'progressbar' || role === 'slider') ? 'range' :
|
212
|
+
(type || role) === 'textbox' || elem[0].nodeName === 'TEXTAREA' ? 'multiline' : '';
|
213
|
+
}
|
214
|
+
|
215
|
+
return {
|
216
|
+
restrict: 'A',
|
217
|
+
require: '?ngModel',
|
218
|
+
priority: 200, //Make sure watches are fired after any other directives that affect the ngModel value
|
219
|
+
compile: function(elem, attr) {
|
220
|
+
var shape = getShape(attr, elem);
|
221
|
+
|
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
|
+
};
|
229
|
+
}
|
230
|
+
},
|
231
|
+
post: function(scope, elem, attr, ngModel) {
|
232
|
+
var needsTabIndex = shouldAttachAttr('tabindex', 'tabindex', elem);
|
233
|
+
|
234
|
+
function ngAriaWatchModelValue() {
|
235
|
+
return ngModel.$modelValue;
|
236
|
+
}
|
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
|
+
};
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
function ngAriaCheckboxReaction() {
|
254
|
+
elem.attr('aria-checked', !ngModel.$isEmpty(ngModel.$viewValue));
|
255
|
+
}
|
256
|
+
|
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
|
+
}
|
292
|
+
|
293
|
+
if (needsTabIndex) {
|
294
|
+
elem.attr('tabindex', 0);
|
295
|
+
}
|
296
|
+
|
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
|
+
};
|
314
|
+
}
|
315
|
+
};
|
316
|
+
}])
|
317
|
+
.directive('ngDisabled', ['$aria', function($aria) {
|
318
|
+
return $aria.$$watchExpr('ngDisabled', 'aria-disabled');
|
319
|
+
}])
|
320
|
+
.directive('ngMessages', function() {
|
321
|
+
return {
|
322
|
+
restrict: 'A',
|
323
|
+
require: '?ngMessages',
|
324
|
+
link: function(scope, elem, attr, ngMessages) {
|
325
|
+
if (!elem.attr('aria-live')) {
|
326
|
+
elem.attr('aria-live', 'assertive');
|
327
|
+
}
|
328
|
+
}
|
329
|
+
};
|
330
|
+
})
|
331
|
+
.directive('ngClick',['$aria', '$parse', function($aria, $parse) {
|
332
|
+
return {
|
333
|
+
restrict: 'A',
|
334
|
+
compile: function(elem, attr) {
|
335
|
+
var fn = $parse(attr.ngClick, /* interceptorFn */ null, /* expensiveChecks */ true);
|
336
|
+
return function(scope, elem, attr) {
|
337
|
+
|
338
|
+
var nodeBlackList = ['BUTTON', 'A', 'INPUT', 'TEXTAREA'];
|
339
|
+
|
340
|
+
function isNodeOneOf(elem, nodeTypeArray) {
|
341
|
+
if (nodeTypeArray.indexOf(elem[0].nodeName) !== -1) {
|
342
|
+
return true;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
if (!elem.attr('role') && !isNodeOneOf(elem, nodeBlackList)) {
|
346
|
+
elem.attr('role', 'button');
|
347
|
+
}
|
348
|
+
|
349
|
+
if ($aria.config('tabindex') && !elem.attr('tabindex')) {
|
350
|
+
elem.attr('tabindex', 0);
|
351
|
+
}
|
352
|
+
|
353
|
+
if ($aria.config('bindKeypress') && !attr.ngKeypress && !isNodeOneOf(elem, nodeBlackList)) {
|
354
|
+
elem.on('keypress', function(event) {
|
355
|
+
var keyCode = event.which || event.keyCode;
|
356
|
+
if (keyCode === 32 || keyCode === 13) {
|
357
|
+
scope.$apply(callback);
|
358
|
+
}
|
359
|
+
|
360
|
+
function callback() {
|
361
|
+
fn(scope, { $event: event });
|
362
|
+
}
|
363
|
+
});
|
364
|
+
}
|
365
|
+
};
|
366
|
+
}
|
367
|
+
};
|
368
|
+
}])
|
369
|
+
.directive('ngDblclick', ['$aria', function($aria) {
|
370
|
+
return function(scope, elem, attr) {
|
371
|
+
if ($aria.config('tabindex') && !elem.attr('tabindex')) {
|
372
|
+
elem.attr('tabindex', 0);
|
373
|
+
}
|
374
|
+
};
|
375
|
+
}]);
|
376
|
+
|
377
|
+
|
378
|
+
})(window, window.angular);
|
@@ -0,0 +1,320 @@
|
|
1
|
+
/**
|
2
|
+
* @license AngularJS v1.4.0
|
3
|
+
* (c) 2010-2015 Google, Inc. http://angularjs.org
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
(function(window, angular, undefined) {'use strict';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @ngdoc module
|
10
|
+
* @name ngCookies
|
11
|
+
* @description
|
12
|
+
*
|
13
|
+
* # ngCookies
|
14
|
+
*
|
15
|
+
* The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies.
|
16
|
+
*
|
17
|
+
*
|
18
|
+
* <div doc-module-components="ngCookies"></div>
|
19
|
+
*
|
20
|
+
* See {@link ngCookies.$cookies `$cookies`} and
|
21
|
+
* {@link ngCookies.$cookieStore `$cookieStore`} for usage.
|
22
|
+
*/
|
23
|
+
|
24
|
+
|
25
|
+
angular.module('ngCookies', ['ng']).
|
26
|
+
/**
|
27
|
+
* @ngdoc provider
|
28
|
+
* @name $cookiesProvider
|
29
|
+
* @description
|
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 = {};
|
56
|
+
|
57
|
+
function calcOptions(options) {
|
58
|
+
return options ? angular.extend({}, defaults, options) : defaults;
|
59
|
+
}
|
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) {
|
87
|
+
return {
|
88
|
+
/**
|
89
|
+
* @ngdoc method
|
90
|
+
* @name $cookies#get
|
91
|
+
*
|
92
|
+
* @description
|
93
|
+
* Returns the value of given cookie key
|
94
|
+
*
|
95
|
+
* @param {string} key Id to use for lookup.
|
96
|
+
* @returns {string} Raw cookie value.
|
97
|
+
*/
|
98
|
+
get: function(key) {
|
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);
|
114
|
+
return value ? angular.fromJson(value) : value;
|
115
|
+
},
|
116
|
+
|
117
|
+
/**
|
118
|
+
* @ngdoc method
|
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
|
133
|
+
*
|
134
|
+
* @description
|
135
|
+
* Sets a value for given cookie key
|
136
|
+
*
|
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`.
|
154
|
+
* @param {Object} value Value to be stored.
|
155
|
+
* @param {Object=} options Options object.
|
156
|
+
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}
|
157
|
+
*/
|
158
|
+
putObject: function(key, value, options) {
|
159
|
+
this.put(key, angular.toJson(value), options);
|
160
|
+
},
|
161
|
+
|
162
|
+
/**
|
163
|
+
* @ngdoc method
|
164
|
+
* @name $cookies#remove
|
165
|
+
*
|
166
|
+
* @description
|
167
|
+
* Remove given cookie
|
168
|
+
*
|
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}
|
172
|
+
*/
|
173
|
+
remove: function(key, options) {
|
174
|
+
$$cookieWriter(key, undefined, calcOptions(options));
|
175
|
+
}
|
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'];
|
314
|
+
|
315
|
+
angular.module('ngCookies').provider('$$cookieWriter', function $$CookieWriterProvider() {
|
316
|
+
this.$get = $$CookieWriter;
|
317
|
+
});
|
318
|
+
|
319
|
+
|
320
|
+
})(window, window.angular);
|