Can YOU describe/explain what this JavaScript does?
=
$(document).ready(
function()
{
// Override the copy operation without harming validation.
$('body').bind(
{
copy :
function()
{
docopy();
}
});
// Don't allow context menu.
$('body').bind(
{
contextmenu :
function(event)
{
if(window.getSelection)
{
text = window.getSelection().toString();
if(text == "")
event.preventDefault();
}
else
event.preventDefault();
}
});
});
// Issue a REST GET request.
function GET(path)
{
if(window.webkit != undefined)
window.webkit.messageHandlers.get.postMessage(path);
else if(window.get != undefined)
window.get.postMessage(path);
}
// Keep track of whether or not unmounted volumes are visible.
var unmountedVolumesVisible = false;
var searchText = null;
var searchResults = [];
var searchResultIndex = 0;
// Show unmounted volumes.
function showUnmountedVolumes()
{
$(".notmounted").fadeIn();
$(".container").fadeIn();
$(".container").prev('tr').removeClass('last_child');
$("#hide_unmounted_volumes").fadeIn();
$("#show_unmounted_volumes").fadeOut();
unmountedVolumesVisible = true;
}
// Hide unmounted volumes.
function hideUnmountedVolumes()
{
$(".notmounted").fadeOut();
$(".container").fadeOut();
$("#show_unmounted_volumes").fadeIn();
$("#hide_unmounted_volumes").fadeOut({
complete:
function ()
{
$(".container").prev('tr').addClass('last_child');
}
});
unmountedVolumesVisible = false;
}
// Scroll to a device.
function showPartition(event, device)
{
// Don't jump to #.
event.preventDefault();
if(!unmountedVolumesVisible)
showUnmountedVolumes();
focusOnElementById(device);
}
function focusOnElementById(id)
{
var element = $("#" + id);
if(element.offset() == undefined)
{
var parts = id.split('_');
if(parts.length > 1)
{
id = parts[0] + "_" + parts[0];
element = $("#" + id);
}
}
focusOnElement(element);
}
function focusOnElement(element)
{
var container = $("div.scrollfix");
var scrollTop =
element.offset().top
- container.offset().top
+ container.scrollTop();
container.animate(
{
scrollTop: scrollTop
},
500,
"swing",
function()
{
element.addClass("flash");
});
setTimeout(
function()
{
element.removeClass("flash");
},
2000);
}
// Get the current scroll position.
function getCurrentScrollTop()
{
return $("div.scrollfix").scrollTop();
}
// Restore the current scroll position.
function setCurrentScrollTop(scrollTop)
{
return $("div.scrollfix").scrollTop(scrollTop);
}
// Show Apple files having a given status and type (agent/daemon).
function showAppleFiles(showButton, status, type, last_row)
{
$(".apple." + status + "." + type).fadeIn();
$(showButton).next().fadeIn();
$(showButton).fadeOut();
if(last_row)
$(showButton).parent().closest('tr').removeClass('last_child');
}
// Hide Apple files having a givent status and type (agent/daemon).
function hideAppleFiles(hideButton, status, type, last_row)
{
$(".apple." + status + "." + type).fadeOut();
$(hideButton).prev().fadeIn();
$(hideButton).fadeOut(
{
complete:
function()
{
if(last_row)
$(hideButton).parent().closest('tr').addClass('last_child');
}
});
}
// Show unsigned apps.
function showUnsignedApps(showButton)
{
$(".unsignedapps").fadeIn();
$(showButton).next().fadeIn();
$(showButton).fadeOut();
$(showButton).parent().closest('tr').removeClass('last_child');
}
// Hide unsigned apps.
function hideUnsignedApps(hideButton)
{
$(".unsignedapps").fadeOut();
$(hideButton).prev().fadeIn();
$(hideButton).fadeOut();
$(hideButton).parent().closest('tr').addClass('last_child');
}
// Show old apps.
function showOldApps(showButton)
{
$(".oldapps").fadeIn();
$(showButton).next().fadeIn();
$(showButton).fadeOut();
$(showButton).parent().closest('tr').removeClass('last_child');
}
// Hide old apps.
function hideOldApps(hideButton)
{
$(".oldapps").fadeOut();
$(hideButton).prev().fadeIn();
$(hideButton).fadeOut();
$(hideButton).parent().closest('tr').addClass('last_child');
}
// Show unsigned files
function showUnsignedFiles(button)
{
GET('/showunsignedfiles');
}
// Show unsigned files
function hideUnsignedFiles(button)
{
GET('/hideunsignedfiles');
}
// Jump to a specific section.
function jump(section, anchor)
{
// Don't jump to #.
event.preventDefault();
var path = "/jump/" + section;
if(anchor != "")
path += "/" + anchor;
GET(path);
}
// Intercept the copy operation.
function docopy()
{
GET("/copy");
}
// Unload a launchd file.
function unload(identifier)
{
GET('/launchd/unload/' + identifier);
}
// Load a launchd file.
function load(identifier)
{
GET('/launchd/load/' + identifier);
}
// Perform a live update.
function performLiveUpdate(identifier, status, statusString)
{
if(identifier.startsWith("launchd"))
updateLaunchdFile(identifier, status, statusString);
else if(identifier.startsWith("safariextension"))
updateSafariExtension(idenifier, status, statusString);
}
// Update a launchd file.
function updateLaunchdFile(identifier, status, statusString)
{
if(status == "deleted")
{
$("." + identifier).remove();
if($(".adware tbody").length == 0)
$(".adware").remove();
if($(".unsigned tbody").length == 0)
$(".unsigned").remove();
if($(".launchagents tbody").length == 0)
$(".launchagents").remove();
if($(".launchdaemons tbody").length == 0)
$(".launchdaemons").remove();
if($(".userlaunchagents tbody").length == 0)
$(".userlaunchagents").remove();
}
$("." + identifier + " .status").html(statusString);
if(status == "loaded")
{
$("." + identifier + " button.load").attr("disabled", "disabled");
$("." + identifier + " button.unload").removeAttr("disabled");
$("." + identifier + " .status img.spinner").remove();
$("." + identifier + "
button.reveal_config").removeAttr("disabled");
$("." + identifier + " button.reveal_executable").removeAttr(
"disabled");
}
else if(status == "notloaded")
{
$("." + identifier + " button.unload").attr("disabled", "disabled");
$("." + identifier + " button.load").removeAttr("disabled");
$("." + identifier + " .status img.spinner").remove();
$("." + identifier + "
button.reveal_config").removeAttr("disabled");
$("." + identifier + " button.reveal_executable").removeAttr(
"disabled");
}
else if(status == "removing")
{
$("." + identifier + " .status").append(
"<img class='spinner' src='image/Spinner.png'>");
$("." + identifier + " button.unload").attr("disabled", "disabled");
$("." + identifier + " button.load").attr("disabled", "disabled");
$("." + identifier + " button.reveal_config").attr(
"disabled", "disabled");
$("." + identifier + " button.reveal_executable").attr(
"disabled", "disabled");
}
}
// Update a Safari extension.
function updateSafariExtension(identifier, status, statusString)
{
if(status == "deleted")
$("." + identifier).remove();
if($(".adware tr").length == 1)
$(".adware").remove();
}
// Update Gatekeeper.
function updateGatekeeper(statusString)
{
$("#gatekeeperstatus").html(statusString);
}
// Remove an item from a section.
function removeItem(item, sectionName)
{
var section = $("." + sectionName);
if($("tbody", section).length == 1)
$(section).fadeOut(
{
complete:
function()
{
$(section).remove();
}
});
else
$("." + item, section).fadeOut(
{
complete:
function()
{
$("." + item, section).remove();
}
});
}
function search(string)
{
searchText = string;
searchResults = [];
searchResultIndex = 0;
findText(document.getElementsByTagName("BODY")[0],
string.toLowerCase());
if(searchResults.length > 0)
{
highlightFoundText();
return true;
}
return false;
}
function searchlast(string)
{
searchText = string;
searchResults = [];
searchResultIndex = 0;
findText(document.getElementsByTagName("BODY")[0],
string.toLowerCase());
if(searchResults.length > 0)
{
searchResultIndex = (searchResults.length - 1);
highlightFoundText();
}
return searchResultIndex > 0;
}
function unhighlightFoundText()
{
var selection = window.getSelection();
selection.removeAllRanges();
}
function highlightFoundText()
{
if(searchResultIndex <= searchResults.length)
{
var result = searchResults[searchResultIndex];
var range = document.createRange();
range.setStart(result.textNode, result.location);
range.setEnd(result.textNode, result.location + result.length);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
var container = $("div.scrollfix");
var scrollTop =
$(result.element).offset().top
- container.offset().top
+ container.scrollTop();
container.animate(
{
scrollTop: scrollTop
},
500,
"swing");
}
}
function findText(element, text)
{
var length = element.childNodes.length;
for(var i = 0; i < length; i++)
{
var child = element.childNodes[i];
if(child.nodeType === 3)
{
var start = 0;
var haystack = child.nodeValue.toLowerCase();
var location = 0;
while(location !== -1)
{
location = haystack.indexOf(text, start);
if(location !== -1)
{
searchResults.push(
{
index: i,
location: location,
length: text.length,
element: element,
textNode: child
});
start = location + text.length;
}
}
}
}
for(var i = 0; i < length; i++)
{
var child = element.childNodes[i];
if(child.nodeType === 1)
findText(child, text);
}
}
function findNext()
{
if(searchResultIndex < (searchResults.length - 1))
{
unhighlightFoundText();
++searchResultIndex;
highlightFoundText();
return true;
}
return false;
}
function findPrevious()
{
if(searchResultIndex > 0)
{
unhighlightFoundText();
--searchResultIndex;
highlightFoundText();
return true;
}
return false;
}
function searchselection()
{
var string = window.getSelection().toString();
if(string == "")
return {searchtext: "", found: false};
if(string == searchText)
return {searchtext: string, found: findNext()};
searchText = string;
searchResults = [];
searchResultIndex = 0;
findText(document.getElementsByTagName("BODY")[0],
string.toLowerCase());
if(searchResults.length > 1)
{
++searchResultIndex;
highlightFoundText();
return {searchtext: string, found: true};
}
return {searchtext: string, found: false};
}
// Show notifications for a given app
function showNotifications(showButton, identifier, last_row)
{
$(".notifications tr." + identifier).fadeIn();
$(showButton).next().fadeIn();
$(showButton).fadeOut();
if(last_row)
$(showButton).parent().closest('tr').removeClass('last_child');
}
// Hide notifications for a given app.
function hideNotifications(hideButton, identifier, last_row)
{
$(".notifications tr." + identifier).fadeOut();
$(hideButton).prev().fadeIn();
$(hideButton).fadeOut(
{
complete:
function()
{
if(last_row)
$(hideButton).parent().closest('tr').addClass('last_child');
}
});
}
function getSelectedLineRange()
{
var selection = window.getSelection();
var text = selection.toString();
var range = null;
if(selection.rangeCount > 0)
range = selection.getRangeAt(0);
else
{
range = document.createRange();
range.collapse(true);
}
var tempRange = document.createRange();
tempRange.selectNodeContents(document.body);
tempRange.setEnd(range.startContainer, range.startOffset);
var before = tempRange.toString();
tempRange.detach();
var startline = before.split(/\r\n|\r|\n/).length - 1;
var linelength = text.split(/\r\n|\r|\n/).length - 1;
var result =
{
startline: startline,
linelength: linelength,
start: before.length,
length: text.length
};
return result;
}
function restoreSelection(json)
{
var selection = JSON.parse(json);
var state =
{
start: selection.start,
end: selection.start + selection.length,
textLength: 0,
range: document.createRange(),
startRangeSet: false,
done: false
};
restoreSelectedText(document.getElementsByTagName("BODY")[0], state);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(state.range);
return "OK";
}
function restoreSelectedText(element, state)
{
var length = element.childNodes.length;
for(var i = 0; i < length; i++)
{
if(state.done)
return;
var child = element.childNodes[i];
if(child.nodeType === 1)
restoreSelectedText(child, state);
else if(child.nodeType === 3)
{
var nodeText = child.nodeValue;
if((state.textLength + nodeText.length) >= state.start)
if(!state.startRangeSet)
{
state.range.setStart(child, state.start - state.textLength);
state.startRangeSet = true;
}
if((state.textLength + nodeText.length) >= state.end)
{
state.range.setEnd(child, state.end - state.textLength);
state.done = true;
}
state.textLength += nodeText.length;
}
}
}
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 62:19:55 |
Calls: | 6,712 |
Files: | 12,244 |
Messages: | 5,355,895 |