mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-05 17:22:51 -06:00
minibar_offline: Update the API exported by pgf_offline.js to be compatible with pgf_online.js
This makes the minibar offline demo work again.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
<!DOCTYPE html>
|
||||||
<HTML>
|
<HTML>
|
||||||
<HEAD>
|
<HEAD>
|
||||||
<TITLE>Grammatical Framework Demos</TITLE>
|
<TITLE>Grammatical Framework Demos</TITLE>
|
||||||
@@ -23,7 +23,7 @@ Phrasebook</a>
|
|||||||
|
|
||||||
<P><a href="minibar/minibar.html">Minibar
|
<P><a href="minibar/minibar.html">Minibar
|
||||||
online</A>
|
online</A>
|
||||||
| <small><a href="http://www.grammaticalframework.org/~hallgren/hs2js/test/">Minibar offline</a></small>
|
| <small><a href="minibar/minibar_offline.html">Minibar offline</a></small>
|
||||||
|
|
||||||
<P>
|
<P>
|
||||||
<a href="http://www.grammaticalframework.org:41296/fridge">Fridge poetry</A>
|
<a href="http://www.grammaticalframework.org:41296/fridge">Fridge poetry</A>
|
||||||
|
|||||||
67
src/www/minibar/minibar_offline.html
Normal file
67
src/www/minibar/minibar_offline.html
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html manifest="minibar_offline.manifest">
|
||||||
|
<head>
|
||||||
|
<title>Minibar Offline</title>
|
||||||
|
<link rel=stylesheet type="text/css" href="http://www.grammaticalframework.org/src/www/minibar/minibar.css">
|
||||||
|
|
||||||
|
<meta name = "viewport" content = "width = device-width">
|
||||||
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class=minibar>
|
||||||
|
<h2>Minibar Offline, technology preview</h2>
|
||||||
|
<div id=beskrivning_intro>
|
||||||
|
<p>
|
||||||
|
<a href="javascript:dolj('intro')">[Hide introduction]</a>
|
||||||
|
<br>
|
||||||
|
<strong>These examples work flawlessly in the <a href="http://www.opera.com/browser/">Opera</a> web browser.</strong>
|
||||||
|
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
|
||||||
|
<a href="http://tests.novemberborn.net/javascript/callstack-size.html">call stack size limit</a> still causes some problems.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
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
|
||||||
|
<a href="http://diveintohtml5.info/offline.html">directed to keep a
|
||||||
|
local copy of everything</a>, so that you can have access to the minibar
|
||||||
|
even when you are offline.
|
||||||
|
</div>
|
||||||
|
<p id=beskriv_intro style="display: none"><a href="javascript:beskriv('intro')">[Show introduction]</a>
|
||||||
|
|
||||||
|
<div id=minibar>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<small>
|
||||||
|
[<a href="http://www.altocumulus.org/~hallgren/hs2js/tests/">About hs2js</a>
|
||||||
|
| <a href="http://www.grammaticalframework.org:41296/minibar/minibar.html">Minibar online</a>]
|
||||||
|
</small>
|
||||||
|
<small class=modtime>
|
||||||
|
HTML <!-- hhmts start --> Last modified: Mon Apr 30 15:44:47 CEST 2012 <!-- hhmts end -->
|
||||||
|
</small>
|
||||||
|
<address><a href="http://www.cse.chalmers.se/~hallgren/">TH</a></address>
|
||||||
|
|
||||||
|
<pre id=nodebug>
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="http://www.grammaticalframework.org/~hallgren/hs2js/test/debug.js"></script>
|
||||||
|
<script type="text/javascript" src="http://www.grammaticalframework.org/~hallgren/hs2js/test/json.js"></script>
|
||||||
|
<script type="text/javascript" src="http://www.grammaticalframework.org/~hallgren/hs2js/test/builtin.js"></script>
|
||||||
|
<script type="text/JavaScript" src="http://www.grammaticalframework.org/~hallgren/hs2js/test/Services.js"></script>
|
||||||
|
<script type="text/javascript" src="http://www.grammaticalframework.org/~hallgren/hs2js/test/visadolj.js"></script>
|
||||||
|
|
||||||
|
<script type="text/JavaScript" src="support.js"></script>
|
||||||
|
<script type="text/JavaScript" src="minibar.js"></script>
|
||||||
|
<script type="text/JavaScript" src="minibar_input.js"></script>
|
||||||
|
<script type="text/JavaScript" src="minibar_translations.js"></script>
|
||||||
|
<script type="text/JavaScript" src="minibar_support.js"></script>
|
||||||
|
<script type="text/JavaScript" src="pgf_offline.js"></script>
|
||||||
|
<script type="text/javascript" src="minibar_offline.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
18
src/www/minibar/minibar_offline.js
Normal file
18
src/www/minibar/minibar_offline.js
Normal file
@@ -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);
|
||||||
4
src/www/minibar/minibar_offline.manifest
Normal file
4
src/www/minibar/minibar_offline.manifest
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
CACHE MANIFEST
|
||||||
|
# 12
|
||||||
|
NETWORK:
|
||||||
|
*
|
||||||
@@ -4,15 +4,22 @@ function pgf_offline(options) {
|
|||||||
var server = {
|
var server = {
|
||||||
// State variables (private):
|
// State variables (private):
|
||||||
grammars_url: "",
|
grammars_url: "",
|
||||||
|
other_grammars_urls: [],
|
||||||
grammar_list: ["Foods.pgf"],
|
grammar_list: ["Foods.pgf"],
|
||||||
|
|
||||||
current_grammar_url: null,
|
current_grammar_url: null,
|
||||||
pgf : null,
|
pgf : null,
|
||||||
|
|
||||||
// Methods:
|
// Methods:
|
||||||
switch_grammar: function(grammar_url,cont) {
|
switch_grammar: function(grammar_url,cont) {
|
||||||
//debug("switch_grammar ");
|
|
||||||
var new_grammar_url=this.grammars_url+grammar_url;
|
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 self=this;
|
||||||
var update_pgf=function(pgfbinary) {
|
var update_pgf=function(pgfbinary) {
|
||||||
debug("Got "+new_grammar_url+", length="
|
debug("Got "+new_grammar_url+", length="
|
||||||
@@ -20,11 +27,25 @@ function pgf_offline(options) {
|
|||||||
self.pgf = {v: Services_decodePGF.v({v:pgfbinary}) }
|
self.pgf = {v: Services_decodePGF.v({v:pgfbinary}) }
|
||||||
//debug("done")
|
//debug("done")
|
||||||
self.current_grammar_url=new_grammar_url;
|
self.current_grammar_url=new_grammar_url;
|
||||||
cont();
|
if(cont) cont();
|
||||||
}
|
}
|
||||||
ajax_http_get_binary(new_grammar_url,update_pgf);
|
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) {
|
get_languages: function(cont) {
|
||||||
cont(fromJSValue(Services_grammar.v(this.pgf)))
|
cont(fromJSValue(Services_grammar.v(this.pgf)))
|
||||||
|
|||||||
Reference in New Issue
Block a user