Fixed parsing.

This commit is contained in:
Michael Jumper
2012-01-19 11:19:02 -08:00
parent a8de72ac42
commit 4482fc4530

View File

@@ -51,11 +51,17 @@ Guacamole.OnScreenKeyboard = function(url) {
// For each child of element, call handler defined in next
function parseChildren(element, next) {
var children = root.childNodes;
var children = element.childNodes;
for (var i=0; i<children.length; i++) {
// Get child node and corresponding handler
// Get child node
var child = children[i];
// Do not parse text nodes
if (!child.tagName)
continue;
// Get handler for node
var handler = next[child.tagName];
// Call handler if defined
@@ -64,7 +70,7 @@ Guacamole.OnScreenKeyboard = function(url) {
// Throw exception if no handler
else
throw new Exception(
throw new Error(
"Unexpected " + child.tagName
+ " within " + element.tagName
);
@@ -111,6 +117,8 @@ Guacamole.OnScreenKeyboard = function(url) {
gap.style.width = gap.style.height =
parseFloat(gap_size.value) + "em";
row.appendChild(gap);
},
"key": function parse_key(e) {
@@ -118,6 +126,11 @@ Guacamole.OnScreenKeyboard = function(url) {
// Get attributes
var key_size = e.attributes["size"];
// Create element
var key = document.createElement("div");
key.className = "key";
key.textContent = "K";
parseChildren(e, {
"cap": function cap(e) {
@@ -127,10 +140,19 @@ Guacamole.OnScreenKeyboard = function(url) {
var keysym = e.attributes["keysym"];
var sticky = e.attributes["sticky"];
// Get content of key cap
var content = e.textContent;
// If no requirements, then show cap by default
if (!required) {
key.textContent = content;
}
}
});
row.appendChild(key);
}
});
@@ -162,26 +184,22 @@ Guacamole.OnScreenKeyboard = function(url) {
// Parse document
parseChildren(xml.documentElement, {
var keyboard_element = xml.documentElement;
if (keyboard_element.tagName != "keyboard")
throw new Error("Root element must be keyboard");
"keyboard": function parse_keyboard(e) {
// Get attributes
var keyboard_size = keyboard_element.attributes["size"];
// Get attributes
var keyboard_size = e.attributes["size"];
parseChildren(keyboard_element, {
parseChildren(e, {
"row": function(e) {
keyboard.appendChild(parse_row(e));
},
"row": function(e) {
keyboard.appendChild(parse_row(e));
},
"column": function(e) {
keyboard.appendChild(parse_column(e));
}
});
} // end keyboard
"column": function(e) {
keyboard.appendChild(parse_column(e));
}
});