4 // The following functions are from Cookie.js class in TinyMCE, Moxiecode, used under LGPL.
6 each : function(o, cb, s) {
14 if (typeof(o.length) != 'undefined') {
15 for (n=0, l = o.length; n<l; n++) {
16 if (cb.call(s, o[n], n, o) === false)
21 if (o.hasOwnProperty(n)) {
22 if (cb.call(s, o[n], n, o) === false) {
31 getHash : function(n) {
32 var v = this.get(n), h;
35 this.each(v.split('&'), function(v) {
44 setHash : function(n, v, e, p, d, s) {
47 this.each(v, function(v, k) {
48 o += (!o ? '' : '&') + k + '=' + v;
51 this.set(n, o, e, p, d, s);
55 var c = document.cookie, e, p = n + "=", b;
60 b = c.indexOf("; " + p);
72 e = c.indexOf(";", b);
77 return decodeURIComponent(c.substring(b + p.length, e));
80 set : function(n, v, e, p, d, s) {
81 document.cookie = n + "=" + encodeURIComponent(v) +
82 ((e) ? "; expires=" + e.toGMTString() : "") +
83 ((p) ? "; path=" + p : "") +
84 ((d) ? "; domain=" + d : "") +
85 ((s) ? "; secure" : "");
88 remove : function(n, p) {
91 d.setTime(d.getTime() - 1000);
93 this.set(n, '', d, p, d);
97 // Returns the value as string. Second arg or empty string is returned when value is not set.
98 function getUserSetting( name, def ) {
99 var o = getAllUserSettings();
101 if ( o.hasOwnProperty(name) )
104 if ( typeof def != 'undefined' )
110 // Both name and value must be only ASCII letters, numbers or underscore
111 // and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text.
112 function setUserSetting( name, value, del ) {
113 if ( 'object' !== typeof userSettings )
116 var c = 'wp-settings-' + userSettings.uid, o = wpCookies.getHash(c) || {}, d = new Date(), p,
117 n = name.toString().replace(/[^A-Za-z0-9_]/, ''), v = value.toString().replace(/[^A-Za-z0-9_]/, '');
125 d.setTime( d.getTime() + 31536000000 );
126 p = userSettings.url;
128 wpCookies.setHash(c, o, d, p);
129 wpCookies.set('wp-settings-time-'+userSettings.uid, userSettings.time, d, p);
134 function deleteUserSetting( name ) {
135 return setUserSetting( name, '', 1 );
138 // Returns all settings as js object.
139 function getAllUserSettings() {
140 if ( 'object' !== typeof userSettings )
143 return wpCookies.getHash('wp-settings-' + userSettings.uid) || {};