From 5481f395f850d84b1c2a31e8f33db50840f66eee Mon Sep 17 00:00:00 2001 From: Walter Lee Davis Date: Mon, 23 Sep 2013 20:43:19 -0400 Subject: [PATCH] updated cookiejar to 1.5.1 - bugfix --- ajax/libs/cookiejar/0.5.1/README.md | 25 +++++ ajax/libs/cookiejar/0.5.1/cookiejar.js | 138 +++++++++++++++++++++++++ ajax/libs/cookiejar/package.json | 53 +++++----- 3 files changed, 193 insertions(+), 23 deletions(-) create mode 100644 ajax/libs/cookiejar/0.5.1/README.md create mode 100644 ajax/libs/cookiejar/0.5.1/cookiejar.js diff --git a/ajax/libs/cookiejar/0.5.1/README.md b/ajax/libs/cookiejar/0.5.1/README.md new file mode 100644 index 000000000..6914a86be --- /dev/null +++ b/ajax/libs/cookiejar/0.5.1/README.md @@ -0,0 +1,25 @@ +JavaScript code to store data as JSON strings in cookies. +It uses prototype.js 1.5.1 or newer (http://www.prototypejs.org) + +Author : Lalit Patel +Website: http://www.lalit.org/lab/jsoncookies +License: Apache Software License 2 + http://www.apache.org/licenses/LICENSE-2.0 +Version: 0.5.1 +Updated: Sep 21, 2013 + +Change Log: + +* v 0.5.1 + - Bug fixes, corrected typos. + - Added set() alias for put() +* v 0.5 + - Changed License from CC to Apache 2 +* v 0.4 + - Removed a extra comma in options (was breaking in IE and Opera). (Thanks Jason) + - Removed the parameter name from the initialize function + - Changed the way expires date was being calculated. (Thanks David) +* v 0.3 + - Removed dependency on json.js (http://www.json.org/json.js) + - empty() function only deletes the cookies set by CookieJar + diff --git a/ajax/libs/cookiejar/0.5.1/cookiejar.js b/ajax/libs/cookiejar/0.5.1/cookiejar.js new file mode 100644 index 000000000..972f58b3d --- /dev/null +++ b/ajax/libs/cookiejar/0.5.1/cookiejar.js @@ -0,0 +1,138 @@ +var CookieJar = Class.create(); + +CookieJar.prototype = { + + /** + * Prepend before all cookie names to differentiate them. + */ + prependString: "__CJ_", + + /** + * Initializes the cookie jar with the options. + */ + initialize: function(options) { + this.options = { + expires: 3600, // seconds (1 hr) + path: '', // cookie path + domain: '', // cookie domain + secure: '' // secure ? + }; + Object.extend(this.options, options || {}); + + if (this.options.expires != '') { + var date = new Date(); + date = new Date(date.getTime() + (this.options.expires * 1000)); + this.options.expires = '; expires=' + date.toGMTString(); + } + if (this.options.path != '') { + this.options.path = '; path=' + escape(this.options.path); + } + if (this.options.domain != '') { + this.options.domain = '; domain=' + escape(this.options.domain); + } + if (this.options.secure == 'secure') { + this.options.secure = '; secure'; + } else { + this.options.secure = ''; + } + }, + + /** + * Adds a name value pair. + */ + put: function(name, value) { + name = this.prependString + name; + cookie = this.options; + var type = typeof value; + switch(type) { + case 'undefined': + case 'function' : + case 'unknown' : return false; + case 'boolean' : + case 'string' : + case 'number' : value = String(value.toString()); + } + var cookie_str = name + "=" + escape(Object.toJSON(value)); + try { + document.cookie = cookie_str + cookie.expires + cookie.path + cookie.domain + cookie.secure; + } catch (e) { + return false; + } + return true; + }, + + set: function(name, value){ + this.put(name, value); + }, + + /** + * Removes a particular cookie (name value pair) from the Cookie Jar. + */ + remove: function(name) { + name = this.prependString + name; + cookie = this.options; + try { + var date = new Date(); + date.setTime(date.getTime() - (3600 * 1000)); + var expires = '; expires=' + date.toGMTString(); + document.cookie = name + "=" + expires + cookie.path + cookie.domain + cookie.secure; + } catch (e) { + return false; + } + return true; + }, + + /** + * Return a particular cookie by name; + */ + get: function(name) { + name = this.prependString + name; + var cookies = document.cookie.match(name + '=(.*?)(;|$)'); + if (cookies) { + return (unescape(cookies[1])).evalJSON(); + } else { + return null; + } + }, + + /** + * Empties the Cookie Jar. Deletes all the cookies. + */ + empty: function() { + keys = this.getKeys(); + size = keys.size(); + for(var i=0; i