Fix OSK to work in IE9+

This commit is contained in:
Michael Jumper
2012-03-01 16:00:07 -08:00
parent e866dbcd1d
commit 108ca03420

View File

@@ -198,17 +198,14 @@ Guacamole.OnScreenKeyboard = function(url) {
"gap": function parse_gap(e) { "gap": function parse_gap(e) {
// Get attributes
var gap_size = e.attributes["size"];
// Create element // Create element
var gap = document.createElement("div"); var gap = document.createElement("div");
gap.className = "guac-keyboard-gap"; gap.className = "guac-keyboard-gap";
// Set gap size // Set gap size
var gap_units = 1; var gap_units = 1;
if (gap_size) if (e.getAttribute("size"))
gap_units = parseFloat(gap_size.value); gap_units = parseFloat(e.getAttribute("size"));
scaledElements.push(new ScaledElement(gap, gap_units, gap_units)); scaledElements.push(new ScaledElement(gap, gap_units, gap_units));
row.appendChild(gap); row.appendChild(gap);
@@ -217,17 +214,13 @@ Guacamole.OnScreenKeyboard = function(url) {
"key": function parse_key(e) { "key": function parse_key(e) {
// Get attributes
var key_size = e.attributes["size"];
var key_class = e.attributes["class"];
// Create element // Create element
var key_element = document.createElement("div"); var key_element = document.createElement("div");
key_element.className = "guac-keyboard-key"; key_element.className = "guac-keyboard-key";
// Append class if specified // Append class if specified
if (key_class) if (e.getAttribute("class"))
key_element.className += " " + key_class.value; key_element.className += " " + e.getAttribute("class");
// Position keys using container div // Position keys using container div
var key_container_element = document.createElement("div"); var key_container_element = document.createElement("div");
@@ -239,28 +232,23 @@ Guacamole.OnScreenKeyboard = function(url) {
// Set key size // Set key size
var key_units = 1; var key_units = 1;
if (key_size) if (e.getAttribute("size"))
key_units = parseFloat(key_size.value); key_units = parseFloat(e.getAttribute("size"));
key.size = key_units; key.size = key_units;
parseChildren(e, { parseChildren(e, {
"cap": function parse_cap(e) { "cap": function parse_cap(e) {
// Get attributes // TODO: Handle "sticky" attribute
var required = e.attributes["if"];
var modifier = e.attributes["modifier"];
var keysym = e.attributes["keysym"];
var sticky = e.attributes["sticky"];
var cap_class = e.attributes["class"];
// Get content of key cap // Get content of key cap
var content = e.textContent; var content = e.textContent || e.text;
// Get keysym // Get keysym
var real_keysym = null; var real_keysym = null;
if (keysym) if (e.getAttribute("keysym"))
real_keysym = parseInt(keysym.value); real_keysym = parseInt(e.getAttribute("keysym"));
// If no keysym specified, try to get from key content // If no keysym specified, try to get from key content
else if (content.length == 1) { else if (content.length == 1) {
@@ -276,8 +264,8 @@ Guacamole.OnScreenKeyboard = function(url) {
// Create cap // Create cap
var cap = new Guacamole.OnScreenKeyboard.Cap(content, real_keysym); var cap = new Guacamole.OnScreenKeyboard.Cap(content, real_keysym);
if (modifier) if (e.getAttribute("modifier"))
cap.modifier = modifier.value; cap.modifier = e.getAttribute("modifier");
// Create cap element // Create cap element
var cap_element = document.createElement("div"); var cap_element = document.createElement("div");
@@ -286,16 +274,16 @@ Guacamole.OnScreenKeyboard = function(url) {
key_element.appendChild(cap_element); key_element.appendChild(cap_element);
// Append class if specified // Append class if specified
if (cap_class) if (e.getAttribute("class"))
cap_element.className += " " + cap_class.value; cap_element.className += " " + e.getAttribute("class");
// Get modifier value // Get modifier value
var modifierValue = 0; var modifierValue = 0;
if (required) { if (e.getAttribute("if")) {
// Get modifier value for specified comma-delimited // Get modifier value for specified comma-delimited
// list of required modifiers. // list of required modifiers.
var requirements = required.value.split(","); var requirements = e.getAttribute("if").split(",");
for (var i=0; i<requirements.length; i++) { for (var i=0; i<requirements.length; i++) {
modifierValue |= getModifier(requirements[i]); modifierValue |= getModifier(requirements[i]);
addClass(cap_element, "guac-keyboard-requires-" + requirements[i]); addClass(cap_element, "guac-keyboard-requires-" + requirements[i]);
@@ -401,10 +389,8 @@ Guacamole.OnScreenKeyboard = function(url) {
var col = document.createElement("div"); var col = document.createElement("div");
col.className = "guac-keyboard-column"; col.className = "guac-keyboard-column";
var align = col.attributes["align"]; if (col.getAttribute("align"))
col.style.textAlign = col.getAttribute("align");
if (align)
col.style.textAlign = align.value;
// Columns can only contain rows // Columns can only contain rows
parseChildren(e, { parseChildren(e, {
@@ -424,10 +410,10 @@ Guacamole.OnScreenKeyboard = function(url) {
throw new Error("Root element must be keyboard"); throw new Error("Root element must be keyboard");
// Get attributes // Get attributes
if (!keyboard_element.attributes["size"]) if (!keyboard_element.getAttribute("size"))
throw new Error("size attribute is required for keyboard"); throw new Error("size attribute is required for keyboard");
var keyboard_size = parseFloat(keyboard_element.attributes["size"].value); var keyboard_size = parseFloat(keyboard_element.getAttribute("size"));
parseChildren(keyboard_element, { parseChildren(keyboard_element, {