[VID-6] Initial rebase push
[vid.git] / epsdk-app-onap / src / main / webapp / app / fusion / external / ebz / angular_js / angular-cookies-1.4.js
1 /**\r
2  * @license AngularJS v1.4.0\r
3  * (c) 2010-2015 Google, Inc. http://angularjs.org\r
4  * License: MIT\r
5  */\r
6 (function(window, angular, undefined) {'use strict';\r
7 \r
8 /**\r
9  * @ngdoc module\r
10  * @name ngCookies\r
11  * @description\r
12  *\r
13  * # ngCookies\r
14  *\r
15  * The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies.\r
16  *\r
17  *\r
18  * <div doc-module-components="ngCookies"></div>\r
19  *\r
20  * See {@link ngCookies.$cookies `$cookies`} and\r
21  * {@link ngCookies.$cookieStore `$cookieStore`} for usage.\r
22  */\r
23 \r
24 \r
25 angular.module('ngCookies', ['ng']).\r
26   /**\r
27    * @ngdoc provider\r
28    * @name $cookiesProvider\r
29    * @description\r
30    * Use `$cookiesProvider` to change the default behavior of the {@link ngCookies.$cookies $cookies} service.\r
31    * */\r
32    provider('$cookies', [function $CookiesProvider() {\r
33     /**\r
34      * @ngdoc property\r
35      * @name $cookiesProvider#defaults\r
36      * @description\r
37      *\r
38      * Object containing default options to pass when setting cookies.\r
39      *\r
40      * The object may have following properties:\r
41      *\r
42      * - **path** - `{string}` - The cookie will be available only for this path and its\r
43      *   sub-paths. By default, this would be the URL that appears in your base tag.\r
44      * - **domain** - `{string}` - The cookie will be available only for this domain and\r
45      *   its sub-domains. For obvious security reasons the user agent will not accept the\r
46      *   cookie if the current domain is not a sub domain or equals to the requested domain.\r
47      * - **expires** - `{string|Date}` - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT"\r
48      *   or a Date object indicating the exact date/time this cookie will expire.\r
49      * - **secure** - `{boolean}` - The cookie will be available only in secured connection.\r
50      *\r
51      * Note: by default the address that appears in your <base> tag will be used as path.\r
52      * This is import so that cookies will be visible for all routes in case html5mode is enabled\r
53      *\r
54      **/\r
55     var defaults = this.defaults = {};\r
56 \r
57     function calcOptions(options) {\r
58       return options ? angular.extend({}, defaults, options) : defaults;\r
59     }\r
60 \r
61     /**\r
62      * @ngdoc service\r
63      * @name $cookies\r
64      *\r
65      * @description\r
66      * Provides read/write access to browser's cookies.\r
67      *\r
68      * BREAKING CHANGE: `$cookies` no longer exposes properties that represent the\r
69      * current browser cookie values. Now you must use the get/put/remove/etc. methods\r
70      * as described below.\r
71      *\r
72      * Requires the {@link ngCookies `ngCookies`} module to be installed.\r
73      *\r
74      * @example\r
75      *\r
76      * ```js\r
77      * angular.module('cookiesExample', ['ngCookies'])\r
78      *   .controller('ExampleController', ['$cookies', function($cookies) {\r
79      *     // Retrieving a cookie\r
80      *     var favoriteCookie = $cookies.get('myFavorite');\r
81      *     // Setting a cookie\r
82      *     $cookies.put('myFavorite', 'oatmeal');\r
83      *   }]);\r
84      * ```\r
85      */\r
86     this.$get = ['$$cookieReader', '$$cookieWriter', function($$cookieReader, $$cookieWriter) {\r
87       return {\r
88         /**\r
89          * @ngdoc method\r
90          * @name $cookies#get\r
91          *\r
92          * @description\r
93          * Returns the value of given cookie key\r
94          *\r
95          * @param {string} key Id to use for lookup.\r
96          * @returns {string} Raw cookie value.\r
97          */\r
98         get: function(key) {\r
99           return $$cookieReader()[key];\r
100         },\r
101 \r
102         /**\r
103          * @ngdoc method\r
104          * @name $cookies#getObject\r
105          *\r
106          * @description\r
107          * Returns the deserialized value of given cookie key\r
108          *\r
109          * @param {string} key Id to use for lookup.\r
110          * @returns {Object} Deserialized cookie value.\r
111          */\r
112         getObject: function(key) {\r
113           var value = this.get(key);\r
114           return value ? angular.fromJson(value) : value;\r
115         },\r
116 \r
117         /**\r
118          * @ngdoc method\r
119          * @name $cookies#getAll\r
120          *\r
121          * @description\r
122          * Returns a key value object with all the cookies\r
123          *\r
124          * @returns {Object} All cookies\r
125          */\r
126         getAll: function() {\r
127           return $$cookieReader();\r
128         },\r
129 \r
130         /**\r
131          * @ngdoc method\r
132          * @name $cookies#put\r
133          *\r
134          * @description\r
135          * Sets a value for given cookie key\r
136          *\r
137          * @param {string} key Id for the `value`.\r
138          * @param {string} value Raw value to be stored.\r
139          * @param {Object=} options Options object.\r
140          *    See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}\r
141          */\r
142         put: function(key, value, options) {\r
143           $$cookieWriter(key, value, calcOptions(options));\r
144         },\r
145 \r
146         /**\r
147          * @ngdoc method\r
148          * @name $cookies#putObject\r
149          *\r
150          * @description\r
151          * Serializes and sets a value for given cookie key\r
152          *\r
153          * @param {string} key Id for the `value`.\r
154          * @param {Object} value Value to be stored.\r
155          * @param {Object=} options Options object.\r
156          *    See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}\r
157          */\r
158         putObject: function(key, value, options) {\r
159           this.put(key, angular.toJson(value), options);\r
160         },\r
161 \r
162         /**\r
163          * @ngdoc method\r
164          * @name $cookies#remove\r
165          *\r
166          * @description\r
167          * Remove given cookie\r
168          *\r
169          * @param {string} key Id of the key-value pair to delete.\r
170          * @param {Object=} options Options object.\r
171          *    See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}\r
172          */\r
173         remove: function(key, options) {\r
174           $$cookieWriter(key, undefined, calcOptions(options));\r
175         }\r
176       };\r
177     }];\r
178   }]);\r
179 \r
180 angular.module('ngCookies').\r
181 /**\r
182  * @ngdoc service\r
183  * @name $cookieStore\r
184  * @deprecated\r
185  * @requires $cookies\r
186  *\r
187  * @description\r
188  * Provides a key-value (string-object) storage, that is backed by session cookies.\r
189  * Objects put or retrieved from this storage are automatically serialized or\r
190  * deserialized by angular's toJson/fromJson.\r
191  *\r
192  * Requires the {@link ngCookies `ngCookies`} module to be installed.\r
193  *\r
194  * <div class="alert alert-danger">\r
195  * **Note:** The $cookieStore service is deprecated.\r
196  * Please use the {@link ngCookies.$cookies `$cookies`} service instead.\r
197  * </div>\r
198  *\r
199  * @example\r
200  *\r
201  * ```js\r
202  * angular.module('cookieStoreExample', ['ngCookies'])\r
203  *   .controller('ExampleController', ['$cookieStore', function($cookieStore) {\r
204  *     // Put cookie\r
205  *     $cookieStore.put('myFavorite','oatmeal');\r
206  *     // Get cookie\r
207  *     var favoriteCookie = $cookieStore.get('myFavorite');\r
208  *     // Removing a cookie\r
209  *     $cookieStore.remove('myFavorite');\r
210  *   }]);\r
211  * ```\r
212  */\r
213  factory('$cookieStore', ['$cookies', function($cookies) {\r
214 \r
215     return {\r
216       /**\r
217        * @ngdoc method\r
218        * @name $cookieStore#get\r
219        *\r
220        * @description\r
221        * Returns the value of given cookie key\r
222        *\r
223        * @param {string} key Id to use for lookup.\r
224        * @returns {Object} Deserialized cookie value, undefined if the cookie does not exist.\r
225        */\r
226       get: function(key) {\r
227         return $cookies.getObject(key);\r
228       },\r
229 \r
230       /**\r
231        * @ngdoc method\r
232        * @name $cookieStore#put\r
233        *\r
234        * @description\r
235        * Sets a value for given cookie key\r
236        *\r
237        * @param {string} key Id for the `value`.\r
238        * @param {Object} value Value to be stored.\r
239        */\r
240       put: function(key, value) {\r
241         $cookies.putObject(key, value);\r
242       },\r
243 \r
244       /**\r
245        * @ngdoc method\r
246        * @name $cookieStore#remove\r
247        *\r
248        * @description\r
249        * Remove given cookie\r
250        *\r
251        * @param {string} key Id of the key-value pair to delete.\r
252        */\r
253       remove: function(key) {\r
254         $cookies.remove(key);\r
255       }\r
256     };\r
257 \r
258   }]);\r
259 \r
260 /**\r
261  * @name $$cookieWriter\r
262  * @requires $document\r
263  *\r
264  * @description\r
265  * This is a private service for writing cookies\r
266  *\r
267  * @param {string} name Cookie name\r
268  * @param {string=} value Cookie value (if undefined, cookie will be deleted)\r
269  * @param {Object=} options Object with options that need to be stored for the cookie.\r
270  */\r
271 function $$CookieWriter($document, $log, $browser) {\r
272   var cookiePath = $browser.baseHref();\r
273   var rawDocument = $document[0];\r
274 \r
275   function buildCookieString(name, value, options) {\r
276     var path, expires;\r
277     options = options || {};\r
278     expires = options.expires;\r
279     path = angular.isDefined(options.path) ? options.path : cookiePath;\r
280     if (value === undefined) {\r
281       expires = 'Thu, 01 Jan 1970 00:00:00 GMT';\r
282       value = '';\r
283     }\r
284     if (angular.isString(expires)) {\r
285       expires = new Date(expires);\r
286     }\r
287 \r
288     var str = encodeURIComponent(name) + '=' + encodeURIComponent(value);\r
289     str += path ? ';path=' + path : '';\r
290     str += options.domain ? ';domain=' + options.domain : '';\r
291     str += expires ? ';expires=' + expires.toUTCString() : '';\r
292     str += options.secure ? ';secure' : '';\r
293 \r
294     // per http://www.ietf.org/rfc/rfc2109.txt browser must allow at minimum:\r
295     // - 300 cookies\r
296     // - 20 cookies per unique domain\r
297     // - 4096 bytes per cookie\r
298     var cookieLength = str.length + 1;\r
299     if (cookieLength > 4096) {\r
300       $log.warn("Cookie '" + name +\r
301         "' possibly not set or overflowed because it was too large (" +\r
302         cookieLength + " > 4096 bytes)!");\r
303     }\r
304 \r
305     return str;\r
306   }\r
307 \r
308   return function(name, value, options) {\r
309     rawDocument.cookie = buildCookieString(name, value, options);\r
310   };\r
311 }\r
312 \r
313 $$CookieWriter.$inject = ['$document', '$log', '$browser'];\r
314 \r
315 angular.module('ngCookies').provider('$$cookieWriter', function $$CookieWriterProvider() {\r
316   this.$get = $$CookieWriter;\r
317 });\r
318 \r
319 \r
320 })(window, window.angular);\r