// minibar.js, assumes that support.js has also been loaded /* --- Configuration -------------------------------------------------------- */ var default_server="http://www.grammaticalframework.org:41296" var tree_icon=default_server+"/translate/se.chalmers.cs.gf.gwt.TranslateApp/tree-btn.png"; // default values for options: var options={ server: default_server, grammars_url: null, // if left null, start_minibar() fills in server+"/grammars/" grammar_list: null, // if left null, start_minibar() will fetch a list from the server show_abstract: false, show_trees: false, show_grouped_translations: true, delete_button_text: "⌫", } /* --- Grammar access object ------------------------------------------------ */ var server = { // State variables (private): current_grammar_url: options.grammars_url+"Foods.pgf", // Methods: switch_grammar: function(grammar_name) { this.current_grammar_url=options.grammars_url+grammar_name; }, get_grammarlist: function(cont_name) { jsonp(options.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) }, translategroup: function(from,input,cont_name) { jsonp(this.current_grammar_url +"?command=translategroup" +"&from="+encodeURIComponent(from) +"&input="+encodeURIComponent(input), cont_name) } }; /* --- Initialisation ------------------------------------------------------- */ function start_minibar(opts) { // typically called when the HTML document is loaded if(opts) for(var o in opts) options[o]=opts[o]; var surface=div_id("surface"); surface.setAttribute("onclick","surface_click(this)"); appendChildren(element("minibar"), [div_id("menubar"), surface, div_id("words"), div_id("translations")]); if(!options.grammars_url) options.grammars_url=options.server+"/grammars/"; if(options.grammar_list) show_grammarlist(options.grammar_list) else server.get_grammarlist("show_grammarlist"); } /* --- Functions ------------------------------------------------------------ */ function show_grammarlist(grammars) { var menubar=element("menubar"); menubar.innerHTML=""; if(grammars.length>1) { 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) { var c=menu.current; if(options.show_grouped_translations) server.translategroup(c.from,c.input,"show_groupedtranslations"); else server.translate(c.from,c.input,"show_translations"); } function tdt(tree_btn,txt) { return options.show_trees ? tda([tree_btn,txt]) : td(txt); } function show_translations(translations) { var trans=element("translations"); var grammar=element("language_menu").grammar; var to_menu=element("to_menu"); var to=to_menu.options[to_menu.selectedIndex].value 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 1) tbody.appendChild(tr([(text(lin[i].tree))])); } trans.appendChild(wrap("table",tbody)); } } } function abstree_button(abs) { var i=img(tree_icon); i.setAttribute("onclick","toggle_img(this)"); i.other=server.current_grammar_url+"?command=abstrtree&tree="+encodeURIComponent(abs); return i; } function parsetree_button(abs,lang) { var i=img(tree_icon); i.setAttribute("onclick","toggle_img(this)"); i.other=server.current_grammar_url +"?command=parsetree&from="+lang+"&tree="+encodeURIComponent(abs); return i; } function toggle_img(i) { var tmp=i.src; i.src=i.other; i.other=tmp; } /* se.chalmers.cs.gf.gwt.TranslateApp/align-btn.png GET /grammars/Foods.pgf?&command=abstrtree&tree=Pred+(This+Fish)+(Very+Fresh) GET /grammars/Foods.pgf?&command=parsetree&tree=Pred+(This+Fish)+Expensive&from=FoodsAfr GET /grammars/Foods.pgf?&command=alignment&tree=Pred+(This+Fish)+Expensive */