+ 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 () {