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:
@@ -2,11 +2,12 @@
|
|||||||
/* --- Input object --------------------------------------------------------- */
|
/* --- Input object --------------------------------------------------------- */
|
||||||
|
|
||||||
function Input(server,translations,opts) { // Input object constructor
|
function Input(server,translations,opts) { // Input object constructor
|
||||||
this.server=server;
|
var t=this
|
||||||
this.translations=translations;
|
t.server=server;
|
||||||
|
t.translations=translations;
|
||||||
|
|
||||||
// Default values for options:
|
// Default values for options:
|
||||||
this.options={
|
t.options={
|
||||||
delete_button_text: "⌫",
|
delete_button_text: "⌫",
|
||||||
default_source_language: null,
|
default_source_language: null,
|
||||||
startcat_menu: true,
|
startcat_menu: true,
|
||||||
@@ -15,34 +16,42 @@ function Input(server,translations,opts) { // Input object constructor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply supplied options
|
// 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
|
// User interface elements
|
||||||
this.main=empty("div");
|
t.main=empty("div");
|
||||||
this.menus=empty("span");
|
t.menus=empty("span");
|
||||||
this.buttons=empty("span");
|
t.buttons=empty("span");
|
||||||
this.surface=div_id("surface");
|
t.surface=div_id("surface");
|
||||||
this.words=div_id("words");
|
t.words=div_id("words");
|
||||||
this.from_menu=empty("select");
|
t.from_menu=empty("select");
|
||||||
this.startcat_menu=empty("select")
|
t.startcat_menu=empty("select")
|
||||||
|
|
||||||
with(this) {
|
with(t) {
|
||||||
appendChildren(main,[surface,words]);
|
appendChildren(main,[surface,words]);
|
||||||
if(options.startcat_menu)
|
if(options.startcat_menu)
|
||||||
appendChildren(menus,[text(" Startcat: "),startcat_menu])
|
appendChildren(menus,[text(" Startcat: "),startcat_menu])
|
||||||
appendChildren(menus,[text(" From: "),from_menu])
|
appendChildren(menus,[text(" From: "),from_menu])
|
||||||
appendChildren(buttons,
|
appendChildren(buttons,
|
||||||
[button(options.delete_button_text,bind(delete_last,this),"H"),
|
[button(options.delete_button_text,bind(delete_last,t),"H"),
|
||||||
button("Clear",bind(clear_all,this),"L")]);
|
button("Clear",bind(clear_all,t),"L")]);
|
||||||
if(options.random_button)
|
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 --- */
|
/* --- Input client state initialization --- */
|
||||||
this.current={from: null, input: [] };
|
t.current={from: null, input: [] };
|
||||||
|
|
||||||
this.from_menu.onchange=bind(this.change_language,this);
|
t.from_menu.onchange=bind(t.change_language,t);
|
||||||
this.startcat_menu.onchange=bind(this.change_startcat,this);
|
t.startcat_menu.onchange=bind(t.change_startcat,t);
|
||||||
}
|
}
|
||||||
|
|
||||||
Input.prototype.change_grammar=function (grammar) {
|
Input.prototype.change_grammar=function (grammar) {
|
||||||
|
|||||||
@@ -19,20 +19,20 @@ var minibar_options= {
|
|||||||
try_google: true
|
try_google: true
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if(window.Editor) // Syntax editor loaded?
|
if(window.Editor) // Syntax editor loaded?
|
||||||
minibar_options.abstract_action=function(tree) {
|
minibar_options.abstract_action=function(tree) {
|
||||||
var editor_options = {
|
var editor_options = {
|
||||||
target: "editor",
|
target: "editor",
|
||||||
initial: { grammar: minibar.grammar_menu.value, // hmm
|
initial: { grammar: minibar.grammar_menu.value, // hmm
|
||||||
startcat: minibar.input.startcat_menu.value, // hmm
|
startcat: minibar.input.startcat_menu.value, // hmm
|
||||||
ast: tree
|
abstr: tree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
minibar.minibar.style.display="none"
|
minibar.minibar.style.display="none"
|
||||||
minibar.editor=new Editor(server,editor_options)
|
minibar.editor=new Editor(server,editor_options)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
if(/^\?\/tmp\//.test(location.search)) {
|
if(/^\?\/tmp\//.test(location.search)) {
|
||||||
var args=decodeURIComponent(location.search.substr(1)).split(" ")
|
var args=decodeURIComponent(location.search.substr(1)).split(" ")
|
||||||
if(args[0]) online_options.grammars_url=args[0];
|
if(args[0]) online_options.grammars_url=args[0];
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ body.syntax_editor {
|
|||||||
display:none;
|
display:none;
|
||||||
}
|
}
|
||||||
|
|
||||||
select#to_menu
|
#editor select#to_menu
|
||||||
{
|
{
|
||||||
height: 10em;
|
height: 10em;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
Reference in New Issue
Block a user