1999-08-23 07:48:53 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-08-23 07:48:53 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-08-23 07:48:53 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-08-23 07:48:53 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-08-23 07:48:53 +04:00
|
|
|
*/
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
/*
|
|
|
|
|
|
|
|
Script for the directory window
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1999-08-23 07:48:53 +04:00
|
|
|
// By the time this runs, The 'HTTPIndex' variable will have been
|
|
|
|
// magically set on the global object by the native code.
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
function debug(msg)
|
|
|
|
{
|
|
|
|
// Uncomment to print out debug info.
|
|
|
|
//dump(msg);
|
|
|
|
}
|
|
|
|
|
1999-08-23 07:48:53 +04:00
|
|
|
function Init()
|
|
|
|
{
|
1999-08-25 07:50:15 +04:00
|
|
|
debug("directory.js: Init()\n");
|
1999-08-23 07:48:53 +04:00
|
|
|
|
|
|
|
// Add the HTTPIndex datasource into the tree
|
|
|
|
var tree = document.getElementById('tree');
|
|
|
|
tree.database.AddDataSource(HTTPIndex.DataSource);
|
|
|
|
|
|
|
|
// Initialize the tree's base URL to whatever the HTTPIndex is rooted at
|
1999-08-25 07:50:15 +04:00
|
|
|
debug("base URL = " + HTTPIndex.BaseURL + "\n");
|
1999-08-23 07:48:53 +04:00
|
|
|
tree.setAttribute('ref', HTTPIndex.BaseURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
function OnClick(event)
|
1999-08-25 05:32:40 +04:00
|
|
|
{
|
1999-08-25 07:50:15 +04:00
|
|
|
debug('OnClick()\n');
|
|
|
|
|
|
|
|
// This'll be set to 'twisty' on the twisty icon, and 'filename'
|
|
|
|
// if they're over the filename link.
|
|
|
|
var targetclass = event.target.getAttribute('class');
|
|
|
|
debug('targetclass = ' + targetclass + '\n');
|
|
|
|
|
|
|
|
if (targetclass == 'twisty') {
|
|
|
|
// The twisty is nested three below the treeitem:
|
|
|
|
// <treeitem>
|
|
|
|
// <treerow>
|
|
|
|
// <treecell>
|
2000-02-16 01:23:32 +03:00
|
|
|
// <titledbutton class="twisty"> <!-- anonymous -->
|
|
|
|
var treeitem = event.target.parentNode.parentNode.parentNode;
|
1999-08-25 07:50:15 +04:00
|
|
|
ToggleOpenState(treeitem);
|
1999-08-25 05:32:40 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-08-25 07:50:15 +04:00
|
|
|
// The click'll have hit a cell, which is nested two below the
|
|
|
|
// treeitem.
|
|
|
|
var treeitem = event.target.parentNode.parentNode;
|
|
|
|
|
|
|
|
// This'll be set to 'FILE' for files and 'DIRECTORY' for
|
|
|
|
// directories.
|
|
|
|
var type = treeitem.getAttribute('type');
|
|
|
|
|
2000-02-08 04:20:01 +03:00
|
|
|
if (targetclass == 'filename') {
|
1999-08-25 07:50:15 +04:00
|
|
|
var url = treeitem.getAttribute('id');
|
|
|
|
|
|
|
|
debug('navigating to ' + url + '\n');
|
|
|
|
window.content.location.href = url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function OnDblClick(event)
|
|
|
|
{
|
|
|
|
debug('OnDblClick()\n');
|
|
|
|
|
|
|
|
// This'll be set to 'filename' if they're over the filename link.
|
|
|
|
var targetclass = event.target.getAttribute('class');
|
|
|
|
|
|
|
|
// This'll be the treeitem that got the event
|
|
|
|
var treeitem = event.target.parentNode.parentNode;
|
|
|
|
|
|
|
|
// This'll be set to 'FILE' for files and 'DIRECTORY' for
|
|
|
|
// directories.
|
|
|
|
var type = treeitem.getAttribute('type');
|
|
|
|
|
|
|
|
if (targetclass == 'filename' && type == 'DIRECTORY') {
|
|
|
|
ToggleOpenState(treeitem);
|
1999-08-25 05:32:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
function ToggleOpenState(treeitem)
|
1999-08-25 05:32:40 +04:00
|
|
|
{
|
1999-08-25 07:50:15 +04:00
|
|
|
debug('ToggleOpenState(' + treeitem.tagName + ')');
|
|
|
|
|
|
|
|
if (treeitem.getAttribute('open') == 'true') {
|
|
|
|
var url = treeitem.getAttribute('id');
|
1999-09-22 01:43:41 +04:00
|
|
|
if (!Read[url]) {
|
|
|
|
treeitem.setAttribute('loading', 'true');
|
|
|
|
ReadDirectory(url);
|
|
|
|
Read[url] = true;
|
|
|
|
}
|
1999-08-25 05:32:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
// This array contains the URL of each directory we've read, so that
|
|
|
|
// we don't load a directory into the datasource >1 time.
|
1999-08-25 05:32:40 +04:00
|
|
|
var Read = new Array();
|
|
|
|
|
|
|
|
function ReadDirectory(url)
|
|
|
|
{
|
1999-08-25 07:50:15 +04:00
|
|
|
debug('ReadDirectory(' + url + ')\n');
|
1999-08-25 05:32:40 +04:00
|
|
|
|
1999-11-16 00:16:10 +03:00
|
|
|
var ios = Components.classes['component://netscape/network/io-service'].getService();
|
1999-08-25 05:32:40 +04:00
|
|
|
ios = ios.QueryInterface(Components.interfaces.nsIIOService);
|
|
|
|
|
1999-10-13 05:36:57 +04:00
|
|
|
var uri = ios.newURI(url, null);
|
1999-08-25 05:32:40 +04:00
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
// Create a channel...
|
1999-12-07 02:45:34 +03:00
|
|
|
var channel = ios.newChannelFromURI('load', uri, null, null,
|
|
|
|
Components.interfaces.nsIChannel.LOAD_NORMAL,
|
|
|
|
null, 0, 0);
|
1999-08-25 05:32:40 +04:00
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
// ...so that we can pipe it into a new HTTPIndex listener to
|
|
|
|
// parse the directory's contents.
|
1999-10-13 05:36:57 +04:00
|
|
|
channel.asyncRead(0, -1, null, HTTPIndex.CreateListener());
|
1999-08-25 05:32:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-23 07:48:53 +04:00
|
|
|
// We need this hack because we've completely circumvented the onload() logic.
|
|
|
|
function Boot()
|
|
|
|
{
|
|
|
|
if (document.getElementById('tree')) {
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setTimeout("Boot()", 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout("Boot()", 0);
|
1999-08-25 05:32:40 +04:00
|
|
|
|
|
|
|
|
1999-08-30 13:34:46 +04:00
|
|
|
function doSort(sortColName)
|
|
|
|
{
|
|
|
|
var node = document.getElementById(sortColName);
|
|
|
|
if (!node) return(false);
|
|
|
|
|
|
|
|
// determine column resource to sort on
|
|
|
|
var sortResource = node.getAttribute('resource');
|
|
|
|
|
|
|
|
// switch between ascending & descending sort (no natural order support)
|
|
|
|
var sortDirection="ascending";
|
|
|
|
var isSortActive = node.getAttribute('sortActive');
|
|
|
|
if (isSortActive == "true")
|
|
|
|
{
|
|
|
|
var currentDirection = node.getAttribute('sortDirection');
|
|
|
|
if (currentDirection == "ascending")
|
|
|
|
{
|
|
|
|
sortDirection = "descending";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var isupports = Components.classes["component://netscape/rdf/xul-sort-service"].getService();
|
|
|
|
if (!isupports) return(false);
|
|
|
|
var xulSortService = isupports.QueryInterface(Components.interfaces.nsIXULSortService);
|
|
|
|
if (!xulSortService) return(false);
|
|
|
|
xulSortService.Sort(node, sortResource, sortDirection);
|
|
|
|
|
|
|
|
return(false);
|
|
|
|
}
|