*** empty log message ***
[m17n/m17n-lib-js.git] / mim.js
diff --git a/mim.js b/mim.js
index abde0a9..2461427 100644 (file)
--- a/mim.js
+++ b/mim.js
@@ -31,7 +31,7 @@ var MIM = {
   // Boolean flag to tell if MIM is running in debug mode or not.
   debug: false,
   // List of main input methods.
-  imlist: {},
+  imlist: null,
   // List of extra input methods;
   imextra: {},
   // Global input method data
@@ -1686,47 +1686,56 @@ MIM.im_domain.DefType (MIM.State.prototype);
       return (! this.key_unhandled
              && this.produced.length == 0);
     }
-  }
+  };
 
-  // Load the list of input methods.
-  var node = Xex.Load (MIM.server, "imlist.xml");
-  for (node = node.firstChild; node; node = node.nextSibling)
-    if (node.nodeName == 'input-method')
-      {
-       var lang = null, name = null, extra_id = null, file = null;
+  MIM.Load = function () {
+    if (MIM.imlist)
+      return;
+    MIM.imlist = {};
+    // Load the list of input methods.
+    var node = Xex.Load (MIM.server, "imlist.xml");
+    for (node = node.firstChild; node; node = node.nextSibling)
+      if (node.nodeName == 'input-method')
+       {
+         var lang = null, name = null, extra_id = null, file = null;
 
-       for (var n = node.firstChild; n; n = n.nextSibling)
-         {
-           if (n.nodeName == 'language')
-             lang = n.firstChild.nodeValue;
-           else if (n.nodeName == 'name')
-             name = n.firstChild.nodeValue;
-           else if (n.nodeName == 'extra-id')
-             extra_id = n.firstChild.nodeValue;
-           else if (n.nodeName == 'filename')
-             file = n.firstChild.nodeValue;
-         }
-       if (name && name != 'nil')
-         {
-           if (! MIM.imlist[lang])
-             MIM.imlist[lang] = {};
-           MIM.imlist[lang][name] = new MIM.IM (lang, name, extra_id, file);
-         }
-       else if (extra_id && extra_id != 'nil')
-         {
-           if (! MIM.imextra[lang])
-             MIM.imextra[lang] = {};
-           MIM.imextra[lang][extra_id] = new MIM.IM (lang, name, extra_id, file);
-         }
+         for (var n = node.firstChild; n; n = n.nextSibling)
+           {
+             if (n.nodeName == 'language')
+               lang = n.firstChild.nodeValue;
+             else if (n.nodeName == 'name')
+               name = n.firstChild.nodeValue;
+             else if (n.nodeName == 'extra-id')
+               extra_id = n.firstChild.nodeValue;
+             else if (n.nodeName == 'filename')
+               file = n.firstChild.nodeValue;
+           }
+         if ((lang == 'ja' && name == 'anthy')
+             || (lang == 'en' && name == 'ispell'))
+           continue;
+         if (name && name != 'nil')
+           {
+             if (! MIM.imlist[lang])
+               MIM.imlist[lang] = {};
+             MIM.imlist[lang][name] = new MIM.IM (lang, name, extra_id, file);
+           }
+         else if (extra_id && extra_id != 'nil')
+           {
+             if (! MIM.imextra[lang])
+               MIM.imextra[lang] = {};
+             MIM.imextra[lang][extra_id] = new MIM.IM (lang, name, extra_id, file);
+           }
+       }
+    if (MIM.imextra.t && MIM.imextra.t.global)
+      MIM.im_global = MIM.imextra.t.global;
+    else
+      {
+       MIM.im_global = new MIM.IM ('t', 'nil', 'global', null);
+       MIM.im_global.load_status = MIM.LoadStatus.Error;
       }
-  if (MIM.imextra.t && MIM.imextra.t.global)
-    MIM.im_global = MIM.imextra.t.global;
-  else
-    {
-      MIM.im_global = new MIM.IM ('t', 'nil', 'global', null);
-      MIM.im_global.load_status = MIM.LoadStatus.Error;
-    }
-  node = undefined;
+    node = undefined;
+    MIM.current = MIM.imlist['t']['latn-post'];
+  }
 }) ();
 
 (function () {
@@ -2106,6 +2115,7 @@ MIM.keydown = function (event)
   if (! (target.type == "text" || target.type == "textarea"))
     return;
 
+  MIM.Load ();
   var ic = target.mim_ic;
   if (! ic || ic.im != MIM.current)
     {
@@ -2284,6 +2294,9 @@ MIM.keypress = function (event)
        var nodes = target.getElementsByTagName ('ul');
        for (var i = 0; i < nodes.length; i++)
          nodes[i].style.visibility = 'hidden';
+       nodes = target.getElementsByTagName ('pre');
+       for (var i = 0; i < nodes.length; i++)
+         nodes[i].style.visibility = 'hidden';
        document.getElementsByTagName ('body')[0].removeChild (target);
       }
   }    
@@ -2316,16 +2329,32 @@ MIM.keypress = function (event)
            last_target = last_target.parentLi;
            last_target.style.backgroundColor = 'white';
          }
-       var uls = last_target.getElementsByTagName ('ul');
-       for (var i = 0; i < uls.length; i++)
-         uls[i].style.visibility = 'hidden';
+       var nodes = last_target.getElementsByTagName ('ul');
+       for (var i = 0; i < nodes.length; i++)
+         nodes[i].style.visibility = 'hidden';
+       nodes = last_target.getElementsByTagName ('pre');
+       for (var i = 0; i < nodes.length; i++)
+         nodes[i].style.visibility = 'hidden';
       }
     last_target = target;
     target.style.backgroundColor = 'yellow';
     if (target.menu_level < 3)
       {
-       target.lastChild.style.visibility = 'visible';
-       target.lastChild.style.left = target.clientWidth + 'px';
+       if (false)
+         {
+           target.lastChild.style.visibility = 'visible';
+           target.lastChild.style.left = target.clientWidth + 'px';
+         }
+       else
+         {
+       var left = target.clientWidth;
+       for (var n = target.firstElement ().nextElement (); n; n = n.nextElement ()) 
+         {
+           n.style.visibility = 'visible';
+           n.style.left = left + 'px';
+           left += n.clientWidth;
+         }
+         }
       }
     event.preventDefault ();   
   }
@@ -2353,6 +2382,7 @@ MIM.keypress = function (event)
   function create_ul (visibility)
   {
     var ul = document.createElement ('ul');
+    ul.name = 'elm';
     ul.style.position = 'absolute';
     ul.style.margin = '0px';
     ul.style.padding = '0px';
@@ -2380,6 +2410,21 @@ MIM.keypress = function (event)
     return li;
   }
 
+  function create_sep ()
+  {
+    var sep = document.createElement ('pre');
+    sep.name = 'elm';
+    sep.innerHTML = ' ';
+    sep.style.position = 'absolute';
+    sep.style.margin = '0px';
+    sep.style.padding = '2px';
+    sep.style.border = '2px solid black';
+    sep.style.top = '-1px';
+    sep.style.backgroundColor = 'black';
+    sep.style.visibility = 'hidden';
+    return sep;
+  }
+
   var menu;
 
   function create_menu (event)
@@ -2391,6 +2436,7 @@ MIM.keypress = function (event)
       return;
     if (! menu)
       {
+       MIM.Load ();
        categorize_im ();
        menu = create_ul ('visible');
        menu.style.fontFamily = 'sans-serif';
@@ -2403,6 +2449,7 @@ MIM.keypress = function (event)
          {
            var cat = lang_category[catname];
            var li = create_li (1, catname);
+           li.appendChild (create_sep ());
            var sub = create_ul ('hidden');
            for (var langname in cat)
              {
@@ -2411,6 +2458,7 @@ MIM.keypress = function (event)
                  continue;
                var sub_li = create_li (2, lang.name);
                sub_li.parentLi = li;
+               sub_li.appendChild (create_sep ());
                var subsub = create_ul ('hidden');
                for (var name in lang.list)
                  {
@@ -2438,6 +2486,5 @@ MIM.keypress = function (event)
     MIM.add_event_listener (window, 'keydown', MIM.keydown);
     MIM.add_event_listener (window, 'keypress', MIM.keypress);
     MIM.add_event_listener (window, 'mousedown', create_menu);
-    MIM.current = MIM.imlist['t']['latn-post'];
   };
 }) ();