1
0
forked from GitHub/gf-core

minibar+syntax editor integration, work in progress 2

+ Transfer current astract syntax tree when activating the syntax editor
  from the minibar.
+ Add options to start the minibar with given input. You need to include
  the current grammar url, the current language and the input, like this:

    initial_grammar: "/grammars/Foods.pgf",
    initial: { from: "FoodsEng", input:["that","fish","is","fresh"]}

+ Fix a style sheet clash.
This commit is contained in:
hallgren
2012-11-21 17:13:21 +00:00
parent 381dc3900c
commit e7b14316dd
3 changed files with 31 additions and 22 deletions

View File

@@ -2,11 +2,12 @@
/* --- Input object --------------------------------------------------------- */
function Input(server,translations,opts) { // Input object constructor
this.server=server;
this.translations=translations;
var t=this
t.server=server;
t.translations=translations;
// Default values for options:
this.options={
t.options={
delete_button_text: "⌫",
default_source_language: null,
startcat_menu: true,
@@ -15,34 +16,42 @@ function Input(server,translations,opts) { // Input object constructor
}
// Apply supplied options
if(opts) for(var o in opts) this.options[o]=opts[o];
if(opts) for(var o in opts) t.options[o]=opts[o];
// User interface elements
this.main=empty("div");
this.menus=empty("span");
this.buttons=empty("span");
this.surface=div_id("surface");
this.words=div_id("words");
this.from_menu=empty("select");
this.startcat_menu=empty("select")
t.main=empty("div");
t.menus=empty("span");
t.buttons=empty("span");
t.surface=div_id("surface");
t.words=div_id("words");
t.from_menu=empty("select");
t.startcat_menu=empty("select")
with(this) {
with(t) {
appendChildren(main,[surface,words]);
if(options.startcat_menu)
appendChildren(menus,[text(" Startcat: "),startcat_menu])
appendChildren(menus,[text(" From: "),from_menu])
appendChildren(buttons,
[button(options.delete_button_text,bind(delete_last,this),"H"),
button("Clear",bind(clear_all,this),"L")]);
[button(options.delete_button_text,bind(delete_last,t),"H"),
button("Clear",bind(clear_all,t),"L")]);
if(options.random_button)
buttons.appendChild(button("Random",bind(generate_random,this),"R"));
buttons.appendChild(button("Random",bind(generate_random,t),"R"));
with(options) {
if(initial_grammar && initial && initial.from && initial.input) {
t.local=mi_local(initial_grammar)
t.local.put("from",initial.from)
t.local.put("current",initial)
}
}
}
/* --- Input client state initialization --- */
this.current={from: null, input: [] };
t.current={from: null, input: [] };
this.from_menu.onchange=bind(this.change_language,this);
this.startcat_menu.onchange=bind(this.change_startcat,this);
t.from_menu.onchange=bind(t.change_language,t);
t.startcat_menu.onchange=bind(t.change_startcat,t);
}
Input.prototype.change_grammar=function (grammar) {

View File

@@ -19,20 +19,20 @@ var minibar_options= {
try_google: true
}
/*
if(window.Editor) // Syntax editor loaded?
minibar_options.abstract_action=function(tree) {
var editor_options = {
target: "editor",
initial: { grammar: minibar.grammar_menu.value, // hmm
startcat: minibar.input.startcat_menu.value, // hmm
ast: tree
abstr: tree
}
}
minibar.minibar.style.display="none"
minibar.editor=new Editor(server,editor_options)
}
*/
if(/^\?\/tmp\//.test(location.search)) {
var args=decodeURIComponent(location.search.substr(1)).split(" ")
if(args[0]) online_options.grammars_url=args[0];

View File

@@ -7,7 +7,7 @@ body.syntax_editor {
display:none;
}
select#to_menu
#editor select#to_menu
{
height: 10em;
position: absolute;