Commit 0a403424 authored by bingchuan's avatar bingchuan

[dev] version 1.8.2

parent aa8ce930
/** /**
* @license AngularJS v1.5.7 * @license AngularJS v1.8.2
* (c) 2010-2016 Google, Inc. http://angularjs.org * (c) 2010-2020 Google LLC. http://angularjs.org
* License: MIT * License: MIT
*/ */
(function(window, angular) {'use strict'; (function(window, angular) {'use strict';
/**
* @ngdoc module
* @name ngCookies
* @description
*
* # ngCookies
*
* The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies.
*
*
* <div doc-module-components="ngCookies"></div>
*
* See {@link ngCookies.$cookies `$cookies`} for usage.
*/
angular.module('ngCookies', ['ng']).
/** /**
* @ngdoc provider * @ngdoc module
* @name $cookiesProvider * @name ngCookies
* @description * @description
* Use `$cookiesProvider` to change the default behavior of the {@link ngCookies.$cookies $cookies} service. *
* */ * The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies.
provider('$cookies', [function $CookiesProvider() { *
/** * See {@link ngCookies.$cookies `$cookies`} for usage.
* @ngdoc property */
* @name $cookiesProvider#defaults
* @description
*
* Object containing default options to pass when setting cookies.
*
* The object may have following properties:
*
* - **path** - `{string}` - The cookie will be available only for this path and its
* sub-paths. By default, this is the URL that appears in your `<base>` tag.
* - **domain** - `{string}` - The cookie will be available only for this domain and
* its sub-domains. For security reasons the user agent will not accept the cookie
* if the current domain is not a sub-domain of this domain or equal to it.
* - **expires** - `{string|Date}` - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT"
* or a Date object indicating the exact date/time this cookie will expire.
* - **secure** - `{boolean}` - If `true`, then the cookie will only be available through a
* secured connection.
*
* Note: By default, the address that appears in your `<base>` tag will be used as the path.
* This is important so that cookies will be visible for all routes when html5mode is enabled.
*
**/
var defaults = this.defaults = {};
function calcOptions(options) {
return options ? angular.extend({}, defaults, options) : defaults;
}
/** angular.module('ngCookies', ['ng']).
* @ngdoc service info({ angularVersion: '1.8.2' }).
* @name $cookies /**
* * @ngdoc provider
* @description * @name $cookiesProvider
* Provides read/write access to browser's cookies. * @description
* * Use `$cookiesProvider` to change the default behavior of the {@link ngCookies.$cookies $cookies} service.
* <div class="alert alert-info"> * */
* Up until Angular 1.3, `$cookies` exposed properties that represented the provider('$cookies', [/** @this */function $CookiesProvider() {
* current browser cookie values. In version 1.4, this behavior has changed, and
* `$cookies` now provides a standard api of getters, setters etc.
* </div>
*
* Requires the {@link ngCookies `ngCookies`} module to be installed.
*
* @example
*
* ```js
* angular.module('cookiesExample', ['ngCookies'])
* .controller('ExampleController', ['$cookies', function($cookies) {
* // Retrieving a cookie
* var favoriteCookie = $cookies.get('myFavorite');
* // Setting a cookie
* $cookies.put('myFavorite', 'oatmeal');
* }]);
* ```
*/
this.$get = ['$$cookieReader', '$$cookieWriter', function($$cookieReader, $$cookieWriter) {
return {
/** /**
* @ngdoc method * @ngdoc property
* @name $cookies#get * @name $cookiesProvider#defaults
*
* @description * @description
* Returns the value of given cookie key
* *
* @param {string} key Id to use for lookup. * Object containing default options to pass when setting cookies.
* @returns {string} Raw cookie value.
*/
get: function(key) {
return $$cookieReader()[key];
},
/**
* @ngdoc method
* @name $cookies#getObject
* *
* @description * The object may have following properties:
* Returns the deserialized value of given cookie key
* *
* @param {string} key Id to use for lookup. * - **path** - `{string}` - The cookie will be available only for this path and its
* @returns {Object} Deserialized cookie value. * sub-paths. By default, this is the URL that appears in your `<base>` tag.
*/ * - **domain** - `{string}` - The cookie will be available only for this domain and
getObject: function(key) { * its sub-domains. For security reasons the user agent will not accept the cookie
var value = this.get(key); * if the current domain is not a sub-domain of this domain or equal to it.
return value ? angular.fromJson(value) : value; * - **expires** - `{string|Date}` - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT"
}, * or a Date object indicating the exact date/time this cookie will expire.
* - **secure** - `{boolean}` - If `true`, then the cookie will only be available through a
/** * secured connection.
* @ngdoc method * - **samesite** - `{string}` - prevents the browser from sending the cookie along with cross-site requests.
* @name $cookies#getAll * Accepts the values `lax` and `strict`. See the [OWASP Wiki](https://www.owasp.org/index.php/SameSite)
* for more info. Note that as of May 2018, not all browsers support `SameSite`,
* so it cannot be used as a single measure against Cross-Site-Request-Forgery (CSRF) attacks.
* *
* @description * Note: By default, the address that appears in your `<base>` tag will be used as the path.
* Returns a key value object with all the cookies * This is important so that cookies will be visible for all routes when html5mode is enabled.
* *
* @returns {Object} All cookies * @example
*/
getAll: function() {
return $$cookieReader();
},
/**
* @ngdoc method
* @name $cookies#put
*
* @description
* Sets a value for given cookie key
* *
* @param {string} key Id for the `value`. * ```js
* @param {string} value Raw value to be stored. * angular.module('cookiesProviderExample', ['ngCookies'])
* @param {Object=} options Options object. * .config(['$cookiesProvider', function($cookiesProvider) {
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults} * // Setting default options
*/ * $cookiesProvider.defaults.domain = 'foo.com';
put: function(key, value, options) { * $cookiesProvider.defaults.secure = true;
$$cookieWriter(key, value, calcOptions(options)); * }]);
}, * ```
**/
var defaults = this.defaults = {};
function calcOptions(options) {
return options ? angular.extend({}, defaults, options) : defaults;
}
/** /**
* @ngdoc method * @ngdoc service
* @name $cookies#putObject * @name $cookies
* *
* @description * @description
* Serializes and sets a value for given cookie key * Provides read/write access to browser's cookies.
* *
* @param {string} key Id for the `value`. * <div class="alert alert-info">
* @param {Object} value Value to be stored. * Up until AngularJS 1.3, `$cookies` exposed properties that represented the
* @param {Object=} options Options object. * current browser cookie values. In version 1.4, this behavior has changed, and
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults} * `$cookies` now provides a standard api of getters, setters etc.
*/ * </div>
putObject: function(key, value, options) {
this.put(key, angular.toJson(value), options);
},
/**
* @ngdoc method
* @name $cookies#remove
* *
* @description * Requires the {@link ngCookies `ngCookies`} module to be installed.
* Remove given cookie
* *
* @param {string} key Id of the key-value pair to delete. * @example
* @param {Object=} options Options object. *
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults} * ```js
* angular.module('cookiesExample', ['ngCookies'])
* .controller('ExampleController', ['$cookies', function($cookies) {
* // Retrieving a cookie
* var favoriteCookie = $cookies.get('myFavorite');
* // Setting a cookie
* $cookies.put('myFavorite', 'oatmeal');
* }]);
* ```
*/ */
remove: function(key, options) { this.$get = ['$$cookieReader', '$$cookieWriter', function($$cookieReader, $$cookieWriter) {
$$cookieWriter(key, undefined, calcOptions(options)); return {
} /**
}; * @ngdoc method
}]; * @name $cookies#get
}]); *
* @description
angular.module('ngCookies'). * Returns the value of given cookie key
/** *
* @ngdoc service * @param {string} key Id to use for lookup.
* @name $cookieStore * @returns {string} Raw cookie value.
* @deprecated */
* @requires $cookies get: function(key) {
* return $$cookieReader()[key];
* @description },
* Provides a key-value (string-object) storage, that is backed by session cookies.
* Objects put or retrieved from this storage are automatically serialized or /**
* deserialized by angular's toJson/fromJson. * @ngdoc method
* * @name $cookies#getObject
* Requires the {@link ngCookies `ngCookies`} module to be installed. *
* * @description
* <div class="alert alert-danger"> * Returns the deserialized value of given cookie key
* **Note:** The $cookieStore service is **deprecated**. *
* Please use the {@link ngCookies.$cookies `$cookies`} service instead. * @param {string} key Id to use for lookup.
* </div> * @returns {Object} Deserialized cookie value.
* */
* @example getObject: function(key) {
* var value = this.get(key);
* ```js return value ? angular.fromJson(value) : value;
* angular.module('cookieStoreExample', ['ngCookies']) },
* .controller('ExampleController', ['$cookieStore', function($cookieStore) {
* // Put cookie /**
* $cookieStore.put('myFavorite','oatmeal'); * @ngdoc method
* // Get cookie * @name $cookies#getAll
* var favoriteCookie = $cookieStore.get('myFavorite'); *
* // Removing a cookie * @description
* $cookieStore.remove('myFavorite'); * Returns a key value object with all the cookies
* }]); *
* ``` * @returns {Object} All cookies
*/ */
factory('$cookieStore', ['$cookies', function($cookies) { getAll: function() {
return $$cookieReader();
return { },
/**
* @ngdoc method /**
* @name $cookieStore#get * @ngdoc method
* * @name $cookies#put
* @description *
* Returns the value of given cookie key * @description
* * Sets a value for given cookie key
* @param {string} key Id to use for lookup. *
* @returns {Object} Deserialized cookie value, undefined if the cookie does not exist. * @param {string} key Id for the `value`.
*/ * @param {string} value Raw value to be stored.
get: function(key) { * @param {Object=} options Options object.
return $cookies.getObject(key); * See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}
}, */
put: function(key, value, options) {
/** $$cookieWriter(key, value, calcOptions(options));
* @ngdoc method },
* @name $cookieStore#put
* /**
* @description * @ngdoc method
* Sets a value for given cookie key * @name $cookies#putObject
* *
* @param {string} key Id for the `value`. * @description
* @param {Object} value Value to be stored. * Serializes and sets a value for given cookie key
*/ *
put: function(key, value) { * @param {string} key Id for the `value`.
$cookies.putObject(key, value); * @param {Object} value Value to be stored.
}, * @param {Object=} options Options object.
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}
*/
putObject: function(key, value, options) {
this.put(key, angular.toJson(value), options);
},
/**
* @ngdoc method
* @name $cookies#remove
*
* @description
* Remove given cookie
*
* @param {string} key Id of the key-value pair to delete.
* @param {Object=} options Options object.
* See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults}
*/
remove: function(key, options) {
$$cookieWriter(key, undefined, calcOptions(options));
}
};
}];
}]);
/** /**
* @ngdoc method * @name $$cookieWriter
* @name $cookieStore#remove * @requires $document
* *
* @description * @description
* Remove given cookie * This is a private service for writing cookies
* *
* @param {string} key Id of the key-value pair to delete. * @param {string} name Cookie name
*/ * @param {string=} value Cookie value (if undefined, cookie will be deleted)
remove: function(key) { * @param {Object=} options Object with options that need to be stored for the cookie.
$cookies.remove(key); */
function $$CookieWriter($document, $log, $browser) {
var cookiePath = $browser.baseHref();
var rawDocument = $document[0];
function buildCookieString(name, value, options) {
var path, expires;
options = options || {};
expires = options.expires;
path = angular.isDefined(options.path) ? options.path : cookiePath;
if (angular.isUndefined(value)) {
expires = 'Thu, 01 Jan 1970 00:00:00 GMT';
value = '';
}
if (angular.isString(expires)) {
expires = new Date(expires);
} }
};
}]);
/**
* @name $$cookieWriter
* @requires $document
*
* @description
* This is a private service for writing cookies
*
* @param {string} name Cookie name
* @param {string=} value Cookie value (if undefined, cookie will be deleted)
* @param {Object=} options Object with options that need to be stored for the cookie.
*/
function $$CookieWriter($document, $log, $browser) {
var cookiePath = $browser.baseHref();
var rawDocument = $document[0];
function buildCookieString(name, value, options) {
var path, expires;
options = options || {};
expires = options.expires;
path = angular.isDefined(options.path) ? options.path : cookiePath;
if (angular.isUndefined(value)) {
expires = 'Thu, 01 Jan 1970 00:00:00 GMT';
value = '';
}
if (angular.isString(expires)) {
expires = new Date(expires);
}
var str = encodeURIComponent(name) + '=' + encodeURIComponent(value); var str = encodeURIComponent(name) + '=' + encodeURIComponent(value);
str += path ? ';path=' + path : ''; str += path ? ';path=' + path : '';
str += options.domain ? ';domain=' + options.domain : ''; str += options.domain ? ';domain=' + options.domain : '';
str += expires ? ';expires=' + expires.toUTCString() : ''; str += expires ? ';expires=' + expires.toUTCString() : '';
str += options.secure ? ';secure' : ''; str += options.secure ? ';secure' : '';
str += options.samesite ? ';samesite=' + options.samesite : '';
// per http://www.ietf.org/rfc/rfc2109.txt browser must allow at minimum:
// - 300 cookies
// - 20 cookies per unique domain
// - 4096 bytes per cookie
var cookieLength = str.length + 1;
if (cookieLength > 4096) {
$log.warn('Cookie \'' + name +
'\' possibly not set or overflowed because it was too large (' +
cookieLength + ' > 4096 bytes)!');
}
// per http://www.ietf.org/rfc/rfc2109.txt browser must allow at minimum: return str;
// - 300 cookies
// - 20 cookies per unique domain
// - 4096 bytes per cookie
var cookieLength = str.length + 1;
if (cookieLength > 4096) {
$log.warn("Cookie '" + name +
"' possibly not set or overflowed because it was too large (" +
cookieLength + " > 4096 bytes)!");
} }
return str; return function(name, value, options) {
rawDocument.cookie = buildCookieString(name, value, options);
};
} }
return function(name, value, options) { $$CookieWriter.$inject = ['$document', '$log', '$browser'];
rawDocument.cookie = buildCookieString(name, value, options);
};
}
$$CookieWriter.$inject = ['$document', '$log', '$browser'];
angular.module('ngCookies').provider('$$cookieWriter', function $$CookieWriterProvider() { angular.module('ngCookies').provider('$$cookieWriter', /** @this */ function $$CookieWriterProvider() {
this.$get = $$CookieWriter; this.$get = $$CookieWriter;
}); });
})(window, window.angular); })(window, window.angular);
{ {
"name": "angular-cookies", "name": "angular-cookies",
"version": "1.5.7", "version": "1.8.2",
"license": "MIT", "license": "MIT",
"main": "./angular-cookies.js", "main": "./angular-cookies.js",
"ignore": [], "ignore": [],
"dependencies": { "dependencies": {
"angular": "1.5.7" "angular": "1.8.2"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment