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,27 +107,14 @@ GuacamoleUI.toggleKeyboard = function() {
}; };
// Constant UI initialization and behavior
(function() {
// Cache error image (might not be available when error occurs)
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 is supported, implement addClass/removeClass using that
if (Node.classList) { if (Node.classList) {
addClass = function(element, classname) { GuacamoleUI.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);
}; };
@@ -136,14 +123,14 @@ GuacamoleUI.toggleKeyboard = function() {
// 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,
@@ -165,45 +152,24 @@ 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
GuacamoleUI.display.addEventListener('touchstart', function(e) {
// 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 // Reconnect button
GuacamoleUI.buttons.reconnect.onclick = function() { GuacamoleUI.buttons.reconnect.onclick = function() {
window.location.reload(); window.location.reload();
@@ -276,8 +242,6 @@ GuacamoleUI.toggleKeyboard = function() {
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
GuacamoleUI.attach = function(guac) { GuacamoleUI.attach = function(guac) {