/* * === Client Information Class === * * updated 2003/07/02 * * mail : peace@skipup.com * home : http://www.skipup.com/~peace/ */ /** * インスタンス変数. * Window window * Document document * HTMLElement documentElement * String platform * String ua * String name * String version * boolean ie * boolean nn * boolean gk * boolean op * boolean dom * boolean win * boolean mac * boolean ie4 * boolean ie5 * boolean ie6 * boolean op6 * boolean op7 * boolean ns4 * boolean ns6 * boolean ns7 * int compatMode * boolean declaredDoctype * * */ function class__JClient__(window) { var classId = Object.getClassName(arguments.callee); var $window = Object.privateId(); var $document = Object.privateId(); //var $body = Object.privateId(); // 読み込み完了前は無効なため× var $documentElement = Object.privateId(); var $listeners = Object.privateId(); /** * JClient() * JClient(Window frame) */ var F = window[classId] = function(frame) { if (this.constructor !== F) this.constructor = F; this[$window] = frame === void 0 ? window : frame; this[$document] = this[$window].document; var w = this[$window]; var d = this[$document]; this.platform = w.navigator.platform; var ua = this.ua = w.navigator.userAgent; this.name = w.navigator.appName; this.version = parseInt(w.navigator.appVersion); this.nn = d.layers !== void 0; this.gk = ua.indexOf("Gecko") != -1; this.ie = !this.gk && d.all !== void 0 && w.opera === void 0; this.op = ua.indexOf("Opera") != -1 || w.opera !== void 0; this.dom = d.getElementById !== void 0; this.win = ua.indexOf("Win") != -1; this.mac = ua.indexOf("Mac") != -1; this.ie4 = this.ie && !this.dom; this.ie5 = this.ie && ua.indexOf("MSIE 5") != -1; this.ie6 = this.ie && ua.indexOf("MSIE 6") != -1; this.op6 = this.op && (ua.indexOf("Opera/6") != -1 || ua.indexOf("Opera 6") != -1); this.op7 = this.op && (ua.indexOf("Opera/7") != -1 || ua.indexOf("Opera 7") != -1); this.ns4 = this.nn; this.ns6 = ua.indexOf("Netscape6") != -1; this.ns7 = ua.indexOf("Netscape7") != -1; /** * DOCTYPEによる互換モード,標準モードを示す. * 0 : BackCompat, 1 : CSS1Compat * *NS6, IE6, Mac版IE5のみ */ this.compatMode = 0; { if (d.compatMode === void 0) this.compatMode = 0; else if (d.compatMode == "BackCompat") this.compatMode = 0; else if (d.compatMode == "CSS1Compat") this.compatMode = 1; } /** * DOCTYPE宣言の有無を示す. * DOCTYPE宣言があるとき真. * *IE6専用 */ this.declaredDoctype = false; { if (this.ie6) this.declaredDoctype = d.documentElement.clientWidth != 0 || d.documentElement.clientHeight != 0; } /** * 表示領域エレメント. */ this[$documentElement] = d.documentElement !== void 0 ? d.documentElement : new Object(); }; var FP = F.prototype; var ZEROS = new Array("", "0", "00"); /** * Object getTransparency() */ FP.getTransparency = function() { return this.ie || this.op ? "" : (this.gk ? "transparent" : (this.nn ? null : "")); }; /** * void setBackgroundColor() * void setBackgroundColor(String color) * void setBackgroundColor(JColor color) */ FP.setBackgroundColor = function(v) { var c = ""; if (Boolean(v)) { if (typeof v == "string") { c = v.charAt(0) != '#' ? "#" + v : v; } else { c = v.toHtmlColor(); } } else c = this.getTransparency(); if (this.ie || this.dom) { //if (this.win && this.ie6 && this.declaredDoctype) { // this[$document].body.style.backgroundColor = this.getTransparency(); // this[$documentElement].style.backgroundColor = c; //} else { this[$document].body.style.backgroundColor = c; //} } else if (this.nn) this[$document].bgColor = c; }; /** * 背景色の取得. * String getBackgroundColor() * @return RRggBB形式. */ FP.getBackgroundColor = function() { var c = ""; if (this.nn) c = this[$document].bgColor; else { if (this[$documentElement].style !== void 0) c = this[$documentElement].style.backgroundColor; if (c == "" && this[$document].body.style !== void 0) c = this[$document].body.style.backgroundColor; if (c == "" && this[$document].bgColor !== void 0) c = this[$document].bgColor; } if (c.indexOf("rgb") == 0) { var k = c.substring(4, c.length - 1).split(','); for (var i = 0; i < 3; i++) { k[i] = parseInt(k[i]); k[i] = k[i] < 0x10 ? "0" + k[i].toString(16) : k[i].toString(16); } return k[0] + "" + k[1] + "" + k[2]; } else return c.substring(1); }; /** * 表示領域の幅を取得. * * int getWidth() * 表示領域の幅を取得(スクロールバー除く). * @return スクロールバーの幅を除く表示領域の幅. * * int getWidth(boolean includeScrollbar) * 表示領域の幅を取得. * @param includeScrollbar *Win IE5, Win IE6のみ*, * 真のとき,スクロールバーを含む表示領域の幅を取得します. * @return 表示領域の幅. */ FP.getWidth = function() { if (arguments.length == 1 && arguments[0]) { if (this.win && this.ie6) return this[$documentElement].offsetWidth; else if (this.win && this.ie5) return this[$document].body.offsetWidth; else return this.getWidth(false); } else { if (this[$window].innerWidth !== void 0) return this[$window].innerWidth; else if (Boolean(this[$documentElement].clientWidth)) return this[$documentElement].clientWidth; else if (this[$document].body.clientWidth !== void 0) return this[$document].body.clientWidth; else return 0; } }; /** * 表示領域の高さを取得. * * int getHeight() * 表示領域の高さを取得(スクロールバー除く). * @return スクロールバーの高さを除く表示領域の高さ. * 対応していないとき,0を返す. * * int getHeight(boolean includeScrollbar) * 表示領域の高さを取得. * @param includeScrollbar *Win IE5, Win IE6のみ*, * 真のとき,スクロールバーを含む表示領域の高さを取得します. * @return 表示領域の高さ. */ FP.getHeight = function() { if (arguments.length == 1 && arguments[0]) { if (this.win && this.ie6) return this[$documentElement].offsetHeight; else if (this.win && this.ie5) return this[$document].body.offsetHeight; else return this.getHeight(false); } else { if (this[$window].innerHeight !== void 0) return this[$window].innerHeight; else if (Boolean(this[$documentElement].clientHeight)) return this[$documentElement].clientHeight; else if (this[$document].body.clientHeight !== void 0) return this[$document].body.clientHeight; else return 0; } }; /** * 表示領域のサイズを取得. * * Dimension getSize() * 表示領域のサイズを取得(スクロールバー除く). * @return スクロールバーを除く表示領域のサイズ. * 対応していないとき,[0, 0]を返す. * * Dimension getSize(boolean includeScrollbar) * 表示領域のサイズを取得. * @param includeScrollbar *Win IE5, Win IE6のみ * 真のとき,スクロールバーを含む表示領域のサイズを取得. */ FP.getSize = function(b) { if (arguments.length == 0) { return new Dimension(this.getWidth(), this.getHeight()); } else { return new Dimension(this.getWidth(b), this.getHeight(b)); } }; /** * int f(void); * BODY要素の幅を取得する. * *Win IE6 doc, Mozilla1.0(Netscape 6不可)のみ. * @return BODY要素対応ブラウザのみ,BODY要素の幅を返します. * 未対応ブラウザは#getWidth()で得られる値を返します. */ FP.getBodyWidth = function() { if ((this.win && this.ie6 && this.declaredDoctype) || this.gk) return this[$document].body.offsetWidth; else return this.getWidth(); }; /** * int f(void); * BODY要素の高さを取得する. * *IE 6.0 Win doc, IE 5 Mac, Mozilla 1.0, Opera 6のみ. * @return BODY要素対応ブラウザのみ,BODY要素の高さを返します. * 未対応ブラウザは#getHeight()で得られる値を返します. */ FP.getBodyHeight = function() { if ((this.win && this.ie6 && this.declaredDoctype) || (this.mac && this.ie5) || this.gk || this.op6) return this[$document].body.offsetHeight; else return this.getHeight(); }; /** * Point f(void); * BODY要素のサイズを取得. * *完全対応はWinIE 6 doc, Mozilla 1.0のみ. * @return BODY要素対応ブラウザのみ,BODY要素のサイズを正確に返します. * @see #getBodyWidth() * @see #getBodyHeight() */ FP.getBodySize = function() { return new Dimension(this.getBodyWidth(), this.getBodyHeight()); }; /** * int getHtmlWidth() * HTML要素の幅を取得. * *Win IE5, Win IE6, Mozilla1.0のみ. * @return HTML要素対応ブラウザのみ,HTML要素の幅を返します. * 未対応ブラウザは#getWidth()で得られる値を返します. */ FP.getHtmlWidth = function() { if ((this.win && this.ie5) || (this.win && this.ie6 && !this.declaredDoctype)) return this[$document].body.scrollWidth; else if ((this.win && this.ie6 && this.declaredDoctype) || this.gk) return this[$documentElement].scrollWidth; else return this.getWidth(); }; /** * int getHtmlHeight() * HTML要素の高さを取得. * *Win IE5, Win IE6, Mac IE5, Mozilla1.0のみ. * @return HTML要素対応ブラウザのみ,HTML要素の高さを返します. * 未対応ブラウザは#getHeight()で得られる値を返します. */ FP.getHtmlHeight = function() { if ((this.win && this.ie5) || (this.win && this.ie6 && !this.declaredDoctype)) return this[$document].body.scrollHeight; else if ((this.win && this.ie6 && this.declaredDoctype) || this.gk) return this[$documentElement].scrollHeight; else if (this.mac && this[$documentElement].offsetHeight) return this[$documentElement].offsetHeight; else return this.getHeight(); }; /** * Point getHtmlSize() * HTML要素のサイズを取得. * *完全対応はWin IE5, Win IE6, Mozilla1.0のみ. * @return HTML要素対応ブラウザのみ,HTML要素のサイズを正確に返します. * @see #getHtmlWidth() * @see #getHtmlHeight() */ FP.getHtmlSize = function() { return new Dimension(this.getHtmlWidth(), this.getHtmlHeight()); }; /** * int getScrollX() */ FP.getScrollX = function() { if (this[$window].pageXOffset !== void 0) return this[$window].pageXOffset; else if (Boolean(this[$documentElement].scrollLeft)) return this[$documentElement].scrollLeft; else if (this[$document].body.scrollLeft !== void 0) return this[$document].body.scrollLeft; else return 0; }; /** * int getScrollY() */ FP.getScrollY = function() { if (this[$window].pageYOffset !== void 0) return this[$window].pageYOffset; else if (Boolean(this[$documentElement].scrollTop)) return this[$documentElement].scrollTop; else if (this[$document].body.scrollTop !== void 0) return this[$document].body.scrollTop; else return 0; }; /** * Point getScroll() */ FP.getScroll = function() { return new Point(this.getScrollX(), this.getScrollY()); }; /** * void setEventListener(string type, function listener) */ FP.setEventListener = function(t, l) { t = t.toLowerCase(); if (this.gk && t == "dblclick") this[$document].addEventListener(t, l, true); else { if (this.nn) this[$document].captureEvents(Event[t.toUpperCase()]); this[$document]["on"+t] = l; } }; /** * void clearEventListener(String type) * void clearEventListener(String type, function listener) */ FP.clearEventListener = function(t) { t = t.toLowerCase(); if (this.gk && t == "dblclick") this[$document].removeEventListener(t, arguments[1], true); else this[$document]["on"+t] = null; }; /** * void addEventListener(string type, function listener) */ FP.addEventListener = function(t, l) { if (this[$listeners] === void 0) { this[$listeners] = {}; this[$listeners].listenerOf = function(t) { var $cp = this; return function(e) { for (var i = 0; i < $cp[t].length; i++) { if (Boolean($cp[t][i])) $cp[t][i](e); } }; }; } t = t.toLowerCase(); var listeners = this[$listeners]; if (listeners[t] === void 0) listeners[t] = []; // function[] if (this.gk && t == "dblclick") this[$document].addEventListener(t, l, true); else { if (this.nn) this[$document].captureEvents(Event[t.toUpperCase()]); this[$document]["on"+t] = listeners.listenerOf(t); listeners[t][listeners[t].length] = l; } }; /** * boolean removeEventListener(string type, function listener) * boolean removeEventListener(string type, int index) */ FP.removeEventListener = function(t, l) { if (this[$listeners] === void 0) return false; t = t.toLowerCase(); var listeners = this[$listeners]; if (this.gk && t == "dblclick") { this[$document].removeEventListener(t, l, true); return true; } else { if (typeof l != "number") { for (var i = 0; i < listeners[t].length; i++) { if (listeners[t][i] === l) { listeners[t][i] = null; return true; } } return false; } else { if (Boolean(listeners[t][l])) return this.removeEventListener(t, listeners[t][l]); else return false; } } }; /** * HTMLElement[] getElementsByTagName(String tagName) * HTMLElement[] getElementsByTagName(String tagName, HTMLElement target) * HTMLElement[] getElementsByTagName(String tagName, HTMLElement target, Array elements) */ FP.getElementsByTagName = function(tagname, target, elements) { if (target === void 0) target = !this.nn ? this[$document].body : this[$window]; if (elements === void 0) elements = new Array(); if (this.ie) { var tmps = target.all.tags(tagname); for (var i = 0, n = tmps.length; i < n; i++) elements[i] = tmps[i]; return elements; } else if (this.nn) { var propname; switch (tagname.toLowerCase()) { case "img" : propname = "images"; break; case "a" : propname = "links"; break; default : propname = "layers"; } return function(p, t, e) { var tmps = t.document[p]; for (var i = 0; i < tmps.length; i++) e.push(tmps[i]); for (var i = 0; i < t.document.layers.length; i++) { var l = t.document.layers[i]; if (l.document[p].length != 0) e = arguments.callee(p, l, e); } return e; }(propname, target, elements); } else if (this.gk) { if (target === this[$document].body) { var tmps = this[$document].getElementsByTagName(tagname); for (var i = 0; i < tmps.length; i++) elements[i] = tmps[i]; return elements; } else { tagname = tagname.toUpperCase(); return function(t, e) { for (var i = 0; i < t.childNodes.length; i++) { var c = t.childNodes[i]; if (c.toString().match(/object HTML.*Element/) != null) { if (c.tagName == tagname) e[e.length] = c; if (c.childNodes.length != 0) e = arguments.callee(c, e); } } return e; }(target, elements); } } else if (this.op) { // if (target === this[$document].body) { var tmps = this[$document].getElementsByTagName(tagname); for (var i = 0; i < tmps.length; i++) elements[i] = tmps[i]; return elements; } else return elements; } else return elements; }; /** * String toString() */ FP.toString = function() { return classId + " : " + this.platform + " \/ " + this.name + " " + this.version; }; /** * String paramString() */ FP.paramString = function() { var t = ""; for (var propName in this) { var prop = this[propName]; if (typeof prop == "function") prop = "function() { ... }"; t += prop + "\t" +prop + "\n"; } return t; }; } class__JClient__(window);