From 87cc4d7624f1cd057103cc76240cb70a69a1513d Mon Sep 17 00:00:00 2001 From: hallgren Date: Fri, 30 Apr 2010 14:55:56 +0000 Subject: [PATCH] Merge phrasebook.js into minibar.js --- src/runtime/javascript/minibar/about.html | 13 +- src/runtime/javascript/minibar/minibar.html | 16 ++- src/runtime/javascript/minibar/minibar.js | 113 ++++++++++++------ .../javascript/minibar/phrasebook.html | 37 ++++++ src/runtime/javascript/minibar/support.js | 9 +- 5 files changed, 145 insertions(+), 43 deletions(-) create mode 100644 src/runtime/javascript/minibar/phrasebook.html diff --git a/src/runtime/javascript/minibar/about.html b/src/runtime/javascript/minibar/about.html index a7f275869..11e4f46f0 100644 --- a/src/runtime/javascript/minibar/about.html +++ b/src/runtime/javascript/minibar/about.html @@ -59,9 +59,6 @@ Some implementation details:
  • [Added 2010-02-25] Next to each translation, there is now a little tree icon that you can click on to see a drawing of an abstract syntax tree or a parse tree. If you click on a drawing it collapses back into a tree icon. - -Work in progress: -
    + + Last modified: Fri Apr 30 16:47:43 CEST 2010 +
    TH
    - Last modified: Mon Apr 19 18:43:48 CEST 2010 diff --git a/src/runtime/javascript/minibar/minibar.html b/src/runtime/javascript/minibar/minibar.html index 345c91e0a..1d80deb53 100644 --- a/src/runtime/javascript/minibar/minibar.html +++ b/src/runtime/javascript/minibar/minibar.html @@ -4,9 +4,21 @@ + - +

    Minibar

    @@ -18,7 +30,7 @@ & Translator] -HTML Last modified: Mon Apr 19 18:16:40 CEST 2010 +HTML Last modified: Fri Apr 30 16:48:36 CEST 2010
    TH diff --git a/src/runtime/javascript/minibar/minibar.js b/src/runtime/javascript/minibar/minibar.js index 124a7e1b9..f20fd96c5 100644 --- a/src/runtime/javascript/minibar/minibar.js +++ b/src/runtime/javascript/minibar/minibar.js @@ -2,30 +2,33 @@ /* --- 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"; +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={ - show_abstract: true, - show_trees: true + 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: grammars_url+"Foods.pgf", + current_grammar_url: options.grammars_url+"Foods.pgf", // Methods: switch_grammar: function(grammar_name) { - this.current_grammar_url=grammars_url+grammar_name; + this.current_grammar_url=options.grammars_url+grammar_name; }, get_grammarlist: function(cont_name) { - jsonp(grammars_url+"grammars.cgi",cont_name); + jsonp(options.grammars_url+"grammars.cgi",cont_name); }, get_languages: function(cont_name) { jsonp(this.current_grammar_url,cont_name); @@ -51,6 +54,13 @@ var server = { +"&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) } }; @@ -59,7 +69,6 @@ var server = { 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"), @@ -67,31 +76,36 @@ function start_minibar(opts) { // typically called when the HTML document is loa surface, div_id("words"), div_id("translations")]); - server.get_grammarlist("show_grammarlist"); + 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 menu=empty("select"); - for(var i=0;i1) { + var menu=empty("select"); + for(var i=0;i 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)"); diff --git a/src/runtime/javascript/minibar/phrasebook.html b/src/runtime/javascript/minibar/phrasebook.html new file mode 100644 index 000000000..a331dc112 --- /dev/null +++ b/src/runtime/javascript/minibar/phrasebook.html @@ -0,0 +1,37 @@ + + +Phrasebook + + + + + + + + +
    +
    +
    + + + +Based on +minibar, +powered by +GF, +see +doc. + + + + + + + + diff --git a/src/runtime/javascript/minibar/support.js b/src/runtime/javascript/minibar/support.js index 2161ff650..e2240624c 100644 --- a/src/runtime/javascript/minibar/support.js +++ b/src/runtime/javascript/minibar/support.js @@ -117,7 +117,10 @@ function swap(a,i,j) { // Note: this doesn't work on strings. return a; } -function sort(a) { // Note: this doesn't work on strings. +function sort(a) { +// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/sort + return a.sort; + /* // Note: this doesn't work on strings. for(var i=0;i