From 81362ed7b724ee5161b494b29020b9068b2c10c2 Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Mon, 5 Aug 2019 15:25:29 +0200 Subject: [PATCH] Minibar can now display grammar documentation. The documentation is taken from a file called Grammar.pgf_info, located next to the Grammar.pgf file on the server. The first line of the documentation is displayed below the menu bar in the minibar. The rest of the documentation is displayed when you press the "More info" button (or the "i" button). The documentation can contain HTML markup. Blank lines are treated as paragraph breaks. --- src/www/minibar/about.html | 21 ++++++++++++++++----- src/www/minibar/minibar.css | 1 + src/www/minibar/minibar.js | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/www/minibar/about.html b/src/www/minibar/about.html index 7c127fe5f..87df72e00 100644 --- a/src/www/minibar/about.html +++ b/src/www/minibar/about.html @@ -10,8 +10,10 @@ +

About Minibar

- +
+
Minibar is an alternative implementation of the GF web app Fridge Poetry. @@ -233,14 +235,23 @@ Some implementation details: category names.
  • [Added 2013-04-02] Minibar now remembers from one visit to the next the selected set of target languages for each grammar. +
  • [Added 2019-08-05] Minibar can now display grammar documentation. + The documentation is taken from a file called + Grammar.pgf_info, located + next to the Grammar.pgf file on the server. + The first line of the documentation is displayed below the menu bar in + the minibar. The rest of the documentation is displayed when you press + the More info button (or the i button). The documentation + can contain HTML markup. Blank lines are treated as paragraph breaks. - +
  • + diff --git a/src/www/minibar/minibar.css b/src/www/minibar/minibar.css index 2e4d646ea..5d77b4508 100644 --- a/src/www/minibar/minibar.css +++ b/src/www/minibar/minibar.css @@ -10,6 +10,7 @@ h1:first-child, h2:first-child { margin-top: 0; margin-bottom: 1ex; } th, td { vertical-align: baseline; text-align: left; } div.menubar { font-family: sans-serif; font-size: small; } +div.infobar { margin: 5px; } div#surface { min-height: 3ex; diff --git a/src/www/minibar/minibar.js b/src/www/minibar/minibar.js index c299cb77c..6822e7926 100644 --- a/src/www/minibar/minibar.js +++ b/src/www/minibar/minibar.js @@ -53,13 +53,14 @@ function Minibar(server,opts) { /* --- Creating user interface elements --------------------------------- */ this.menubar=div_class("menubar"); + this.infobar=div_class("infobar"); this.extra=div_id("extra"); this.minibar=element(this.options.target); this.minibar.innerHTML=""; with(this) { appendChildren(menubar,[input.menus,translations.menus,input.buttons]) - appendChildren(minibar,[menubar,input.main,translations.main,extra]); + appendChildren(minibar,[menubar,infobar,input.main,translations.main,extra]); if(options.help_url) menubar.appendChild(button("Help",bind(open_help,this))); append_extra_buttons(extra,options); @@ -205,6 +206,30 @@ Minibar.prototype.change_grammar=function(grammar_info) { t.grammar=grammar_info; t.input.change_grammar(grammar_info) t.translations.change_grammar(grammar_info) + t.get_pgf_info() +} + +Minibar.prototype.get_pgf_info=function() { + var t=this; + var info_url=t.server.current_grammar_url+"_info"; + clear(t.infobar) + t.pgf_info=null; + ajax_http_get(info_url,bind(t.show_pgf_info,t),function(){}) +} + +Minibar.prototype.show_pgf_info=function(info) { + var t=this; + var cnt=0; + console.log(info) + info=info.split("\n"); + for(var i=0;i1) + t.infobar.appendChild(button("More info",bind(t.show_grammarinfo,t))) } Minibar.prototype.show_grammarinfo=function() { @@ -241,7 +266,10 @@ Minibar.prototype.show_grammarinfo=function() { var cats=wrap("div",text(g.categories.join(", "))) var funs=wrap("div",text(g.functions.join(", "))) - var btn=button("More info",more) + var btn=button("Show more details",more) + + var info=empty("div") + if(t.pgf_info) info.innerHTML=t.pgf_info clear(t.translations.main) var hdr=[text(g.name)] @@ -249,8 +277,11 @@ Minibar.prototype.show_grammarinfo=function() { hdr.push(text(" ")) hdr.push(wrap("small",text("("+g.lastmodified+")"))) } + appendChildren(this.translations.main, [wrap("h3",hdr), + info, + text("The categories and functions in the grammar are listed below."), btn, wrap("h4",text("Start category")), text(g.startcat || ""), wrap("h4",text("Categories")), cats,