diff --git a/src/www/js/wc.js b/src/www/js/wc.js index 5395c9618..2b12ca322 100644 --- a/src/www/js/wc.js +++ b/src/www/js/wc.js @@ -4,8 +4,8 @@ wc.f=document.forms[0] wc.o=element("output") wc.e=element("extra") wc.p=element("pick") -wc.serial=0 wc.os=[] // output segment list +wc.cache={} // output segment cache, indexed by source text wc.local=appLocalStorage("gf.wc.") wc.delayed_translate=function() { @@ -43,9 +43,7 @@ wc.load=function() { } wc.translate=function() { - var current= ++wc.serial var f=wc.f, e=wc.e, p=wc.p - var selected= -1 /* function disable(yes) { @@ -59,18 +57,16 @@ wc.translate=function() { return s.split(/([.!?]+[ \t\n]+|\n\n+|[ \t\n]*[-•*+#]+[ \t\n]+)/) } - function translate_segment(si) { // si = segment index + function translate_segment(so) { // so = segment output var rs=[] // list of alternative translations for this segment var current_pick=0 // index of currently selected alternative - var get_more // if defined, a function that will fetch more alternatives - var output=wc.os[si].target // the element where this segment is shown function show_error(msg) { //if(e) e.innerHTML="Translation problem: "+msg+"" //else { - replaceChildren(output,text("["+msg+"]")) - output.className="error" + replaceChildren(so.target,text("["+msg+"]")) + so.target.className="error" } //disable(false) } @@ -95,32 +91,27 @@ wc.translate=function() { */ } function show_more() { - selected=si + wc.selected=so var r=rs[current_pick] if(e) e.innerHTML=(r.prob||"")+"
"+(r.tree||"") if(wc.p /*&& rs.length>1*/) show_picks() //if(f.speak.checked) wc.speak(t.text,f.to.value) - if(get_more) { - var f=get_more - get_more=null - f() - } } - output.onclick=show_more + so.target.onclick=show_more function show_trans(i) { var r=rs[i] - replaceChildren(output,text(r.text)) - wc.os[si].text=r.text - output.className=r.t.quality + replaceChildren(so.target,text(r.text)) + so.text=r.text + so.target.className=r.t.quality current_pick=i - if(selected==si) show_more() + if(wc.selected==so) show_more() } function showit2(r) { rs.push(r) var j=rs.length-1 if(current_pick==j) show_trans(j) - else if(selected==si) show_picks() + else if(wc.selected==so) show_picks() //disable(false) } function showit(r) { @@ -136,52 +127,42 @@ wc.translate=function() { function word_for_word(text,cont) { function step3(tra) { - if(wc.serial==current) { - if(tra.length>=1) { - var r=tra[0] - if(r.error!=undefined) { - if(i==0 && rs.length==0) show_error(tra[0].error) - } - else { - var r=tra[0] - if(r.linearizations) show_words(r) - } + if(tra.length>=1) { + var r=tra[0] + if(r.error!=undefined) { + if(i==0 && rs.length==0) show_error(tra[0].error) + } + else { + var r=tra[0] + if(r.linearizations) show_words(r) } - else if(i==0 && rs.length==0) - show_error("Unable to translate") } + else if(i==0 && rs.length==0) + show_error("Unable to translate") } gftranslate.wordforword(text,f.from.value,f.to.value,step3) } function trans(text,i,count) { function step3(tra) { - if(wc.serial==current) { - if(tra.length>=1) { - var r=tra[0] - if(r.error!=undefined) { - if(i==0 && rs.length==0) { - //show_error(tra[0].error) - word_for_word(text) - } - } - else { - for(var ti=0;ti=1) { + var r=tra[0] + if(r.error!=undefined) { + if(i==0 && rs.length==0) { + //show_error(tra[0].error) + word_for_word(text) + } + } + else { + for(var ti=0;ti* { padding: 0 0.5ex; } #speak { display: none; } -.colors .default_quality { background-color: #ffc; } -.colors .high_quality { background-color: #cfc; } -.colors .low_quality { background-color: #fba; } -.colors .bad_quality { background-color: #f88; } +.colors .default_quality { background-color: #ffb; } +.colors .high_quality { background-color: #bfb; } +.colors .low_quality { background-color: #fa7; } +.colors .bad_quality { background-color: #f89; } .placeholder { color: #999; } .error { color: #c00; } @@ -61,12 +62,14 @@ small { color: #666; } Colors +
- Enter text to translate above. +
+ Enter text to translate above. @@ -80,7 +83,7 @@ small { color: #666; }

-Last modified: Wed Apr 16 16:48:16 CEST 2014 +Last modified: Thu Apr 17 15:45:17 CEST 2014