Ticket #757 (closed enhancement: fixed)
add removeOptionCookie() function to core
| Reported by: | EricShulman | Owned by: | JeremyRuston |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.4.3 |
| Component: | core | Version: | |
| Severity: | low | Keywords: | |
| Cc: |
Description (last modified by EricShulman) (diff)
The core function, saveOptionCookie(), creates a browser cookie that stores the current value of the specified option. However, when an option is reset to it's hard-coded default value, rather than removing the cookie, it is usually just set to that default value, which results in an accumulation of unnecessary cookies.
Unfortunately, there is a browser-imposed limit on the number of cookies that are stored for any given domain and, when that limit is reached, the browser starts discarding cookies on it's own, thereby unexpectedly losing some TW settings.
In order to allow core and/or plugin code to 'clean up after themselves' and remove unneeded cookies, the core should provide a function, removeOptionCookie() that is the inverse of the existing saveOptionCookie(), and results in the actual deletion of the associated browser cookie.
window.removeOptionCookie=function(cookie) {
var ex=new Date();
ex.setTime(ex.getTime()-1000); // immediately expire cookie
document.cookie = cookie+"=novalue; path=/; expires="+ex.toGMTString();
}
Note: this approach is currently being used by several TiddlyTools plugins and scripts. For example, NestedSlidersPlugin? only creates a cookie to track a slider's opened/closed condition if that slider is currently in it's non-default state (i.e., an open slider that starts out closed, or a closed slider that starts out opened). When the slider is returned to it's default state, the corresponding tracking cookie is completely *removed* (as opposed to simply setting it's value to "false"), thereby minimizing the number of active cookies being used to track sliders.
Also note that this proposal is only to add the core utility function... it would then still remain up to the individual bits of core and/or plugin code to actually start using this function to remove some of their cookies as appropriate.
