From 1a25f0430340af0659b03f50f291921723d73bee Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 3 Aug 2011 14:24:47 +0000 Subject: [PATCH] minibar: small code and documentation tweaks --- src/runtime/javascript/minibar/about.html | 21 +++++++++------- .../minibar/gf-web-api-examples.html | 20 ++++++++++----- src/runtime/javascript/minibar/minibar.css | 2 +- src/runtime/javascript/minibar/minibar.html | 23 +++++++---------- .../javascript/minibar/minibar_online.js | 25 +++++++++++++++++++ src/runtime/javascript/minibar/pgf_online.js | 16 ++++++------ 6 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 src/runtime/javascript/minibar/minibar_online.js diff --git a/src/runtime/javascript/minibar/about.html b/src/runtime/javascript/minibar/about.html index 67ce7b961..9ab31e987 100644 --- a/src/runtime/javascript/minibar/about.html +++ b/src/runtime/javascript/minibar/about.html @@ -1,8 +1,7 @@ - + About Minibar - @@ -33,7 +32,9 @@ Some implementation details: There seems to be some rendering bugs in Chrome 5.0.342.9 β.
  • The implementation consist of two JavaScript files: minibar.js and support.js - The latter is also used in a small web app based on the + The latter is also used in + a couple of + small web apps based on the SALDO web services.
  • To access the GF web service, it uses the JSONP method @@ -94,17 +95,17 @@ Some implementation details: or if what you have entered exactly matches one of the remaining magnet.
  • [Added 2010-05-28] Added a link to make it easy to try the same sentence in - Google Translate. - This can be turned of by passing the option {try_google:false} to + Google Translate.This can be + turned off by passing the option {try_google:false} to start_minibar.
  • [Added 2010-06-02] Added support for Help and Feedback buttons, controlled by the options feedback_url and help_url passed to start_minibar.
  • [Added 2010-06-02] New option: default_source_language.
  • [Added 2010-09-10] Minibar now automatically uses - AJAX + XHR instead of JSONP when possible (i.e. when the HTML document and the - PGF server are on the same server). + PGF service are on the same server).
  • [Added 2010-09-10] The default input language is now the user's preferred language, if possible. This is implemented by consulting the userLanguage field in the grammar info output by pgf-server. @@ -131,7 +132,7 @@ Some implementation details: pgf_online.js.
  • The minibar code has been rewritten to avoid storing state information in the document tree and accessing it by referring to named document - elements. The code now also avoids using string literals contaning + elements. The code now also avoids using string literals containing the names of top-level functions to specify event handlers for buttons and menus. (The code is no longer introspective, so α conversion will not change its meaning.) @@ -150,11 +151,13 @@ Some implementation details: after every word. On touch-based devices, the on-screen keyboard kept popping up after every word, which was very annoying if you were entering a sentence by tapping on the magnets. +
  • [Changed 2011-08-03] Moved the initialization code in minibar.html to + minibar_online.js.
    - Last modified: Mon Apr 11 15:03:31 CEST 2011 + Last modified: Wed Aug 3 16:14:22 CEST 2011
    TH diff --git a/src/runtime/javascript/minibar/gf-web-api-examples.html b/src/runtime/javascript/minibar/gf-web-api-examples.html index cc310ec4f..c4be198b1 100644 --- a/src/runtime/javascript/minibar/gf-web-api-examples.html +++ b/src/runtime/javascript/minibar/gf-web-api-examples.html @@ -1,10 +1,12 @@ - + GF web services API examples - + + @@ -24,7 +29,7 @@ availiable in the GF shell is also available via the GF web services API.

    The GF -Web Service API page describes the calls supported by the GF web service +Web Service API page describes the calls supported by the GF web service API. Below, we illustrate these calls by examples, and also show how to make these calls from JavaScript using the API defined in pgf_online.js. @@ -63,7 +68,8 @@ incomplete and might be made more complete in a future version...

    ["Foods.pgf","Phrasebook.pgf"]
    // Select which grammar to use
    server.switch_grammar("Foods.pgf") -
    // Get grammar info (this method could be renamed) +
    // Get concrete language list and other grammar info + (this method could be renamed)
    server.get_languages(callback)
    http://localhost:41296/grammars/Foods.pgf
    {"name":"Foods", @@ -120,7 +126,9 @@ incomplete and might be made more complete in a future version... "text":""}]
    - Last modified: Mon Apr 11 14:47:59 CEST 2011 +
    + Last modified: Wed Aug 3 15:33:17 CEST 2011 +
    -TH
    \ No newline at end of file diff --git a/src/runtime/javascript/minibar/minibar.css b/src/runtime/javascript/minibar/minibar.css index 0ea982efc..4d2094066 100644 --- a/src/runtime/javascript/minibar/minibar.css +++ b/src/runtime/javascript/minibar/minibar.css @@ -33,7 +33,7 @@ div.word, span.word, div#words div, div#words input[type=button] { .invalid { color: red; } div.modtime { float: right; } -.modtime { color: #444; white-space: nowrap; } +.modtime { color: #666; white-space: nowrap; } ul.space>li { margin-top: 0.75ex; } diff --git a/src/runtime/javascript/minibar/minibar.html b/src/runtime/javascript/minibar/minibar.html index f669482ee..61fc49791 100644 --- a/src/runtime/javascript/minibar/minibar.html +++ b/src/runtime/javascript/minibar/minibar.html @@ -1,24 +1,20 @@ - - + + + Minibar - - - -

    Minibar online

    -
    -
    - +
    + + +
    @@ -27,7 +23,7 @@ This page doesn't works unless JavaScript is enabled. & Translator] -HTML Last modified: Tue Mar 22 16:11:27 CET 2011 +HTML Last modified: Wed Aug 3 15:09:58 CEST 2011
    TH @@ -54,11 +50,10 @@ var minibar_options= { show_trees: true, show_grouped_translations: false, default_source_language: "Eng", - feedback_url: "feedback.html", +//feedback_url: "feedback.html", try_google: true } var minibar=new Minibar(server,minibar_options,"minibar"); - diff --git a/src/runtime/javascript/minibar/minibar_online.js b/src/runtime/javascript/minibar/minibar_online.js new file mode 100644 index 000000000..6d15a306b --- /dev/null +++ b/src/runtime/javascript/minibar/minibar_online.js @@ -0,0 +1,25 @@ +// minibar_demo.js, assumes that minibar.js and pgf_online.js have been loaded. + +var online_options={ + //grammars_url: "http://www.grammaticalframework.org/grammars/", + //grammars_url: "http://tournesol.cs.chalmers.se:41296/grammars/", + //grammars_url: "http://localhost:41296/grammars/", + //grammar_list: ["Foods.pgf"], // leave undefined to get list from server +} + + +if(/^\?\/tmp\//.test(location.search)) { + online_options.grammars_url=location.search.substr(1); +} + +var server=pgf_online(online_options); + +var minibar_options= { + show_abstract: true, + show_trees: true, + show_grouped_translations: false, + default_source_language: "Eng", +//feedback_url: "feedback.html", + try_google: true +} +var minibar=new Minibar(server,minibar_options,"minibar"); diff --git a/src/runtime/javascript/minibar/pgf_online.js b/src/runtime/javascript/minibar/pgf_online.js index c17aafae1..65c9fd5ee 100644 --- a/src/runtime/javascript/minibar/pgf_online.js +++ b/src/runtime/javascript/minibar/pgf_online.js @@ -18,7 +18,9 @@ function pgf_online(options) { }, pgf_call: function(cmd,args,cont) { var url=this.current_grammar_url+"?command="+cmd; - for(var arg in args) url+="&"+arg+"="+encodeURIComponent(args[arg]); + for(var arg in args) + if(args[arg]!=undefined) + url+="&"+arg+"="+encodeURIComponent(args[arg]); http_get_json(url,cont); }, @@ -26,22 +28,22 @@ function pgf_online(options) { this.pgf_call("grammar",{},cont); }, - get_random: function(cont) { + get_random: function(cont) { // cat, limit this.pgf_call("random",{random:Math.random()},cont); }, - linearize: function(tree,to,cont) { + linearize: function(tree,to,cont) { // tree, to this.pgf_call("linearize",{tree:tree,to:to},cont); }, - complete: function(from,input,cont) { + complete: function(from,input,cont) { // from, input, cat, limit this.pgf_call("complete",{from:from,input:input},cont); }, - parse: function(from,input,cont) { + parse: function(from,input,cont) { // from, input cat this.pgf_call("parse",{from:from,input:input},cont); }, - translate: function(from,input,cont) { + translate: function(from,input,cont) { // from, input, cat, to this.pgf_call("translate",{from:from,input:input},cont); }, - translategroup: function(from,input,cont) { + translategroup: function(from,input,cont) { // from, input, cat, to this.pgf_call("translategroup",{from:from,input:input},cont); }