From: handa Date: Thu, 4 Mar 2010 13:13:06 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ALPHA~32 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=689a85994ac22e499b3877f9d829e179450b616e;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/xex.js b/xex.js index 68e38df..2ebaf54 100644 --- a/xex.js +++ b/xex.js @@ -6,11 +6,16 @@ var Xex = { { if (! Xex.LogNode) return; - var str = ''; - if (indent != undefined) - for (var i = 0; i <= indent; i++) - str += ' '; - Xex.LogNode.value = str + arg + "\n" + Xex.LogNode.value; + if (! arg) + Xex.LogNode.value = ''; + else + { + var str = ''; + if (indent != undefined) + for (var i = 0; i <= indent; i++) + str += ' '; + Xex.LogNode.value = str + arg + "\n" + Xex.LogNode.value; + } } }; @@ -3025,224 +3030,279 @@ MIM.keypress = function (event) return; }; -MIM.Lang = { - European: new Array ('de', 'fr'), - MiddleEast: new Array ('ar', 'he'), - SouthAsia: new Array ('hi'), - SouthEastAsia: new Array ('th'), - EastAsia: new Array ('ja', 'zh'), - Other: new Array () -}; +(function () { + var lang_category = { + European: { + cs: { name: 'Czech' }, + da: { name: 'Danish' }, + el: { name: 'Greek' }, + eo: { name: 'Esperanto' }, + fr: { name: 'French' }, + hr: { name: 'Croatian' }, + hy: { name: 'Armenian' }, + kk: { name: 'Kazakh' }, + ru: { name: 'Russian' }, + sk: { name: 'Slovak' }, + sr: { name: 'Serbian' }, + sv: { name: 'Swedish' }, + vi: { name: 'Vietnamese' }, + yi: { name: 'Yiddish' } }, + MiddleEast: { + ar: { name: 'Arabic' }, + dv: { name: 'Divehi' }, + fa: { name: 'Persian' }, + he: { name: 'Hebrew' }, + kk: { name: 'Kazakh' }, + ps: { name: 'Pushto' }, + ug: { name: 'Uighur' }, + yi: { name: 'Yiddish' } }, + SouthAsia: { + as: { name: 'Assamese' }, + bn: { name: 'Bengali' }, + bo: { name: 'Tibetan' }, + gu: { name: 'Gujarati' }, + hi: { name: 'Hindi' }, + kn: { name: 'Kannada' }, + ks: { name: 'Kashmiri' }, + ml: { name: 'Malayalam' }, + mr: { name: 'Marathi' }, + ne: { name: 'Nepali' }, + or: { name: 'Oriya' }, + pa: { name: 'Panjabi' }, + sa: { name: 'Sanskirit' }, + sd: { name: 'Sindhi' }, + si: { name: 'Sinhalese' }, + ta: { name: 'Tamil' }, + te: { name: 'Telugu' }, + ur: { name: 'Urdu' } }, + SouthEastAsia: { + km: { name: 'Khmer'}, + lo: { name: 'Lao' }, + my: { name: 'Burmese' }, + tai: { name: 'Tai Viet' }, + th: { name: 'Thai' }, + vi: { name: 'Vietanamese' } }, + EastAsia: { + ii: { name: 'Yii' }, + ja: { name: 'Japanese' }, + ko: { name: 'Korean' }, + zh: { name: 'Chinese' } }, + Other: { + am: { name: 'Amharic' }, + ath: { name: 'Carrier' }, + bla: { name: 'Blackfoot' }, + cr: { name: 'Cree' }, + eo: { name: 'Esperanto' }, + iu: { name: 'Inuktitut' }, + nsk: { name: 'Naskapi' }, + oj: { name: 'Ojibwe' } } + }; + + function categorize_im () + { + var cat, lang, list, name; + for (lang in MIM.imlist) + { + list = null; + for (cat in lang_category) + if (lang_category[cat][lang]) + { + list = lang_category[cat][lang].list; + if (! list) + list = lang_category[cat][lang].list = {}; + break; + } + if (list) + for (name in MIM.imlist[lang]) + list[name] = MIM.imlist[lang][name]; + } + } -// Other -// am -// ath -// bla -// cr -// el -// eo -// iu -// nsk -// oj - -// Middle Eastern -// ar -// dv -// fa -// he -// hi -// kk -// ps -// ug -// yi* - -// South Asian -// as -// bn -// bo -// gu -// kn -// ks -// ml -// mr -// ne -// or -// pa -// sd -// sa -// si -// ta -// te -// ur - -// European -// cs -// da -// eo -// fr -// hr -// hy -// kk -// ru -// sk -// sr -// sv -// vi* -// yi* - -// East Asian -// ii -// ja -// ko -// zh - -// SouthEast Asian -// km -// lo -// my -// tai -// th -// vi* - -MIM.select_im = function (event) -{ - var target = event.target.parentNode; - while (target.tagName != "mim-select-im") - target = target.parentNode; - var idx = 0; - var im = false; - for (var lang in MIM.imlist) - for (var name in MIM.imlist[lang]) - if (idx++ == target.selectedIndex) - { - im = MIM.imlist[lang][name]; - break; - } - document.getElementsByTagName ('body')[0].removeChild (target); - target.target.focus (); - if (im && im != MIM.current) - { - MIM.current = im; - Xex.Log ('select IM: ' + im.name); - } -}; + var destroy_timer; -MIM.destroy_menu = function (event) -{ - if (event.target.tagName == "mim-select-im") - document.getElementsByTagName ('body')[0].removeChild (event.target); -}; + function destroy () + { + clearTimeout (destroy_timer); + var target = document.getElementById ('mim-menu'); + if (target) + document.getElementsByTagName ('body')[0].removeChild (target); + } -MIM.select_menu = function (event) -{ - var target = event.target; - var sel; + function destroy_menu () { destroy_timer = setTimeout (destroy, 1000); } - if (! ((target.type == "text" || target.type == "textarea") - && event.which == 1 && event.ctrlKey)) - return; - if (! sel) - { - sel = document.createElement ('select'); - sel.onclick = MIM.select_im; - sel.onmouseout = MIM.destroy_menu; - sel.style.position='absolute'; - sel.style.left = (event.clientX - 10) + "px"; - sel.style.top = (event.clientY - 10) + "px"; - sel.target = target; - var idx = 0; - for (var lang in MIM.imlist) - for (var name in MIM.imlist[lang]) + var last_target; + + function show_submenu (event) + { + if (destroy_timer) + clearTimeout (destroy_timer); + var target = event.target; + if (target.menu_level) + { + if (last_target && last_target.menu_level <= target.menu_level) { - var option = document.createElement ('option'); - var imname = lang + "-" + name; - option.appendChild (document.createTextNode (imname)); - option.value = imname; - sel.appendChild (option); - if (MIM.imlist[lang][name] == MIM.current) - sel.selectedIndex = idx; - idx++; + last_target.style.backgroundColor = 'white'; + var uls = last_target.getElementsByTagName ('ul'); + for (var i = 0; i < uls.length; i++) + uls[i].style.visibility = 'hidden'; } - sel.size = idx; - } - document.getElementsByTagName ('body')[0].appendChild (sel); -}; + last_target = target; + target.style.backgroundColor = 'yellow'; + target.lastChild.style.visibility = 'visible'; + target.lastChild.style.left = target.clientWidth + 'px'; + event.preventDefault (); + } + } + + function hide_submenu (event) + { + var target = event.target; + target.style.backgroundColor = 'white'; + for (var ul = target.firstChild; ul; ul = ul.nextSibling) + if (ul.tagName == 'UL') + ul.style.visibility = 'hidden'; + } + + function select_im (event) + { + var target = event.target.parentNode; + while (target.tagName != "mim-menu") + target = target.parentNode; + var idx = 0; + var im = false; + for (var lang in MIM.imlist) + for (var name in MIM.imlist[lang]) + if (idx++ == target.selectedIndex) + { + im = MIM.imlist[lang][name]; + break; + } + document.getElementsByTagName ('body')[0].removeChild (target); + target.target.focus (); + if (im && im != MIM.current) + { + MIM.current = im; + Xex.Log ('select IM: ' + im.name); + } + } -MIM.select_menu = function (event) -{ - var target = event.target; var menu; - if (! ((target.type == "text" || target.type == "textarea") - && event.which == 1 && event.ctrlKey)) - return; - if (! menu) - { - menu = document.createElement ('ul'); - menu.style.margin = '0'; - menu.style.padding = '0'; - menu.id = 'mim-select-im'; - menu.onclick = MIM.select_im; - menu.onmouseout = MIM.destroy_menu; - menu.style.position='absolute'; - menu.style.left = (event.clientX - 10) + "px"; - menu.style.top = (event.clientY - 10) + "px"; - menu.style['border-bottom'] = '1px solid #ccc'; - menu.style['background-color'] = 'white'; - menu.target = target; - var idx = 0; - for (var lang in MIM.imlist) - { - var li = document.createElement ('li'); - li.style.position = 'relative'; - li.style['list-style']= 'none'; - li.style.margin = '0'; - li.style.padding = '0'; - li.onmouseover = function () + function create_menu (event) + { + var target = event.target; + + if (! ((target.type == "text" || target.type == "textarea") + && event.which == 1 && event.ctrlKey)) + return; + if (! menu) + { + categorize_im (); + menu = document.createElement ('ul'); + menu.style.fontFamily = 'sans-serif'; + menu.style.fontWeight = 'bold'; + menu.style.margin = '0px'; + menu.style.padding = '0px'; + menu.style.border = '1px solid gray'; + menu.style.borderBottom = 'none'; + menu.style.backgroundColor = 'white'; + menu.style.position='absolute'; + menu.style.left = (event.clientX - 10) + "px"; + menu.style.top = (event.clientY - 10) + "px"; + //menu.style.width = '100px'; + menu.id = 'mim-menu'; + menu.onclick = select_im; + menu.onmouseout = destroy_menu; + menu.target = target; + var idx = 0; + for (var catname in lang_category) { - this.style.backgroundColor = 'yellow'; - var children = this.getElementsByTagName ('ul'); - for (var i = children.length - 1; i >= 0; i--) + var cat = lang_category[catname]; + var li = document.createElement ('li'); + li.menu_level = 1; + li.style.position = 'relative'; + li.style.listStyle= 'none'; + li.style.margin = '0'; + li.style.padding = '1px'; + li.style.borderBottom = '1px solid gray'; + li.onmouseover = show_submenu; + //li.onmouseout = hide_submenu; + li.appendChild (document.createTextNode (catname)); + var sub = document.createElement ('ul'); + sub.style.position = 'absolute'; + sub.style.margin = '0px'; + sub.style.padding = '0px'; + sub.style.border = '1px solid gray'; + sub.style.borderBottom = 'none'; + sub.style.top = '-1px'; + //sub.style.width = '100px'; + sub.style.listStyle = 'disc inside'; + sub.style.visibility = 'hidden'; + sub.style.backgroundColor = 'white'; + li.appendChild (sub); + for (var langname in cat) { - children[i].display = 'block'; - children[i].visibility = 'visible'; - children[i].left = '100px'; - } - children = this.getElementsByTagName ('li'); - for (var i = children.length - 1; i >= 0; i--) - { - children[i].display = 'block'; - children[i].visibility = 'visible'; - children[i].left = '100px'; + var lang = cat[langname]; + if (! lang.list) + continue; + var sub_li = document.createElement ('li'); + sub_li.menu_level = 2; + sub_li.style.position = 'relative'; + sub_li.style.padding = '1px'; + sub_li.style.borderBottom = '1px solid gray'; + sub_li.style.listStyle= 'none'; + sub_li.style.backgroundColor = 'white'; + //sub_li.onmouseover = show_submenu; + //sub_li.onmouseout = hide_submenu; + sub_li.appendChild (document.createTextNode (lang.name)); + sub.appendChild (sub_li); + var subsub = document.createElement ('ul'); + subsub.style.position = 'absolute'; + subsub.style.margin = '0px'; + subsub.style.padding = '0px'; + subsub.style.border = '1px solid gray'; + subsub.style.borderBottom = 'none'; + subsub.style.top = '-1px'; + //subsub.style.width = '100px'; + //subsub.style.listStyle = 'disc inside'; + subsub.style.visibility = 'hidden'; + subsub.style.backgroundColor = 'white'; + for (var name in lang.list) + { + var im = lang.list[name]; + var subsub_li = document.createElement ('li'); + subsub_li.menu_level = 3; + subsub_li.style.position = 'relative'; + subsub_li.style.padding = '1px'; + subsub_li.style.borderBottom = '1px solid gray'; + subsub_li.style.listStyle= 'none'; + subsub_li.style.backgroundColor = 'white'; + //subsub_li.onmouseover = show_submenu; + //subsub_li.onmouseout = hide_submenu; + subsub_li.appendChild (document.createTextNode (im.name)); + subsub_li.im = im; + subsub.appendChild (subsub_li); + } + sub_li.appendChild (subsub); + idx++; } - }; - li.onmouseout = function () { this.style.backgroundColor = 'white'; }; - li.appendChild (document.createTextNode (lang)); - var sub = document.createElement ('ul'); - sub.style.position = 'absolute'; - sub.style.top = '0px'; - sub.style.visibility = 'hidden'; - li.appendChild (sub); - for (var name in MIM.imlist[lang]) - { - var sub_li = document.createElement ('li'); - var imname = ' ' + lang + "-" + name; - sub_li.style.position = 'absolute'; - sub_li.style.top = '0px'; - sub_li.style['list-style']= 'none'; - //sub_li.style.visibility = 'hidden'; - sub_li.appendChild (document.createTextNode (imname)); - sub.appendChild (sub_li); - if (MIM.imlist[lang][name] == MIM.current) - menu.selectedIndex = idx; - idx++; - } - menu.appendChild (li); - } - menu.size = idx; - } - document.getElementsByTagName ('body')[0].appendChild (menu); -}; + menu.appendChild (li); + } + document.mimmenu = menu; + } + document.getElementsByTagName ('body')[0].appendChild (menu); + }; + + MIM.init = function () + { + MIM.add_event_listener (window, 'keydown', MIM.keydown); + MIM.add_event_listener (window, 'keypress', MIM.keypress); + MIM.add_event_listener (window, 'mousedown', create_menu); + if (window.location == 'http://localhost/mim/index.html') + MIM.server = 'http://localhost/mim'; + MIM.current = MIM.imlist['vi']['telex']; + }; +}) (); MIM.test = function () { @@ -3267,19 +3327,10 @@ MIM.test = function () } -MIM.init = function () -{ - MIM.add_event_listener (window, 'keydown', MIM.keydown); - MIM.add_event_listener (window, 'keypress', MIM.keypress); - MIM.add_event_listener (window, 'mousedown', MIM.select_menu); - if (window.location == 'http://localhost/mim/index.html') - MIM.server = 'http://localhost/mim'; - MIM.current = MIM.imlist['vi']['telex']; -}; - MIM.init_debug = function () { MIM.debug = true; Xex.LogNode = document.getElementById ('log'); + Xex.Log (null); MIM.init (); };