From d4638f54bad7523907ebb6502af48470351d8f9e Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 8 Aug 2011 17:28:24 +0000 Subject: minibar: refactoring for improved modularity Two smaller objects have been factored out from the Minibar object: Input and Translations. These have been placed in two separate files: minibar_input.js and minibar_translations.js. Some common auxiliary functions have also been moved to a separate file: minibar_support.js --- .../javascript/minibar/minibar_translations.js | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/runtime/javascript/minibar/minibar_translations.js (limited to 'src/runtime/javascript/minibar/minibar_translations.js') diff --git a/src/runtime/javascript/minibar/minibar_translations.js b/src/runtime/javascript/minibar/minibar_translations.js new file mode 100644 index 000000000..bccbada67 --- /dev/null +++ b/src/runtime/javascript/minibar/minibar_translations.js @@ -0,0 +1,127 @@ +/* --- Translations object -------------------------------------------------- */ + +function Translations(server,options) { + this.server=server; + this.options=options; + + this.main=empty("div"); + this.menus=empty("span"); + + this.to_menu=empty_id("select","to_menu"); + + appendChildren(this.menus,[text(" To: "), this.to_menu]) + this.to_menu.onchange=bind(this.get_translations,this); + +} + +Translations.prototype.change_grammar=function(grammar) { + this.grammar=grammar; + + update_language_menu(this.to_menu,grammar); + insertFirst(this.to_menu,option("All","All")); + this.to_menu.value="All"; +} + +Translations.prototype.clear=function() { + this.main.innerHTML=""; +} + +Translations.prototype.translateFrom=function(current) { + this.current=current; + this.get_translations(); +} + +Translations.prototype.get_translations=function() { + with(this) { + var c=current; + if(options.show_grouped_translations) + server.translategroup({from:c.from,input:c.input}, + bind(show_groupedtranslations,this)); + else + server.translate({from:c.from,input:c.input}, + bind(show_translations,this)); + } +} + +Translations.prototype.tdt=function(tree_btn,txt) { + with(this) { + return options.show_trees ? tda([tree_btn,txt]) : td(txt); + } +} + +Translations.prototype.target_lang=function() { + with(this) return langpart(to_menu.value,grammar.name); +} + +Translations.prototype.show_translations=function(translationResults) { + with(this) { + var trans=main; + //var to=target_lang(); // wrong + var to=to_menu.value; + var cnt=translationResults.length; + //trans.translations=translations; + trans.single_translation=[]; + 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([td(text(lin[i].tree))])); + } + trans.appendChild(wrap("table",tbody)); + } + } + } +} -- cgit v1.2.3