/* * === Event === * * updated 2003/07/02 * * mail : peace@skipup.com * home : http://www.skipup.com/~peace/ */ function class__JEvent__(window) { var classId = Object.getClassName(arguments.callee); var $event = Object.privateId(); var CLIENT = new JClient(window); var ua = CLIENT.ua; var ie = CLIENT.ie; var nn = CLIENT.nn; var gk = CLIENT.gk; var op = CLIENT.op; var op6 = CLIENT.op6; var op7 = CLIENT.op7; var dom = CLIENT.dom; var win = CLIENT.win; var mac = CLIENT.mac; function getEvent() { if (ie) return window.event; else if (nn || gk) { for(var f = arguments.callee.caller; f != null; f = f.caller) { var e = f.arguments[0]; if (e !== void 0 && typeof e == "object" && e.toString() == "[object Event]") return e; if (f.caller == f) break; } } else if (op) { } return null; } /** * コンストラクタ * JEvent() * JEvent(Event e) * * 関数 * Event JEvent() * Event JEvent(Event e) */ var F = window[classId] = function() { var e = ie ? window.event : (arguments.length == 0 ? getEvent() : arguments[0]); if (arguments.callee === this.constructor) { if (this.constructor !== F) this.constructor = F; this[$event] = e; this.type = e.type; this.button = ie || op ? e.button : e.which; // Primary button this.button1 = this.button == 1; // Secondary button this.button2 = this.button == (ie ? 2 : 3); // Scroll button this.button3 = !nn ? (this.button == (ie ? 4 : 2)) : false; this.altKey = !nn ? e.altKey : Boolean(e.modifiers & 1); this.ctrlKey = !nn ? e.ctrlKey : Boolean(e.modifiers & 2); this.shiftKey = !nn ? e.shiftKey : Boolean(e.modifiers & 4); this.keyCode = ie || gk ? e.keyCode : (nn || op ? e.which : 0); } else { return e; } }; var FP = F.prototype; var textKeys = [ "BACKSPACE", "SHIFT", "CTRL", "ALT", "PAUSE", "ESCAPE", "HENKAN", "MUHENKAN", "PAGEUP", "PAGEDOWN", "END", "HOME", "LEFT", "UP", "RIGHT", "DOWN", "INSERT", "DELETE", "WINDOWS", "PROPERTY", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "NUMLOCK", "SCROLLLOCK", "CAPSLOCK", "KATAKANAHIRAGANA", "HANKAKUZENKAKU"]; for(var i = 0; i < textKeys.length; i++) F["KEY_" + textKeys[i]] = textKeys[i]; FP.getKey = function() { var c = this.keyCode; if (this.type == "keypress") { return String.fromCharCode(c); } else { if (win) { var m = this.shiftKey; if (ie) { switch (c) { case 8 : return F.KEY_BACKSPACE; case 9 : return "\t"; case 12 : return ""; case 13 : return "\n"; case 16 : return F.KEY_SHIFT; case 17 : return F.KEY_CTRL; case 18 : return F.KEY_ALT; case 19 : return F.KEY_PAUSE; case 20 : return F.KEY_CAPSLOCK; // Shift+CapsLock case 27 : return F.KEY_ESCAPE; case 28 : return F.KEY_HENKAN; case 29 : return F.KEY_MUHENKAN; case 33 : return F.KEY_PAGEUP; case 34 : return F.KEY_PAGEDOWN; case 35 : return F.KEY_END; case 36 : return F.KEY_HOME; case 37 : return F.KEY_LEFT; case 38 : return F.KEY_UP; case 39 : return F.KEY_RIGHT; case 40 : return F.KEY_DOWN; case 45 : return F.KEY_INSERT; case 46 : return F.KEY_DELETE; case 93 : return F.KEY_PROPERTY; case 144 : return F.KEY_NUMLOCK; case 145 : return F.KEY_SCROLLLOCK; case 240 : return F.KEY_CAPSLOCK; case 242 : return F.KEY_KATAKANAHIRAGANA; case 244 : return F.KEY_HANKAKUZENKAKU; } if (c == 48 && m) return ""; if (c == 91 || c == 92) return F.KEY_WINDOWS; if (112 <= c && c <= 123) return F["KEY_F"+(c-112+1)]; if (c == 32); // else if ((49 <= c && c <= 57) && m) c -= 49-33; // ! - ) else if (((c == 186 || c == 187) && m) || ((188 <= c && c <= 191) && !m)) c -= 186-42; // *-/ else if (c == 106 || c == 107 || c == 109 || c == 110 || c == 111) c -= 106-42; // * + - . / else if ((48 <= c && c <= 56) && !m); // 0-9 else if (96 <= c && c <= 105) c -= 96-48; // 0-9 else if (((c == 186 || c == 187) && !m) || ((188 <= c && c <= 191) && m) || (c == 192 && !m)) c -= 186-58; // :-@ else if ((65 <= c && c <= 90) && m); // A-Z else if ((219 <= c && c <= 222) && !m) c -= 219-91; // [ \ ] ^ else if (c == 226 && !m) c = 92; // \ else if (c == 226 && m) c = 95; // _ else if (c == 192 && m) c = 96; // ` else if ((65 <= c && c <= 90) && !m) c += 97-65; // a-z else if ((219 <= c && c <= 222) && m) c -= 219-123; // {-~ return String.fromCharCode(c); } else if (nn) { // 特殊キーは全て0 if (c == 0) return ""; if (c == 3) return F.KEY_PAUSE; if (c == 8) return F.KEY_BACKSPACE; if (c == 13) return "\n"; return String.fromCharCode(c); } else if (gk) { // 日本語に関するものは全て229 if (c == 8) return F.KEY_BACKSPACE; if (c == 9) return "\t"; if (c == 12) return ""; if (c == 13) return "\n"; if (c == 16) return F.KEY_SHIFT; if (c == 17) return F.KEY_CTRL; if (c == 18) return F.KEY_ALT; if (c == 19) return F.KEY_PAUSE; if (c == 27) return F.KEY_ESCAPE; if (c == 29) return F.KEY_MUHENKAN; if (c == 33) return F.KEY_PAGEUP; if (c == 34) return F.KEY_PAGEDOWN; if (c == 35) return F.KEY_END; if (c == 36) return F.KEY_HOME; if (c == 37) return F.KEY_LEFT; if (c == 38) return F.KEY_UP; if (c == 39) return F.KEY_RIGHT; if (c == 40) return F.KEY_DOWN; if (c == 45) return F.KEY_INSERT; if (c == 46) return F.KEY_DELETE; if (c == 91 || c == 92) return F.KEY_WINDOWS; if (c == 93) return F.KEY_PROPERTY; if (112 <= c && c <= 123) return F["KEY_F"+(c-112+1)]; if (c == 144) return F.KEY_NUMLOCK; if (c == 145) return F.KEY_SCROLLLOCK; if (c == 229) return F.KEY_HANKAKUZENKAKU; if (c == 240) return F.KEY_CAPSLOCK; if (c == 242) return F.KEY_KATAKANAHIRAGANA; if (c == 32); // else if (c == 48 && m) return ""; else if ((49 <= c && c <= 57) && m) c -= 49-33; // !-) else if (c == 59 && m) c = 42; // * else if (c == 61 && m) c = 43; // + else if (c == 188 && !m) c = 44; // , else if (c == 109 && !m) c = 45; // - else if (c == 190 && !m) c = 46; // . else if (c == 191 && !m) c = 47; // / else if (c == 106 || c == 107 || c == 110 || c == 111) c -= 106-42; // テンキー * + . / else if ((48 <= c && c <= 57) && !m); // 0-9 else if ((96 <= c && c <= 105) && !m) c -= 96-48; // テンキー 0-9 else if (c == 59 && !m) c = 58; // : else if (c == 61 && !m) c = 59; // ; else if (c == 188 && m) c = 60; // < else if (c == 109 && m) c = 61; // = else if (c == 190 && m) c = 62; // > else if (c == 191 && m) c = 63; // ? else if (c == 192 && !m) c = 64; // @ else if ((65 <= c && c <= 90) && m); // A-Z else if ((219 <= c && c <= 222) && !m) c -= 219-91; // [ \ ] ^ else if (c == 226 && !m) c = 92; // \ else if (c == 226 && m) c = 95; // _ else if (c == 192 && m) c = 96; // ` else if ((65 <= c && c <= 90) && !m) c += 97-65; // a-z else if (219 <= c && c <= 222) c -= 219-123; // { | } ~ return String.fromCharCode(c); } else if (op) { // 日本語入力中は殆どのキーが229に置き換わる if (c == 3) return F.KEY_PAUSE; if (c == 12) return ""; if (c == 13) return "\n"; if (c == 20) return F.KEY_CAPSLOCK; if (c == 27) return F.KEY_ESCAPE; if (c == 29) return F.KEY_MUHENKAN; if (c == 91 || c == 92) return F.KEY_WINDOWS; if (c == 93) return F.KEY_PROPERTY; if (c == 144) return F.KEY_NUMLOCK; if (c == 145) return F.KEY_SCROLLLOCK; if (c == 229) return F.KEY_HANKAKUZENKAKU; if (c == 240) return F.KEY_CAPSLOCK; if (c == 242) return F.KEY_KATAKANAHIRAGANA; if (c == 48 && m) return ""; else if ((49 <= c && c <= 57) && m) c -= 49-33; // ! - ) else if (((c == 186 || c == 187) && m) || ((188 <= c && c <= 191) && !m)) c -= 186-42; // *-/ else if (((c == 186 || c == 187) && !m) || ((188 <= c && c <= 191) && m) || (c == 192 && !m)) c -= 186-58; // :-@ else if ((65 <= c && c <= 90) && m); // A-Z else if ((219 <= c && c <= 222) && !m) c -= 219-91; // [-^ else if (c == 226 && !m) c = 92; // \ else if (c == 226 && m) c = 95; // _ else if (c == 192 && m) c = 96; // ` else if ((65 <= c && c <= 90) && !m) c += 97-65; // a-z else if ((219 <= c && c <= 222) && m) c -= 219-123; // {-~ return String.fromCharCode(c); } else { return String.fromCharCode(c); } } } }; FP.setBubble = function(v) { if (ie || gk || this[$event].cancelBubble !== void 0) this[$event].cancelBubble = !Boolean(v); }; /** * int getAbsoluteX() */ FP.getAbsoluteX = function() { if (ie) return this[$event].clientX + CLIENT.getScrollX(); else if (nn || gk || op) return this[$event].pageX; return 0; }; /** * int getAbsoluteY() */ FP.getAbsoluteY = function() { if (ie) return this[$event].clientY + CLIENT.getScrollY(); else if (nn || gk || op) return this[$event].pageY; return 0; }; /** * Point getAbsolutePosition() */ FP.getAbsolutePosition = function() { return new Point(this.getAbsoluteX(), this.getAbsoluteY()); }; /** * int getRelativeX() */ FP.getRelativeX = function() { if (ie || gk) return this[$event].clientX; else if (nn) return this[$event].pageX - CLIENT.getScrollX(); else if (op) // ■■■ return this[$event].clientX - CLIENT.getScrollX(); return 0; }; /** * int getRelativeY() */ FP.getRelativeY = function() { if (ie || gk) return this[$event].clientY; else if (nn) return this[$event].pageY - CLIENT.getScrollY(); else if (op) // ■■■ return this[$event].clientY - CLIENT.getScrollY(); return 0; }; /** * Point getRelativePosition() */ FP.getRelativePosition = function() { return new Point(this.getRelativeX(), this.getRelativeY()); }; /** * int getElementX() */ FP.getElementX = function() { if (ie || op7) return this[$event].offsetX; else if (nn || gk) return this[$event].layerX; return 0; }; /** * int getElementY() */ FP.getElementY = function() { if (ie || op7) return this[$event].offsetY; else if (nn || gk) return this[$event].layerY; return 0; }; /** * Dimesnion getElementPosition() * @see #getElementX() * @see #getElementY() */ FP.getElementPosition = function() { return new Point(this.getElementX(), this.getElementY()); }; /** * int getScreenX() */ FP.getScreenX = function() { return this[$event].screenX; }; /** * int getScreenY() */ FP.getScreenY = function() { return this[$event].screenY; }; /** * Point getScreenPosition() */ FP.getScreenPosition = function() { return new Point(this.getScreenX(), this.getScreenY()); }; // dragElement(JElement element); F.dragElement = function(element) { if (!ie && !nn && !gk && !op7) return; function $_d_() { var e = new F(); if (!e.button1) return; if (ie) { element.layer.oncontextmenu = function() { return false; }; element.layer.onselectstart = function() { return false; }; element.layer.ondragstart = function() { return false; }; } d = true; e.setBubble(false); p = e.getElementPosition(); element.setEventListener("mousemove", $_m_); element.setEventListener("mouseup", $_u_); } function $_m_() { if (d) { var e = new F(); var q = e.getAbsolutePosition(); q.sub(p); element.setPosition(q); e.setBubble(false); return false; } } function $_u_() { var e = new F(); if (!e.button1) return; if (ie) { element.layer.oncontextmenu = null; element.layer.onselectstart = null; element.layer.ondragstart = null; } d = false; element.clearEventListener("mousemove"); element.clearEventListener("mouseup"); e.setBubble(false); } var d = false; var p = null; element.addEventListener("mousedown", $_d_); }; // string toString(void); FP.toString = function() { return classId + " : " + this[$event]; }; } class__JEvent__(window);