/* * === Cookie Utility Class === * * updated 2003/07/02 * * mail : peace@skipup.com * home : http://www.skipup.com/~peace/ */ /** * クッキーユーティリティクラス. * * インスタンス変数. * String name * Date expiration * String path * String domain * boolean secure * Document document * boolean load */ function class__JCookie__(window) { var classId = Object.getClassName(arguments.callee); var $name = "$" + Object.privateId(); var $expiration = "$" + Object.privateId(); var $path = "$" + Object.privateId(); var $domain = "$" + Object.privateId(); var $secure = "$" + Object.privateId(); var $document = "$" + Object.privateId(); var $load = "$" + Object.privateId(); /** * コンストラクタ. * JCookie(String name, number limitDay, String path, String domain, boolean secure, Document document) */ var F = window[classId] = function() { if (this.constructor !== F) this.constructor = F; var a = arguments; this[$name] = a[0]; this[$expiration] = a[1] ? new Date(new Date().getTime() + a[1] * DAY_RATE) : null; this[$path] = a[2] ? a[2] : ""; this[$domain] = a[3] ? a[3] : ""; this[$secure] = Boolean(a[4]); this[$document] = a[5] || window.document; this[$load] = false; }; var FP = F.prototype; var DAY_RATE = 24 * 60 * 60 * 1000; F.toString = function(d) { if (d === void 0) d = window.document; return d.cookie; }; FP.store = function() { var value = ""; { for (var i in this) { if (i.charAt(0) == '$' || typeof this[i] == "function") continue; value += "&" + i + ":" + escape(this[i]); } value = value.substring(1) } var cookie = this[$name] + "=" + value; if (this[$expiration]) cookie += "; expires=" + this[$expiration].toGMTString(); if (this[$path]) cookie += "; path=" + this[$path]; if (this[$domain]) cookie += "; domain=" + this[$domain]; if (this[$secure]) cookie += "; secure"; this[$document].cookie = cookie; }; FP.load = function(f) { if (!this[$load]) { if (this[$document].cookie == "") return false; var v = this[$document].cookie.match( new RegExp(this[$name] + "=[^\\s;]+")); if (v == null) return false; var a = v[0].substring(this[$name].length + 1).split('&'); for (var i = 0; i < a.length; i++) { var p = a[i].split(':'); this[p[0]] = unescape(p[1]); } this[$load] = true; } if (f !== void 0) { if (f.indexOf('|') != -1) { var p = f.split('|'); for (var i = 0; i < p.length; i++) if (this[p[i]] === void 0) return false; } else { if (this[f] === void 0) return false; } } return true; }; FP.unload = function(f) { return !(f !== void 0 ? this.load(f) : this.load()); }; FP.remove = function(f) { if (f !== void 0) { if (f.indexOf('|') != -1) { var keys = f.split('|'); for (var i = 0, n = keys.length; i < n; i++) { var key = keys[i]; delete this[key]; } } else { delete this[f]; } this.store(); } else { var cookie = this[$name] + "="; if (this[$path]) cookie += "; path=" + this[$path]; if (this[$domain]) cookie += "; domain=" + this[$domain]; cookie += "; expires=Fri, 02-Jan-1970 00:00:00 GMT"; this[$document].cookie = cookie; } }; FP.toString = function() { return this[$document].cookie.match( new RegExp(this[$name]+"=[^\\s;]+"))[0]; }; } class__JCookie__(window);