[hg] galaxy 2619: Merge
details: http://www.bx.psu.edu/hg/galaxy/rev/3ca815c4be07 changeset: 2619:3ca815c4be07 user: James Taylor <james@jamestaylor.org> date: Mon Aug 24 15:55:39 2009 -0400 description: Merge 1 file(s) affected in this change: static/scripts/json_cookie.js diffs (66 lines): diff -r 9c325f3656b5 -r 3ca815c4be07 static/scripts/json_cookie.js --- a/static/scripts/json_cookie.js Mon Aug 24 15:53:17 2009 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - JSONCookie: Uses JSON to allow the settings of multiple preferences in one cookie. - Kanwei Li, 2009 - - cookie = new JSONCookie("cookie_name"); // Pass in the name of the cookie - - // Gets the value of a preference, returns optional second argument if pref not found - cookie.get("pref", "val_if_not_found"); - - cookie.set("pref", "val"); // Sets a value for the preference and saves cookie - cookie.unset("pref"); // Unsets the preference and saves cookie - cookie.clear() // Deletes the cookie - -*/ - -function JSONCookie(name) { - this.cookie_name = name; - -} - -JSONCookie.prototype = { - json_data : function() { - cookie = $.cookie(this.cookie_name); - return cookie ? JSON.parse(cookie) : null; - }, - - save : function(data) { - $.cookie(this.cookie_name, JSON.stringify(data)); - }, - - get : function(attr, else_val) { - data = this.json_data(); - if (data && data[attr]) { return data[attr]; - } else if (else_val) { return else_val; - } else { return null; - } - }, - - set : function(attr, val) { - data = this.json_data(); - if (data) { - data[attr] = val; - } else { - data = { attr : val } - } - this.save(data); - }, - - unset : function(attr) { - data = this.json_data(); - if (data) { - delete data[attr]; - } - this.save(data); - }, - - clear : function() { - this.save(null); - } - -}; \ No newline at end of file
participants (1)
-
Nate Coraor