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=""; \
};
function toggle_debug (event)
{
- Xex.LogToggle ();
event.preventDefault ();
+ Xex.LogToggle ();
return false;
}
</script>
</head>
-<body onload="MIM.init ()">
+<body onload="MIM.init ();">
<h4>m17n-lib input method in Javascript (tested only on Chrome)</h4>
The default input method is latn-post.
Click an input area by Control-Mouse-1 to select any other input method.<br>
<!--
<br>
Please add this link
-<a href="javascript:(function(){var%20s=document.createElement(%22script%22);s.src=%22http://www.m17n.org/common/mim-js/xex.js%22;document.body.appendChild(s);s=document.createElement(%22script%22);s.src=%22http://www.m17n.org/common/mim-js/mim.js%22;document.body.appendChild(s);setTimeout(function(){MIM.init();},2000);})();">MIM-JS</a>
+<a href="javascript:(function(){var%20s=document.createElement(%22script%22);s.src=%22http://www.m17n.org/common/mim-js/xex2.js%22;document.body.appendChild(s);s=document.createElement(%22script%22);s.src=%22http://www.m17n.org/common/mim-js/mim2.js%22;document.body.appendChild(s);setTimeout(function(){MIM.init();},2000);})();">MIM-JS</a>
to the bookmark. Then, you can activate the MIM input method on any page
when you access the bookmarked link.<br>
-->
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;
}
</script>
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);
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)
{
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 ();
}
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;
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);
+ }
+ }
+}) ();