From: handa Date: Thu, 25 Mar 2010 07:24:52 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ALPHA~2 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0eb9adf6e42434704f52f04a5d79ea5219da118e;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/Makefile b/Makefile index 123272e..49948e6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ DIST=/project/web/extra/m17n-lib/mim-js/ -FILES=index.html test.html imlist.xml xex.js mim.js loadxml.html /usr/local/work/m17n-db-xml/MIM/*.mimx +FILES=index.html index2.html test.html imlist.xml xex.js mim.js xex2.js mim2.js loadxml.html /usr/local/work/m17n-db-xml/MIM/*.mimx upload: @updated=""; \ diff --git a/index2.html b/index2.html index 94c85b7..54500a4 100644 --- a/index2.html +++ b/index2.html @@ -63,14 +63,14 @@ }; function toggle_debug (event) { - Xex.LogToggle (); event.preventDefault (); + Xex.LogToggle (); return false; } - +

m17n-lib input method in Javascript (tested only on Chrome)

The default input method is latn-post. Click an input area by Control-Mouse-1 to select any other input method.
@@ -86,7 +86,7 @@ Click an input area by Control-Mouse-1 to select any other input method.
diff --git a/loadxml.html b/loadxml.html index d5ca545..b4aef8b 100644 --- a/loadxml.html +++ b/loadxml.html @@ -9,12 +9,12 @@ var href = window.location.href; alert ('loadxml called: ' + href); var xmlfile = href.substring (thisurl.length + 1); - alert ('loading ' + xmlfile); + //alert ('loading ' + xmlfile); var obj = new XMLHttpRequest (); obj.open ('GET', xmlfile, false); obj.send (''); window.parent.postMessage (obj.responseText, '*'); - alert ('message sent to parent: ' + obj.responseText.length + 'chars'); + //alert ('message sent to parent: ' + obj.responseText.length + 'chars'); return false; } diff --git a/mim2.js b/mim2.js index 3df31e3..2bb2370 100644 --- a/mim2.js +++ b/mim2.js @@ -1051,7 +1051,6 @@ MIM.im_domain.DefType (MIM.State.prototype); var vname = node.attributes['vname'].nodeValue; if (this != MIM.im_global) { - alert ("getting global var of vname:"+vname); var vari = get_global_var (vname); if (vari != null) this.domain.Defvar (vname, vari.desc, vari.val, vari.range); @@ -1152,26 +1151,31 @@ MIM.im_domain.DefType (MIM.State.prototype); MIM.im_domain, null); }; - function load_im (node) + function load_im (node, im) { - this.map_list = {}; - this.initial_state = null; - this.state_list = {}; + //alert ('Loading IM (' + im + ':' + im.lang + '-' + im.name + ')'); + im.map_list = {}; + im.initial_state = null; + im.state_list = {}; for (node = node.firstElement (); node; node = node.nextElement ()) { var name = node.nodeName; + //Xex.Log ('parsing ' + name); var parser = parsers[name]; if (parser) - parser.call (this, node); + parser.call (im, node); } - this.load_status = MIM.LoadStatus.Loaded; + //alert ('initial state = ' + im.initial_state); + im.load_status = MIM.LoadStatus.Loaded; } - MIM.IM.prototype.Load = function () - { - this.load_status = MIM.LoadStatus.Loading; - Xex.Load (MIM.server, this.file, load_im); - } + MIM.IM.prototype = { + Load: function () + { + this.load_status = MIM.LoadStatus.Loading; + Xex.Load (MIM.server, this.file, load_im, this); + } + }; MIM.IC = function (im, target) { @@ -1729,7 +1733,6 @@ MIM.im_domain.DefType (MIM.State.prototype); MIM.im_global = new MIM.IM ('t', 'nil', 'global', null); MIM.im_global.load_status = MIM.LoadStatus.Error; } - node = undefined; MIM.current = MIM.imlist['t']['latn-post']; MIM.current.Load (); } @@ -2116,7 +2119,7 @@ MIM.keydown = function (event) if (! ic || ic.im != MIM.current) { target.mim_ic = null; - Xex.Log ('creating IC'); + Xex.Log ('creating IC for ' + MIM.current.lang + '-' + MIM.current.name); ic = new MIM.IC (MIM.current, target); if (ic.im.load_status != MIM.LoadStatus.Loaded) return true; diff --git a/xex2.js b/xex2.js index 0d6ceb1..02ab5ce 100644 --- a/xex2.js +++ b/xex2.js @@ -1361,24 +1361,49 @@ Xex.LoadOld = function (server, file) return (obj.responseXML && obj.responseXML.firstChild); }; -Xex.Load = function (server, file, callback) -{ - var body = document.getElementsByTagName ('body')[0]; - var iframe = document.createElement ('iframe'); +(function () { + var queue = new Array (); + var iframe; + function receiver (event) { - //alert ('receiver called:'+event.data); + var request = queue.shift (); + alert ('received: ' + request[0]); + alert ('queue length = ' + queue.length); var parser = new DOMParser (); var xml = parser.parseFromString (event.data, 'text/xml'); //alert ('parsed:'+xml); - window.removeEventListener ('message', receiver, false); - body.removeChild (iframe); - callback (xml.firstElement ()); + request[1] (xml.firstElement (), request[2]); + alert ('queue length = ' + queue.length); + if (queue.length > 0) + { + document.getElementsByTagName ('body')[0].removeChild (iframe); + iframe.src = queue[0][0]; + document.getElementsByTagName ('body')[0].appendChild (iframe); + } + else + { + window.removeEventListener ('message', receiver, false); + document.getElementsByTagName ('body')[0].removeChild (iframe); + alert ('queue cleared'); + } + event.preventDefault (); }; - Xex.xml = undefined; - window.addEventListener ('message', receiver, false); - iframe.src = server + '/loadxml.html#' + file; - //alert ('iframe created'); - body.appendChild (iframe); -}; + + Xex.Load = function (server, file, callback, arg) + { + var url = server + '/loadxml.html#' + file; + alert ('loading file:' + file); + queue.push ([url, callback, arg]); + if (queue.length == 1) + { + window.addEventListener ('message', receiver, false); + iframe = document.createElement ('iframe'); + iframe.style.display = 'none'; + iframe.src = url; + //alert ('iframe created'); + document.getElementsByTagName ('body')[0].appendChild (iframe); + } + } +}) ();