diff options
| author | Thomas Hallgren <th-github@altocumulus.org> | 2019-11-21 14:25:07 +0100 |
|---|---|---|
| committer | Thomas Hallgren <th-github@altocumulus.org> | 2019-11-21 14:25:07 +0100 |
| commit | e6b33ac8b8869ad5741685932bbc14f7ae9efad9 (patch) | |
| tree | cad09bd5c31422a1d3e9329bed4e8efc27f02c9b | |
| parent | 14e5528544462d9b3645da7a91120e418cc3a28b (diff) | |
Minibar: make it possible to configure a list of preferred grammars
A preferred grammar is selected when a user visits the Minibar for the
first time. (Like before, Minibar remembers the selected grammar for future
visits.)
A preferred list of grammars can be specified in config.js in the .../minibar
directory on the server, e.g. like this:
preferred_grammars=["/grammars/Foods.pgf","/grammars/ResourceDemo.pgf"]
The first available grammar from the list is used.
| -rw-r--r-- | src/www/minibar/about.html | 12 | ||||
| -rw-r--r-- | src/www/minibar/minibar.js | 8 | ||||
| -rw-r--r-- | src/www/minibar/minibar_online.js | 3 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/www/minibar/about.html b/src/www/minibar/about.html index 87df72e00..4880a20a3 100644 --- a/src/www/minibar/about.html +++ b/src/www/minibar/about.html @@ -243,12 +243,22 @@ Some implementation details: the minibar. The rest of the documentation is displayed when you press the <b>More info</b> button (or the <b>i</b> button). The documentation can contain HTML markup. Blank lines are treated as paragraph breaks. + <li>[Added 2019-11-21] It is now possible to configure a list of preferred + grammars. + A preferred grammar is selected when a user visits Minibar for the + first time. (Like before, Minibar remembers the selected grammar for + future visits.) + <p> + A preferred list of grammars can be specified in <code>config.js</code> + in the <code>…/minibar</code> directory on the server, e.g. like this: + <pre> preferred_grammars=["/grammars/Foods.pgf","/grammars/ResourceDemo.pgf"]</pre> + The first available grammar from the list is used. </ul> </main> <footer> <hr> <div class=modtime><small> -<!-- hhmts start -->Last modified: Mon Aug 5 15:22:46 CEST 2019 <!-- hhmts end --> +<!-- hhmts start -->Last modified: Thu Nov 21 14:23:59 CET 2019 <!-- hhmts end --> </small></div> <address> <a href="http://www.cse.chalmers.se/~hallgren/">Thomas Hallgren</a> diff --git a/src/www/minibar/minibar.js b/src/www/minibar/minibar.js index 944d4d93b..413683095 100644 --- a/src/www/minibar/minibar.js +++ b/src/www/minibar/minibar.js @@ -181,7 +181,15 @@ Minibar.prototype.show_grammarlist=function(dir,grammar_names,dir_count) { if(last_grammar && elem(last_grammar,t.grammars)) grammar0=last_grammar; } + var pgs=t.options.preferred_grammars + if(!grammar0 && pgs) + for(var i in pgs) + if(elem(pgs[i],t.grammars)) { + grammar0=pgs[i] + break + } if(!grammar0) grammar0=t.grammars[0]; + //console.log("grammar0=",grammar0) t.grammar_menu.value=grammar0; t.select_grammar(grammar0); } diff --git a/src/www/minibar/minibar_online.js b/src/www/minibar/minibar_online.js index 0d7792e9d..f691de3d6 100644 --- a/src/www/minibar/minibar_online.js +++ b/src/www/minibar/minibar_online.js @@ -21,6 +21,9 @@ var minibar_options= { try_google: true } +if(window.preferred_grammars) + minibar_options.preferred_grammars=preferred_grammars + if(/^\?\/(tmp|grammars)\//.test(location.search)) { var args=decodeURIComponent(location.search.substr(1)).split(" ") if(args[0]) online_options.grammars_url=args[0]; |
