From c88986c81d58c3158777688d0bd80f9f00ed9076 Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 17 Mar 2010 08:17:14 +0000 Subject: [PATCH] *** empty log message *** --- xex.js | 247 +++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 143 insertions(+), 104 deletions(-) diff --git a/xex.js b/xex.js index a7ed176..46d510f 100644 --- a/xex.js +++ b/xex.js @@ -2,25 +2,31 @@ var Xex = { LogNode: null, + LogNodeLen: 0, Log: function (arg, indent, cont) { if (! Xex.LogNode) return; - if (typeof indent == 'number') - return; if (! arg) - Xex.LogNode.value = ''; + { + while (Xex.LogNode.childNodes.length > 0) + Xex.LogNode.removeChild (Xex.LogNode.firstChild); + LogNodeLen = 0; + } else { - var str = ''; - if (! cont) - { - str = "\n"; - if (indent != undefined) - for (var i = 0; i <= indent; i++) - str += ' '; - } - Xex.LogNode.value += str + arg; + var node; + LogNodeLen++; + if (LogNodeLen >= 200) + node = Xex.LogNode.firstElement (); + else + node = document.createElement ('div'); + if (indent != undefined) + node.style.textIndent = (indent + 1) + 'em'; + else + node.style.textIndent = '0px'; + node.innerText = LogNodeLen + ': ' + arg; + Xex.LogNode.appendChild (node); Xex.LogNode.scrollTop = Xex.LogNode.scrollHeight; } } @@ -724,8 +730,8 @@ Xex.Funcall = function (func, vname, args) var arglist = '' var len = this.args.length; var str = '<' + this.func.name; - if (this.vari) - str += ' vname="' + this.vari.name + '"'; + if (this.vname) + str += ' vname="' + this.vname + '"'; if (len == 0) return str + '/>'; if (this.func instanceof Xex.Subrountine) @@ -3157,44 +3163,21 @@ MIM.get_range = function (target, ic) from = rr.text.length - r.text.length; to = rr.text.length; } - if (ic.range[0] == from && ic.range[1] == to - && (to == from || target.value.substring (from, to) == ic.preedit)) + if (from == to + && from == ic.range[0] + ic.cursor_pos + && (ic.preedit.length == 0 + || ic.preedit == target.value.substring (ic.range[0], ic.range[1]))) return true; + Xex.Log ('reset ic'); + ic.reset (); ic.range[0] = from; ic.range[1] = to; return false; -} - -MIM.set_caret = function (target, ic) -{ - if (target.setSelectionRange) // Mozilla - { - var scrollTop = target.scrollTop; - target.setSelectionRange (ic.range[0], ic.range[1]); - target.scrollTop = scrollTop; - } - else // IE - { - var range = target.createTextRange (); - range.moveStart ('character', ic.range[0]); - range.moveEnd ('character', ic.range[1]); - range.select (); - } -}; - -MIM.update = function (target, ic) -{ - var text = target.value; - target.value = (text.substring (0, ic.range[0]) - + ic.produced - + ic.preedit - + text.substring (ic.range[1])); - ic.range[0] += ic.produced.length; - ic.range[1] = ic.range[0] + ic.preedit.length; - MIM.set_caret (target, ic); }; (function () { + var temp; + var style_props = { width: 'width', height: 'height', @@ -3227,30 +3210,98 @@ MIM.update = function (target, ic) to.style.height = from.offsetHeight; } + MIM.get_preedit_pos = function (target, ic) + { + if (! temp) + { + temp = document.createElement ('div'); + temp.style.visibility = 'hidden'; + temp.style.position = 'absolute'; + temp.appendChild (document.createElement ('span')); + temp.appendChild (document.createElement ('span')); + document.getElementsByTagName ('body')[0].appendChild (temp); + } + if (temp.ic != ic) + { + temp.ic = ic; + copy_style (target, temp); + ic.abs_top = 0; + ic.abs_left = 0; + for (var elm = target.offsetParent; elm; elm = elm.offsetParent) + { + ic.abs_top += elm.offsetTop; + ic.abs_left += elm.offsetLeft; + } + } + temp.firstChild.innerText = target.value.substr (0, ic.range[0]); + temp.lastChild.innerText = "." + target.value.substr (ic.range[0], ic.range[1]); + ic.abs_y = (ic.abs_top + temp.lastChild.offsetTop + + temp.lastChild.offsetHeight - target.scrollTop); + ic.abs_x0 = ic.abs_left + temp.lastChild.offsetLeft; + ic.abs_x1 = ic.abs_x0 + temp.lastChild.offsetWidth; + } +}) (); + +MIM.set_caret = function (target, ic) +{ + if (ic.preedit.length > 0) + { + MIM.get_preedit_pos (target, ic); + if (! ic.bar) + { + ic.bar = document.createElement ('div'); + ic.bar.style.position = 'absolute'; + ic.bar.style.backgroundColor = "black"; + ic.bar.style.minHeight = '1px'; + document.getElementsByTagName ('body')[0].appendChild (ic.bar); + } + ic.bar.style.display = 'block' + ic.bar.style.top = (ic.abs_y + 1) + 'px'; + ic.bar.style.left = ic.abs_x0 + 'px'; + ic.bar.style.minWidth = (ic.abs_x1 - ic.abs_x0) + 'px'; + } + else if (ic.bar) + ic.bar.style.display = 'none' +}; + +MIM.update = function (target, ic, for_focus_out) +{ + var text = target.value; + target.value = (text.substring (0, ic.range[0]) + + ic.produced + + ic.preedit + + text.substring (ic.range[1])); + ic.range[0] += ic.produced.length; + ic.range[1] = ic.range[0] + ic.preedit.length; + MIM.set_caret (target, ic); + if (! for_focus_out) + { + var pos = ic.range[0] + ic.cursor_pos; + if (target.setSelectionRange) // Mozilla + { + var scrollTop = target.scrollTop; + target.setSelectionRange (pos, pos); + target.scrollTop = scrollTop; + } + else // IE + { + var range = target.createTextRange (); + range.moveStart ('character', pos); + range.moveEnd ('character', pos); + range.select (); + } + } +}; + +(function () { MIM.show = function (ic) { if (! ic.candidates) return; var target = ic.target; - if (! ic.div_node) + MIM.get_preedit_pos (target, ic); + if (! ic.can_node) { - ic.target_top = 0; - ic.target_left = 0; - for (var elm = ic.target.offsetParent; elm; elm = elm.offsetParent) - { - ic.target_top += elm.offsetTop; - ic.target_left += elm.offsetLeft; - } - ic.div_node = document.createElement ('div'); - copy_style (target, ic.div_node); - ic.div_node.style.visibility="hidden"; - ic.div_node.style.position = "absolute"; - document.getElementsByTagName ('body')[0].appendChild (ic.div_node); - ic.div_node_first = document.createElement ('span'); - ic.div_node_last = document.createElement('span'); - ic.div_node_last.innerHTML = '.'; - ic.div_node.appendChild (ic.div_node_first); - ic.div_node.appendChild (ic.div_node_last); ic.can_node = document.createElement ('table'); ic.can_node.style.position = 'absolute'; ic.can_node.style.display = 'none'; @@ -3280,12 +3331,8 @@ MIM.update = function (target, ic) tr.appendChild (td); } ic.can_node.appendChild (tr); - ic.div_node_first.innerHTML = target.value.substr (0, ic.range[0]); - var x = ic.target_left + ic.div_node.lastChild.offsetLeft; - var y = (ic.target_top + ic.div_node.lastChild.offsetTop - + ic.div_node.lastChild.offsetHeight - target.scrollTop + 10); - ic.can_node.style.left = x + 'px'; - ic.can_node.style.top = y + 'px'; + ic.can_node.style.top = (ic.abs_y + 10) + 'px'; + ic.can_node.style.left = ic.abs_x0 + 'px'; } else { @@ -3308,41 +3355,26 @@ MIM.focus_in = function (event) { var target = event.target; var ic = target.mim_ic; - if (ic.wait_update == true) - { - Xex.Log ("Focus in " + target.tagName + ' IGNORED'); - event.preventDefault (); - return false; - } Xex.Log ("Focus in " + target.tagName); + MIM.get_range (target, ic) ic.Filter (MIM.Key.FocusIn); - function up () {MIM.update (target, ic);} - setTimeout (up, 100); + setTimeout (function () { MIM.update (target, ic, false); }, 100); + return true; } MIM.focus_out = function (event) { var target = event.target; var ic = target.mim_ic; - function reset_update () { ic.wait_update = false; }; - if (ic.wait_update == true) - { - Xex.Log ("Focus out " + target.tagName + ' IGNORED'); - event.preventDefault (); - return false; - } Xex.Log ("Focus out " + target.tagName); ic.Filter (MIM.Key.FocusOut); - ic.wait_update = true; MIM.update (target, ic, true); - setTimeout (reset_update, 1000); + return true; }; MIM.keydown = function (event) { var target = event.target; - if (target.id == 'log') - return; if (! (target.type == "text" || target.type == "textarea")) return; @@ -3353,17 +3385,12 @@ MIM.keydown = function (event) Xex.Log ('creating IC'); ic = new MIM.IC (MIM.current, target); if (ic.im.load_status != MIM.LoadStatus.Loaded) - return; + return true; target.mim_ic = ic; MIM.add_event_listener (target, 'focus', MIM.focus_in); MIM.add_event_listener (target, 'blur', MIM.focus_out); - MIM.get_range (target, ic) - } - else - { - if (! MIM.get_range (target, ic)) - ic.reset (); } + MIM.get_range (target, ic) MIM.debug_print (event, ic); ic.key = MIM.decode_key_event (event); if (ic.key) @@ -3374,7 +3401,7 @@ MIM.keydown = function (event) Xex.Log ('Error' + e); throw (e); } - MIM.update (target, ic); + MIM.update (target, ic, false); if (! ic.key_unhandled) event.preventDefault (); } @@ -3383,8 +3410,6 @@ MIM.keydown = function (event) MIM.keypress = function (event) { var target = event.target; - if (target.id == 'log') - return; if (! (target.type == "text" || target.type == "textarea")) return; @@ -3408,7 +3433,7 @@ MIM.keypress = function (event) Xex.Log ('Error:' + e); throw (e); } - MIM.update (target, ic); + MIM.update (target, ic, false); if (! ic.key_unhandled) event.preventDefault (); } catch (e) { @@ -3537,18 +3562,23 @@ MIM.keypress = function (event) function destroy_menu () { if (! destroy_timer) destroy_timer = setTimeout (destroy, 1000); + return true; } function show_submenu (event) { + var target = event.target; + if (! target.menu_level) + { + if (! target.parentNode || ! target.parentNode.menu_level) + return true; + target = target.parentNode; + } if (destroy_timer) { clearTimeout (destroy_timer); destroy_timer = null; } - var target = event.target; - if (! target.menu_level) - return; if (last_target && target.parentLi != last_target) { last_target.style.backgroundColor = 'white'; @@ -3574,6 +3604,15 @@ MIM.keypress = function (event) function select_im (event) { var target = event.target; + if (! target.im) + { + if (! target.parentNode || ! target.parentNode.menu_level) + { + event.preventDefault (); + return false; + } + target = target.parentNode; + } if (target.im) { MIM.current = target.im; @@ -3628,7 +3667,7 @@ MIM.keypress = function (event) menu.style.fontFamily = 'sans-serif'; menu.style.fontWeight = 'bold'; menu.id = 'mim-menu'; - menu.onclick = select_im; + menu.onmousedown = select_im; menu.onmouseover = show_submenu; menu.onmouseout = destroy_menu; for (var catname in lang_category) @@ -3702,7 +3741,7 @@ MIM.test = function () MIM.init_debug = function () { MIM.debug = true; - Xex.LogNode = document.getElementById ('log'); + Xex.LogNode = document.getElementById ('xexlog'); Xex.Log (null); MIM.init (); }; -- 1.7.10.4