PageSourceSearch

https://biovea.com/us/scripts/angular-cookies-1.5.0.js

js biovea.com collected 2026-10-01 14:09:01 UTC 12,700 bytes, 323 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.