summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjohn.j.camilleri <john.j.camilleri@chalmers.se>2012-11-22 12:45:20 +0000
committerjohn.j.camilleri <john.j.camilleri@chalmers.se>2012-11-22 12:45:20 +0000
commitbac6b7fe6438d06fab3451263d4d94e9055f6f88 (patch)
treeabcb68ac3df3fa2e17fd3ba38cc9f5f899c9b913 /src
parent486a510611b72d4daf551f30156fa59608d099af (diff)
Syntax editor: can now load minibar (in-place) from a linearised tree
Diffstat (limited to 'src')
-rw-r--r--src/www/js/support.js9
-rw-r--r--src/www/syntax-editor/editor.css2
-rw-r--r--src/www/syntax-editor/editor.html29
-rw-r--r--src/www/syntax-editor/editor.js71
-rw-r--r--src/www/syntax-editor/editor_online.js41
5 files changed, 100 insertions, 52 deletions
diff --git a/src/www/js/support.js b/src/www/js/support.js
index 9687ea8a1..41b736855 100644
--- a/src/www/js/support.js
+++ b/src/www/js/support.js
@@ -20,6 +20,15 @@ if(!Array.isArray) {
};
}
+// Create a clone of an array
+// http://davidwalsh.name/javascript-clone-array
+// Note that iterating over an array with for...in will include "clone" as a key!
+// if(!Array.clone) {
+// Array.prototype.clone = function() {
+// return this.slice(0);
+// };
+// }
+
/* --- JSONP ---------------------------------------------------------------- */
// Inspired by the function jsonp from
diff --git a/src/www/syntax-editor/editor.css b/src/www/syntax-editor/editor.css
index 29f45a7e7..2b5d5a6d1 100644
--- a/src/www/syntax-editor/editor.css
+++ b/src/www/syntax-editor/editor.css
@@ -7,7 +7,7 @@ body.syntax_editor {
display:none;
}
-#editor select#to_menu
+.editor select#to_menu
{
height: 10em;
position: absolute;
diff --git a/src/www/syntax-editor/editor.html b/src/www/syntax-editor/editor.html
index 36045957c..1d4cc401c 100644
--- a/src/www/syntax-editor/editor.html
+++ b/src/www/syntax-editor/editor.html
@@ -9,7 +9,7 @@
</head>
<body class=syntax_editor>
<h2>Syntax Editor</h2>
- <div id="editor"></div>
+ <div id="editor" class="test"></div>
<noscript>This page doesn't works unless JavaScript is enabled.</noscript>
<hr />
@@ -17,26 +17,23 @@
John J. Camilleri, November 2012
</small>
+ <!-- Common -->
<script type="text/javascript" src="../js/support.js"></script>
<script type="text/javascript" src="../js/pgf_online.js"></script>
+
+ <!-- Editor -->
<script type="text/javascript" src="ast.js"></script>
<script type="text/javascript" src="editor_menu.js"></script>
<script type="text/javascript" src="editor.js"></script>
- <script type="text/javascript">
- var server_options = {
- // grammars_url: "http://www.grammaticalframework.org/grammars/",
- grammars_url: "http://localhost:41296/grammars/",
- }
- var editor_options = {
- target: "editor"
- }
- if(/^\?\/tmp\//.test(location.search)) {
- var args=decodeURIComponent(location.search.substr(1)).split(" ")
- if(args[0]) server_options.grammars_url=args[0];
- }
- var server = pgf_online(server_options);
- var editor = new Editor(server, editor_options);
- </script>
+
+ <!-- Minibar -->
+ <script type="text/JavaScript" src="../minibar/minibar.js"></script>
+ <script type="text/JavaScript" src="../minibar/minibar_input.js"></script>
+ <script type="text/JavaScript" src="../minibar/minibar_translations.js"></script>
+ <script type="text/JavaScript" src="../minibar/minibar_support.js"></script>
+
+ <!-- Get us rolling! -->
+ <script type="text/javascript" src="editor_online.js"></script>
</body>
</html>
diff --git a/src/www/syntax-editor/editor.js b/src/www/syntax-editor/editor.js
index df2a49da8..70dbab8e9 100644
--- a/src/www/syntax-editor/editor.js
+++ b/src/www/syntax-editor/editor.js
@@ -1,11 +1,3 @@
-
-/* --- Some enhancements --------------------------------------------------- */
-
-// http://www.xenoveritas.org/blog/xeno/the-correct-way-to-clone-javascript-arrays
-// Array.prototype.clone = function(){
-// return this.slice(0);
-// }
-
/* --- Main Editor object --------------------------------------------------- */
/* When creating the object, stuff gets called in this order:
new EditorMenu
@@ -49,16 +41,20 @@ function Editor(server,opts) {
if(opts) for(var o in opts) this.options[o]=opts[o];
/* --- Creating UI components ------------------------------------------- */
- var main = document.getElementById(this.options.target);
+ this.container = document.getElementById(this.options.target);
+ this.container.classList.add("editor");
this.ui = {
menubar: div_class("menu"),
tree: div_id("tree"),
refinements: div_id("refinements"),
lin: div_id("linearisations")
};
- with(this.ui) {
- appendChildren(main, [menubar, tree, refinements, lin]);
- }
+ appendChildren(this.container, [
+ this.ui.menubar,
+ this.ui.tree,
+ this.ui.refinements,
+ this.ui.lin
+ ]);
/* --- Client state initialisation -------------------------------------- */
this.server = server;
@@ -70,8 +66,11 @@ function Editor(server,opts) {
/* --- Main program, this gets things going ----------------------------- */
this.menu = new EditorMenu(this, this.options);
- /* --- Apply supplied initial settings (if any) ------------------------- */
-// if (this.options.initial.grammar)
+ /* --- Shutdown the editor nicely --------------------------------------- */
+ this.shutdown = function() {
+ clear(this.container);
+ this.container.classList.remove("editor");
+ }
}
@@ -237,32 +236,34 @@ Editor.prototype.redraw_tree=function() {
}
Editor.prototype.update_linearisation=function(){
-
+ var t = this;
function langpart(conc,abs) { // langpart("FoodsEng","Foods") == "Eng"
return hasPrefix(conc,abs) ? conc.substr(abs.length) : conc;
}
-
- var t = this;
- with (this) {
- var args = {
- tree: ast.toString()
- };
- server.linearize(args, function(data){
- clear(t.ui.lin);
- for (i in data) {
- var lang = data[i].to;
- var langname = langpart(lang, t.grammar.name);
- if (t.languages.length < 1 || elem(lang, t.languages)) {
- var div_lang = empty("div");
- div_lang.appendChild(span_class("lang", text(langname)));
- div_lang.appendChild(
- span_class("lin", [text(data[i].text)])
- );
- t.ui.lin.appendChild(div_lang);
- }
- }
+ function row(lang, lin) {
+ var langname = langpart(lang, t.grammar.name);
+ var btn = button(langname, function(){
+ t.options.lin_action(lin,lang);
});
+ var c1 = th(btn);
+ var c2 = td(text(lin));
+ var row = tr([c1,c2]);
+ return row;
}
+ var args = {
+ tree: t.ast.toString()
+ };
+ t.server.linearize(args, function(data){
+ clear(t.ui.lin);
+ var tbody=empty("tbody");
+ for (i in data) {
+ var lang = data[i].to;
+ if (t.languages.length < 1 || elem(lang, t.languages)) {
+ tbody.appendChild(row(lang, data[i].text))
+ }
+ }
+ t.ui.lin.appendChild(wrap("table",tbody));
+ });
}
//
diff --git a/src/www/syntax-editor/editor_online.js b/src/www/syntax-editor/editor_online.js
new file mode 100644
index 000000000..8b7c48acd
--- /dev/null
+++ b/src/www/syntax-editor/editor_online.js
@@ -0,0 +1,41 @@
+var server_options = {
+ // grammars_url: "http://www.grammaticalframework.org/grammars/",
+ // grammars_url: "http://localhost:41296/grammars/",
+}
+var editor_options = {
+ target: "editor",
+ // initial: {
+ // grammar: "http://localhost:41296/grammars/Phrasebook.pgf",
+ // startcat: "Proposition",
+ // languages: ["Eng","Swe","Ita"],
+ // abstr: "PropOpenDate (SuperlPlace TheMostExpensive School) Tomorrow",
+ // node_id: null
+ // },
+ show: {
+ grammar_menu: true,
+ startcat_menu: true,
+ to_menu: true,
+ random_button: true
+ }
+}
+if(window.Minibar) // Minibar loaded?
+ editor_options.lin_action=function(s,langFrom) {
+ editor.shutdown();
+ var minibar_options = {
+ target: "editor",
+ initial_grammar: editor.menu.ui.grammar_menu.value, // hmm
+ initial: {
+ from: langFrom,
+ input: s.split(" ") // is it that easy?
+ }
+ }
+ editor.minibar=new Minibar(server,minibar_options);
+ }
+if(/^\?\/tmp\//.test(location.search)) {
+ var args=decodeURIComponent(location.search.substr(1)).split(" ")
+ if(args[0]) server_options.grammars_url=args[0];
+}
+var server = pgf_online(server_options);
+var editor = new Editor(server, editor_options);
+
+