diff --git a/demos/index.html b/demos/index.html index 86449bd6f..02d2168e9 100644 --- a/demos/index.html +++ b/demos/index.html @@ -1,4 +1,4 @@ - +
Minibar online - | Minibar offline + | Minibar offline
Fridge poetry diff --git a/src/www/minibar/minibar_offline.html b/src/www/minibar/minibar_offline.html new file mode 100644 index 000000000..d4d7f3919 --- /dev/null +++ b/src/www/minibar/minibar_offline.html @@ -0,0 +1,67 @@ + + +
+
+[Hide introduction]
+
+These examples work flawlessly in the Opera web browser.
+They also work to some extent in Opera Mobile 11 and WebKit browsers
+(Safari and Chrome) and recent versions of Gecko browers (Firefox).
+A hardcoded
+call stack size limit still causes some problems.
+
+
+How it works: a JavaScript translation of the Haskell PGF run-time library +is downloaded and run in the browser. The binary PGF files are downloaded +from the server, parsed and used in the normal way by functions in the PGF +library. The brower is +directed to keep a +local copy of everything, so that you can have access to the minibar +even when you are offline. +
++ + + + + + + + + + + + + + + + diff --git a/src/www/minibar/minibar_offline.js b/src/www/minibar/minibar_offline.js new file mode 100644 index 000000000..6069f1430 --- /dev/null +++ b/src/www/minibar/minibar_offline.js @@ -0,0 +1,18 @@ + +var offline_options = { + grammars_url: "/~hallgren/hs2js/test/", + grammar_list: ["Foods.pgf","Smart.pgf","Phrasebook.pgf"] +} + +var server=pgf_offline(offline_options); + +var minibar_options= { + show_abstract: true, + show_trees: false, + show_grouped_translations: false, + default_source_language: "Eng", + try_google: true, + random_button: false +} + +var minibar1=new Minibar(server,minibar_options); diff --git a/src/www/minibar/minibar_offline.manifest b/src/www/minibar/minibar_offline.manifest new file mode 100644 index 000000000..b0e46cd62 --- /dev/null +++ b/src/www/minibar/minibar_offline.manifest @@ -0,0 +1,4 @@ +CACHE MANIFEST +# 12 +NETWORK: +* diff --git a/src/www/minibar/pgf_offline.js b/src/www/minibar/pgf_offline.js index cd2d40b1c..e5a3933a5 100644 --- a/src/www/minibar/pgf_offline.js +++ b/src/www/minibar/pgf_offline.js @@ -4,15 +4,22 @@ function pgf_offline(options) { var server = { // State variables (private): grammars_url: "", + other_grammars_urls: [], grammar_list: ["Foods.pgf"], - current_grammar_url: null, pgf : null, // Methods: switch_grammar: function(grammar_url,cont) { - //debug("switch_grammar "); var new_grammar_url=this.grammars_url+grammar_url; + this.switch_to_other_grammar(new_grammar_url,cont) + }, + add_grammars_url: function(grammars_url,cont) { + this.other_grammars_urls.push(grammars_url); + if(cont) cont(); + }, + switch_to_other_grammar: function(new_grammar_url,cont) { + //debug("switch_grammar "); var self=this; var update_pgf=function(pgfbinary) { debug("Got "+new_grammar_url+", length=" @@ -20,11 +27,25 @@ function pgf_offline(options) { self.pgf = {v: Services_decodePGF.v({v:pgfbinary}) } //debug("done") self.current_grammar_url=new_grammar_url; - cont(); + if(cont) cont(); } ajax_http_get_binary(new_grammar_url,update_pgf); }, - get_grammarlist: function(cont) { cont([this.grammar_list]); }, + get_grammarlist: function(cont,err) { + if(this.grammar_list) cont(this.grammar_list) + else http_get_json(this.grammars_url+"grammars.cgi",cont,err); + }, + get_grammarlists: function(cont,err) { // May call cont several times! + var ds=this.other_grammars_urls; + var n=1+ds.length; + function pair(dir) { + return function(grammar_list){cont(dir,grammar_list,n)} + } + function ignore_error(err) { console.log(err) } + this.get_grammarlist(pair(this.grammars_url),err) + for(var i in ds) + http_get_json(ds[i]+"grammars.cgi",pair(ds[i]),ignore_error); + }, get_languages: function(cont) { cont(fromJSValue(Services_grammar.v(this.pgf)))