// minibar.js, assumes that support.js has also been loaded /* --- Configuration -------------------------------------------------------- */ var server="http://www.grammaticalframework.org:41296" //var server="http://tournesol.cs.chalmers.se:41296"; //var server="http://localhost:41296"; var grammars_url=server+"/grammars/"; var tree_icon=server+"/translate/se.chalmers.cs.gf.gwt.TranslateApp/tree-btn.png"; /* --- Grammar access object ------------------------------------------------ */ var server = { // State variables (private): current_grammar_url: grammars_url+"Foods.pgf", // Methods: switch_grammar: function(grammar_name) { this.current_grammar_url=grammars_url+grammar_name; }, get_grammarlist: function(cont_name) { jsonp(grammars_url+"grammars.cgi",cont_name); }, get_languages: function(cont_name) { jsonp(this.current_grammar_url,cont_name); }, get_random: function(cont_name) { jsonp(this.current_grammar_url+"?command=random&random="+Math.random(),cont_name); }, linearize: function(tree,to,cont_name) { jsonp(this.current_grammar_url+"?command=linearize&tree=" +encodeURIComponent(tree)+"&to="+to,cont_name) }, complete: function(from,input,cont_name) { jsonp(this.current_grammar_url +"?command=complete" +"&from="+encodeURIComponent(from) +"&input="+encodeURIComponent(input), cont_name); }, translate: function(from,input,cont_name) { jsonp(this.current_grammar_url +"?command=translate" +"&from="+encodeURIComponent(from) +"&input="+encodeURIComponent(input), cont_name) } }; /* --- Initialisation ------------------------------------------------------- */ function start_minibar() { // typically called when the HTML document is loaded appendChildren(element("minibar"), [div_id("menubar"), div_id("surface"), div_id("words"), div_id("translations")]); server.get_grammarlist("show_grammarlist"); } /* --- Functions ------------------------------------------------------------ */ function show_grammarlist(grammars) { var menu=empty("select"); for(var i=0;i0) box.appendChild(word(s)); else emptycnt++; } if(emptycnt>0) //setTimeout(function(){get_translations(menu);},200); get_translations(menu); } function get_translations(menu) { server.translate(menu.current.from,menu.current.input,"show_translations"); /* jsonp(server.current_grammar_url +"?command=translate" +"&from="+encodeURIComponent(menu.current.from) +"&input="+encodeURIComponent(menu.current.input), "show_translations") */ } function show_translations(translations) { var trans=element("translations"); var cnt=translations.length; trans.innerHTML=""; trans.appendChild(wrap("h3",text(cnt<1 ? "No translations?" : cnt>1 ? ""+cnt+" translations:": "One translation:"))); for(p=0;p