Clean up interface.js a bit.

This commit is contained in:
Michael Jumper
2012-11-09 11:00:00 -08:00
parent 95a61ceb14
commit 1a3801c2f7

View File

@@ -107,43 +107,30 @@ GuacamoleUI.toggleKeyboard = function() {
}; };
// Constant UI initialization and behavior // If Node.classList is supported, implement addClass/removeClass using that
(function() { if (Node.classList) {
// Cache error image (might not be available when error occurs) GuacamoleUI.addClass = function(element, classname) {
var guacErrorImage = new Image();
guacErrorImage.src = "images/noguacamole-logo-24.png";
// Function for adding a class to an element
var addClass;
// Function for removing a class from an element
var removeClass;
// If Node.classList is supported, implement addClass/removeClass using that
if (Node.classList) {
addClass = function(element, classname) {
element.classList.add(classname); element.classList.add(classname);
}; };
removeClass = function(element, classname) { GuacamoleUI.removeClass = function(element, classname) {
element.classList.remove(classname); element.classList.remove(classname);
}; };
} }
// Otherwise, implement own // Otherwise, implement own
else { else {
addClass = function(element, classname) { GuacamoleUI.addClass = function(element, classname) {
// Simply add new class // Simply add new class
element.className += " " + classname; element.className += " " + classname;
}; };
removeClass = function(element, classname) { GuacamoleUI.removeClass = function(element, classname) {
// Filter out classes with given name // Filter out classes with given name
element.className = element.className.replace(/([^ ]+)[ ]*/g, element.className = element.className.replace(/([^ ]+)[ ]*/g,
@@ -161,56 +148,35 @@ GuacamoleUI.toggleKeyboard = function() {
}; };
} }
GuacamoleUI.hideStatus = function() { GuacamoleUI.hideStatus = function() {
removeClass(document.body, "guac-error"); GuacamoleUI.removeClass(document.body, "guac-error");
GuacamoleUI.containers.state.style.visibility = "hidden"; GuacamoleUI.containers.state.style.visibility = "hidden";
GuacamoleUI.display.style.opacity = "1"; GuacamoleUI.display.style.opacity = "1";
}; };
GuacamoleUI.showStatus = function(text) { GuacamoleUI.showStatus = function(text) {
removeClass(document.body, "guac-error"); GuacamoleUI.removeClass(document.body, "guac-error");
GuacamoleUI.containers.state.style.visibility = "visible"; GuacamoleUI.containers.state.style.visibility = "visible";
GuacamoleUI.state.textContent = text; GuacamoleUI.state.textContent = text;
GuacamoleUI.display.style.opacity = "1"; GuacamoleUI.display.style.opacity = "1";
}; };
GuacamoleUI.showError = function(error) { GuacamoleUI.showError = function(error) {
addClass(document.body, "guac-error"); GuacamoleUI.addClass(document.body, "guac-error");
GuacamoleUI.state.textContent = error; GuacamoleUI.state.textContent = error;
GuacamoleUI.display.style.opacity = "0.1"; GuacamoleUI.display.style.opacity = "0.1";
}; };
// Detect three-finger tap // Reconnect button
GuacamoleUI.display.addEventListener('touchstart', function(e) { GuacamoleUI.buttons.reconnect.onclick = function() {
// If three touches, toggle keyboard
if (e.touches.length == 3)
GuacamoleUI.toggleKeyboard();
}, true);
function positionCentered(element) {
element.style.left =
((GuacamoleUI.viewport.offsetWidth - element.offsetWidth) / 2
+ window.pageXOffset)
+ "px";
element.style.top =
((GuacamoleUI.viewport.offsetHeight - element.offsetHeight) / 2
+ window.pageYOffset)
+ "px";
}
// Reconnect button
GuacamoleUI.buttons.reconnect.onclick = function() {
window.location.reload(); window.location.reload();
}; };
// Query audio support // Query audio support
if (!GuacamoleUI.sessionState.getProperty("disable-sound")) if (!GuacamoleUI.sessionState.getProperty("disable-sound"))
(function () { (function () {
var probably_supported = []; var probably_supported = [];
var maybe_supported = []; var maybe_supported = [];
@@ -244,8 +210,8 @@ GuacamoleUI.toggleKeyboard = function() {
Array.prototype.push.apply(GuacamoleUI.supportedAudio, maybe_supported); Array.prototype.push.apply(GuacamoleUI.supportedAudio, maybe_supported);
})(); })();
// Query video support // Query video support
(function () { (function () {
var probably_supported = []; var probably_supported = [];
var maybe_supported = []; var maybe_supported = [];
@@ -274,8 +240,6 @@ GuacamoleUI.toggleKeyboard = function() {
Array.prototype.push.apply(GuacamoleUI.supportedVideo, probably_supported); Array.prototype.push.apply(GuacamoleUI.supportedVideo, probably_supported);
Array.prototype.push.apply(GuacamoleUI.supportedVideo, maybe_supported); Array.prototype.push.apply(GuacamoleUI.supportedVideo, maybe_supported);
})();
})(); })();
// Tie UI events / behavior to a specific Guacamole client // Tie UI events / behavior to a specific Guacamole client