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.
|
2000-04-27 05:17:10 +04:00
|
|
|
dump(msg);
|
1999-08-25 07:50:15 +04:00
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
// Initialize the tree's base URL to whatever the HTTPIndex is rooted at
|
2000-04-27 05:17:10 +04:00
|
|
|
var baseURI = HTTPIndex.BaseURL;
|
|
|
|
|
|
|
|
// fix bug # 37102: if its a FTP directory
|
|
|
|
// ensure it ends with a trailing slash
|
|
|
|
if (baseURI && (baseURI.indexOf("ftp://") == 0) &&
|
|
|
|
(baseURI.substr(baseURI.length - 1) != "/"))
|
|
|
|
{
|
|
|
|
debug("append traiing slash to FTP directory URL\n");
|
|
|
|
baseURI += "/";
|
|
|
|
}
|
|
|
|
debug("base URL = " + baseURI + "\n");
|
2000-05-10 04:26:46 +04:00
|
|
|
|
2000-07-14 13:07:13 +04:00
|
|
|
// Note: set encoding for FTP URLs BEFORE setting "ref"
|
|
|
|
HTTPIndex.encoding = "ISO-8859-1";
|
|
|
|
|
|
|
|
// re-root the tree
|
2000-04-27 05:17:10 +04:00
|
|
|
tree.setAttribute("ref", baseURI);
|
1999-08-23 07:48:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-14 13:07:13 +04:00
|
|
|
|
1999-08-25 07:50:15 +04:00
|
|
|
function OnClick(event)
|
1999-08-25 05:32:40 +04:00
|
|
|
{
|
2000-05-10 04:26:46 +04:00
|
|
|
if( event.type == "click" &&
|
2000-05-16 15:35:12 +04:00
|
|
|
( event.button != 1 || event.detail != 2 ) )
|
2000-05-10 04:26:46 +04:00
|
|
|
return false;
|
|
|
|
if( event.type == "keypress" && event.which != 13 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var tree = document.getElementById("tree");
|
|
|
|
if( tree.selectedItems.length == 1 )
|
|
|
|
{
|
|
|
|
var selectedItem = tree.selectedItems[0];
|
|
|
|
|
|
|
|
//if( selectedItem.getAttribute( "type" ) == "FILE" )
|
2000-06-22 04:48:45 +04:00
|
|
|
window._content.location.href = selectedItem.getAttribute('id');
|
2000-05-10 04:26:46 +04:00
|
|
|
}
|
1999-08-25 07:50:15 +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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-17 09:07:26 +04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
}
|
1999-08-30 13:34:46 +04:00
|
|
|
return(false);
|
|
|
|
}
|