mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-932: Remove legacy JavaScript source.
This commit is contained in:
@@ -142,8 +142,6 @@
|
|||||||
<jsSourceFile>lib/messageformat/messageformat.js</jsSourceFile>
|
<jsSourceFile>lib/messageformat/messageformat.js</jsSourceFile>
|
||||||
<jsSourceFile>license.txt</jsSourceFile>
|
<jsSourceFile>license.txt</jsSourceFile>
|
||||||
<jsSourceFile>guacamole-common-js/all.js</jsSourceFile>
|
<jsSourceFile>guacamole-common-js/all.js</jsSourceFile>
|
||||||
<jsSourceFile>scripts/session.js</jsSourceFile>
|
|
||||||
<jsSourceFile>scripts/history.js</jsSourceFile>
|
|
||||||
</jsSourceFiles>
|
</jsSourceFiles>
|
||||||
|
|
||||||
<jsSourceIncludes>
|
<jsSourceIncludes>
|
||||||
|
@@ -1,212 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Glyptodon LLC
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set of thumbnails for each connection, indexed by ID.
|
|
||||||
*/
|
|
||||||
GuacamoleHistory = new (function() {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reference to this GuacamoleHistory.
|
|
||||||
*/
|
|
||||||
var guac_history = this;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of entries to allow before removing old entries based on the
|
|
||||||
* cutoff.
|
|
||||||
*/
|
|
||||||
var IDEAL_LENGTH = 6;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum age of a history entry before it is removed, in
|
|
||||||
* milliseconds.
|
|
||||||
*/
|
|
||||||
var CUTOFF_AGE = 900000;
|
|
||||||
|
|
||||||
var history = {};
|
|
||||||
|
|
||||||
function truncate() {
|
|
||||||
|
|
||||||
// Build list of entries
|
|
||||||
var entries = [];
|
|
||||||
for (var old_id in history)
|
|
||||||
entries.push(history[old_id]);
|
|
||||||
|
|
||||||
// Avoid history growth beyond defined number of entries
|
|
||||||
if (entries.length > IDEAL_LENGTH) {
|
|
||||||
|
|
||||||
// Sort list
|
|
||||||
entries.sort(GuacamoleHistory.Entry.compare);
|
|
||||||
|
|
||||||
// Remove entries until length is ideal or all are recent
|
|
||||||
var now = new Date().getTime();
|
|
||||||
while (entries.length > IDEAL_LENGTH
|
|
||||||
&& now - entries[0].accessed > CUTOFF_AGE) {
|
|
||||||
|
|
||||||
// Remove entry
|
|
||||||
var removed = entries.shift();
|
|
||||||
delete history[removed.id];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the URL for the thumbnail of the connection with the given ID,
|
|
||||||
* or undefined if no thumbnail is associated with that connection.
|
|
||||||
*/
|
|
||||||
this.get = function(id) {
|
|
||||||
return history[id] || new GuacamoleHistory.Entry();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the thumbnail and access time of the history entry for the
|
|
||||||
* connection with the given ID.
|
|
||||||
*/
|
|
||||||
this.update = function(id, thumbnail) {
|
|
||||||
|
|
||||||
/* Do nothing if localStorage not present */
|
|
||||||
if (!localStorage)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Create updated entry
|
|
||||||
var entry = new GuacamoleHistory.Entry(
|
|
||||||
id,
|
|
||||||
thumbnail,
|
|
||||||
new Date().getTime()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Store entry in history
|
|
||||||
history[id] = entry;
|
|
||||||
truncate();
|
|
||||||
|
|
||||||
// Save updated history, ignore inability to use localStorage
|
|
||||||
try {
|
|
||||||
localStorage.setItem("GUAC_HISTORY", JSON.stringify(history));
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reloads all history data.
|
|
||||||
*/
|
|
||||||
this.reload = function() {
|
|
||||||
|
|
||||||
/* Do nothing if localStorage not present */
|
|
||||||
if (!localStorage)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Get old and new for comparison, ignore inability to use localStorage
|
|
||||||
var old_history = history;
|
|
||||||
try {
|
|
||||||
var new_history = JSON.parse(localStorage.getItem("GUAC_HISTORY") || "{}");
|
|
||||||
}
|
|
||||||
catch (ignore) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update history
|
|
||||||
history = new_history;
|
|
||||||
|
|
||||||
// Call onchange handler as necessary
|
|
||||||
if (guac_history.onchange) {
|
|
||||||
|
|
||||||
// Produce union of all known IDs
|
|
||||||
var known_ids = {};
|
|
||||||
for (var new_id in new_history) known_ids[new_id] = true;
|
|
||||||
for (var old_id in old_history) known_ids[old_id] = true;
|
|
||||||
|
|
||||||
// For each known ID
|
|
||||||
for (var id in known_ids) {
|
|
||||||
|
|
||||||
// Get entries
|
|
||||||
var old_entry = old_history[id];
|
|
||||||
var new_entry = new_history[id];
|
|
||||||
|
|
||||||
// Call handler for all changed
|
|
||||||
if (!old_entry || !new_entry
|
|
||||||
|| old_entry.accessed != new_entry.accessed)
|
|
||||||
guac_history.onchange(id, old_entry, new_entry);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end onchange
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event handler called whenever a history entry is changed.
|
|
||||||
*
|
|
||||||
* @event
|
|
||||||
* @param {String} id The ID of the connection whose history entry is
|
|
||||||
* changing.
|
|
||||||
* @param {GuacamoleHistory.Entry} old_entry The old value of the entry, if
|
|
||||||
* any.
|
|
||||||
* @param {GuacamoleHistory.Entry} new_entry The new value of the entry, if
|
|
||||||
* any.
|
|
||||||
*/
|
|
||||||
this.onchange = null;
|
|
||||||
|
|
||||||
// Reload when modified
|
|
||||||
window.addEventListener("storage", guac_history.reload, false);
|
|
||||||
|
|
||||||
// Initial load
|
|
||||||
guac_history.reload();
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A single entry in the indexed connection usage history.
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @param {String} id The ID of this connection.
|
|
||||||
* @param {String} thumbnail The URL of the thumbnail to use to represent this
|
|
||||||
* connection.
|
|
||||||
* @param {Number} last_access The time this connection was last accessed, in
|
|
||||||
* seconds.
|
|
||||||
*/
|
|
||||||
GuacamoleHistory.Entry = function(id, thumbnail, last_access) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ID of the connection associated with this history entry.
|
|
||||||
*/
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The thumbnail associated with the connection associated with this history
|
|
||||||
* entry.
|
|
||||||
*/
|
|
||||||
this.thumbnail = thumbnail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The time the connection associated with this entry was last accessed.
|
|
||||||
*/
|
|
||||||
this.accessed = last_access;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GuacamoleHistory.Entry.compare = function(a, b) {
|
|
||||||
return a.accessed - b.accessed;
|
|
||||||
};
|
|
@@ -1,171 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Glyptodon LLC
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Global storage for Guacamole pages.
|
|
||||||
*/
|
|
||||||
GuacamoleSessionStorage = (function() {
|
|
||||||
|
|
||||||
// Retrieve storage from owner of window, if possible
|
|
||||||
var opener_storage = null;
|
|
||||||
try {
|
|
||||||
opener_storage = opener && opener.GuacamoleSessionStorage;
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
|
|
||||||
return opener_storage;
|
|
||||||
|
|
||||||
})() || new (function() {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The contents of storage, as a JSON string containing name/value pairs as
|
|
||||||
* properties.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @type String
|
|
||||||
*/
|
|
||||||
var stored_json = "{}";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called whenever an item value changes.
|
|
||||||
*
|
|
||||||
* @callback onchange
|
|
||||||
* @param {String} name The name of the item changed.
|
|
||||||
* @param value The new item value.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All attached listeners.
|
|
||||||
*
|
|
||||||
* @type onchange[]
|
|
||||||
*/
|
|
||||||
var listeners = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies all listeners that an item has changed.
|
|
||||||
*
|
|
||||||
* @param {String} name The name of the item that changed.
|
|
||||||
* @param value The new item value.
|
|
||||||
*/
|
|
||||||
function __notify_changed(name, value) {
|
|
||||||
for (var i=0; i<listeners.length; i++)
|
|
||||||
listeners[i](name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the value stored within the item having the given name.
|
|
||||||
*
|
|
||||||
* @param {String} name The name of the item to read.
|
|
||||||
* @param [value] The default value, if any.
|
|
||||||
* @return The value of the given item.
|
|
||||||
*/
|
|
||||||
this.getItem = function(name, value) {
|
|
||||||
|
|
||||||
// Attempt to read JSON from localStorage, default to local variable
|
|
||||||
var json = stored_json;
|
|
||||||
if (localStorage) {
|
|
||||||
try {
|
|
||||||
json = localStorage.getItem("GUACAMOLE_STATE") || "{}";
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
var obj = JSON.parse(json);
|
|
||||||
if (obj[name] !== undefined)
|
|
||||||
return obj[name];
|
|
||||||
|
|
||||||
return value;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the item having the given name to the given value.
|
|
||||||
*
|
|
||||||
* @param {String} name The name of the item to change.
|
|
||||||
* @param [value] An arbitrary value.
|
|
||||||
*/
|
|
||||||
this.setItem = function(name, value) {
|
|
||||||
|
|
||||||
// Attempt to read JSON from localStorage, default to local variable
|
|
||||||
var json = stored_json;
|
|
||||||
if (localStorage) {
|
|
||||||
try {
|
|
||||||
json = localStorage.getItem("GUACAMOLE_STATE") || "{}";
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modify object property
|
|
||||||
var obj = JSON.parse(json);
|
|
||||||
var old = obj[name];
|
|
||||||
obj[name] = value;
|
|
||||||
|
|
||||||
// Notify of change
|
|
||||||
if (old !== value)
|
|
||||||
__notify_changed(name, value);
|
|
||||||
|
|
||||||
// Attempt to set JSON within localStorage, default to local variable
|
|
||||||
stored_json = JSON.stringify(obj);
|
|
||||||
if (localStorage) {
|
|
||||||
try {
|
|
||||||
localStorage.setItem("GUACAMOLE_STATE", stored_json);
|
|
||||||
}
|
|
||||||
catch (ignore) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// Reload when modified
|
|
||||||
window.addEventListener("storage", function reload() {
|
|
||||||
|
|
||||||
// Pull current state
|
|
||||||
var new_json = localStorage.getItem("GUACAMOLE_STATE") || "{}";
|
|
||||||
|
|
||||||
var new_state = JSON.parse(new_json);
|
|
||||||
var old_state = JSON.parse(stored_json);
|
|
||||||
|
|
||||||
// Check if any values are different
|
|
||||||
for (var name in new_state) {
|
|
||||||
|
|
||||||
// If value changed, notify
|
|
||||||
var old = old_state[name];
|
|
||||||
if (old !== new_state[name])
|
|
||||||
__notify_changed(name, new_state[name]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
stored_json = new_json;
|
|
||||||
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensures that the given function will be called for each change in
|
|
||||||
* item value. The function must accept a single argument which will be
|
|
||||||
* the name of the item changed.
|
|
||||||
*
|
|
||||||
* @param {onchange} onchange The function to call when an item changes.
|
|
||||||
*/
|
|
||||||
this.addChangeListener = function(onchange) {
|
|
||||||
listeners.push(onchange);
|
|
||||||
};
|
|
||||||
|
|
||||||
})();
|
|
Reference in New Issue
Block a user