jQuery File Tree
Written by Cory S.N. LaViska on March 25th, 2008
A configurable, AJAX file browser plugin for jQuery.
The responses to jQuery File Tree have been incredible over the past few months. A special thanks to everyone for your compliments and support :)
If anyone is interested in a 2.0 release, let me know. I'm thinking that I'd like to branch this project into a generic AJAX tree that can use custom connectors for more than just files and folders. I've been considering some really great features, but I'd prefer to hear what you folks want before I make any final decisions. If I get a decent response, there's a good chance you'll see another version of this plugin in the near future.
Contents
- Overview
- Features
- Compatibility
- Demo
- Download
- Usage
- Connector Scripts
- Version History
- Licensing & Terms of Use
- Special Thanks
- Comments
Overview
jQuery File Tree is a configurable, AJAX file browser plugin for jQuery. You can create a customized, fully-interactive file tree with as little as one line of JavaScript code.
Currently, server-side connector scripts are available for PHP, ASP, ASP.NET, JSP, and Lasso. If you’re a developer, you can easily make your own connector to work with your language of choice.
Features
- Produces valid, semantic XHTML
- Fully customizable via CSS
- Ability to style icons based on file extension
- Uses AJAX to fetch file information on the fly
- Easy to configure and implement
- Includes connector scripts for PHP and ASP.NET (C#)
- Supports custom connector scripts for extended functionality
- Customizable expand/collapse event
- Customizable expand/collapse speeds
- Supports jQuery easing functions
- Single- and multi-folder views
- Configurable load message
Compatibility
jQuery File Tree works in all browsers supported by jQuery. It has been fully tested in:
- Internet Explorer 6 & 7
- Firefox 2 & 3 (beta)
- Safari 3
- Opera 9
Demo
View a live demonstration of the file tree with various options.
Download
Current version: Version 1.01 (12 April 2008)
Usage
Dependencies
jQuery File Tree requires jQuery 1.2 or above. For easing effects, you will need the jQuery Easing Plugin or another jQuery easing plugin of your choice.
Creating a File Tree
In it’s simplest form, you can create a file tree using the following code:
$('#container_id').fileTree({ root: '/some/folder/' }, function(file) {
alert(file);
});
});
where #container_id is the ID of an empty DIV element that exists on your page. The file tree will automatically load when your page loads.
Configuring the File Tree
Parameters are passed as an object to the fileTree() function. Valid options include:
| Parameter | Description | Default Value |
|---|---|---|
| root | root folder to display | / |
| script | location of the serverside AJAX file to use | jqueryFileTree.php |
| folderEvent | event to trigger expand/collapse | click |
| expandSpeed | Speed at which to expand branches (in milliseconds); use -1 for no animation | 500 |
| collapseSpeed | Speed at which to collapse branches (in milliseconds); use -1 for no animation | 500 |
| expandEasing | Easing function to use on expand | None |
| collapseEasing | Easing function to use on collapse | None |
| multiFolder | Whether or not to limit the browser to one subfolder at a time | true |
| loadMessage | Message to display while initial tree loads (can be HTML) | Loading... |
To create a file tree with multiple parameters, your code will look something like this:
$('#container_id').fileTree({
root: '/some/folder/',
script: 'jqueryFileTree.asp',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: false
}, function(file) {
alert(file);
});
});
Styling the File Tree
The file tree relies 100% on CSS for styling. To give your users an aesthetically pleasing experience, you should either use the included stylesheet for your file tree or create your own. Refer to jqueryFileTree.css to make any changes in the styles.
Handling Feedback
When a file is selected, jQuery File Tree passes the filename back as a string. The easiest way to capture and handle this is by using an anonymous function. If you want to pass the selected filename to a function you create called openFile(), your code will look like this:
// do something with file
}
$(document).ready( function() {
$('#container_id').fileTree({ [options] }, function(file) {
openFile(file);
});
});
Connector Scripts
jQuery File Tree comes with a handful of serverside connector scripts that are used to read the file system on your server and return data to the clientside script via AJAX. The default connector script is jqueryFileTree.php. You can use a connector script for another language by setting the script parameter to the location of the script you want to use (see Configuring the File Tree). Alternatively, you can build a custom connector script to extend the functionality of jQuery File Tree to better suit your needs (see Custom Connector Scripts).
Connector scripts for the following languages are included in the download:
- PHP by Cory S.N. LaViska
- ASP (VBS) by Chazzuka
- ASP.NET (C#) by Andrew Sweeny
- ColdFusion by Tjarko Rikkerink
- JSP by Joshua Gould
- Lasso by Marc Sabourdin
- Lasso by Jason Huck
- Python/Django by Martin Skou
- Ruby by Erik Lax
If you would like to share a connector that you’ve written for another language, let us know! We’ll be happy to add it to the download for everyone to use!
The connector scripts provided with jQuery File Tree are only designed to read information from a specified root folder. Although this is typically harmless, there exists a potential for malicious individuals to be able to view your entire directory structure by spoofing the root parameter. It is highly recommended that you add some form of check to your connector script to verify the path being scanned is a path that you want to allow visitors to see.
Custom Connector Scripts
You can create a custom connector script to extend the functionality of the file tree. The easiest way to do this is probably by modifying one of the scripts supplied in the download. If you want to start from scratch, your script should accept one POST variable (dir) and output an unsorted list in the following format:
<li class="directory collapsed"><a href="#" rel="/this/folder/">Folder Name</a></li>
(additional folders here)
<li class="file ext_txt"><a href="#" rel="/this/folder/filename.txt">filename.txt</a></li>
(additional files here)
</ul>
Note that the corresponding file extension should be written as a class of the li element, prefixed with ext_. (The prefix is used to prevent invalid class names for file extensions that begin with non-alpha characters.)
Version History
1.01
- Updated to work with foreign characters in directory/file names (12 April 2008)
1.00
- Initial release (24 March 2008)
Licensing & Terms of Use
jQuery File Tree is licensed under a Creative Commons License and is copyrighted ©2008 by Cory S.N. LaViska.
Special Thanks
A special thanks goes out to FAMFAMFAM for their excellent Silk Icon Set.


Comments
#1 Floopie on Mar 26th, 2008
#2 Coskun on Mar 27th, 2008
#3 Demetrios Kyriakis on Mar 27th, 2008
#4 Cory S.N. LaViska on Mar 27th, 2008
#5 Ihsan on Mar 27th, 2008
#6 John on Mar 28th, 2008
#7 Cory S.N. LaViska on Mar 28th, 2008
#8 Levi Lewis on Mar 28th, 2008
#9 John on Mar 28th, 2008
#10 Cory S.N. LaViska on Mar 28th, 2008
#11 Kevin on Mar 28th, 2008
#12 bali web designer on Apr 1st, 2008
#13 Bramus! on Apr 1st, 2008
#14 Daniele Di Bernardo on Apr 1st, 2008
#15 decimus on Apr 1st, 2008
#16 mark on Apr 1st, 2008
#17 Daniele Di Bernardo on Apr 2nd, 2008
#18 pavlentij on Apr 4th, 2008
#19 Ignacio on Apr 11th, 2008
#20 Cory S.N. LaViska on Apr 12th, 2008
#21 Ignacio on Apr 14th, 2008
#22 Prakaash on Apr 18th, 2008
#23 Luis on Apr 19th, 2008
#24 Travis Phipps on Apr 21st, 2008
#25 Travis Phipps on Apr 22nd, 2008
#26 Cory S.N. LaViska on Apr 22nd, 2008
#27 kaspar on Apr 22nd, 2008
#28 Travis Phipps on Apr 23rd, 2008
#29 Sabrina on Apr 24th, 2008
#30 Demetrios Kyriakis on May 1st, 2008
#31 Demetrios Kyriakis on May 1st, 2008
#32 adarsh on May 3rd, 2008
#33 Stephen on May 7th, 2008
#34 Ernest on May 7th, 2008
#35 Stephen on May 9th, 2008
#36 Stephen on May 9th, 2008
#37 Matt on May 10th, 2008
#38 Soulhuntre on May 14th, 2008
#39 Mato on May 23rd, 2008
#40 Seth on May 29th, 2008
#41 Dalibor on Jun 4th, 2008
#42 Rp on Jun 4th, 2008
#43 kpo on Jun 4th, 2008
#44 sam on Jun 12th, 2008
#45 Demetrios Kyriakis on Jun 15th, 2008
#46 Rp on Jun 16th, 2008
#47 Vincent on Jun 18th, 2008
#48 Rp on Jun 20th, 2008
#49 Chris on Jun 25th, 2008
#50 Deniz on Jun 26th, 2008
#51 matt on Jul 7th, 2008
#52 Allan on Jul 8th, 2008
#53 Richard van Zon on Jul 9th, 2008
#54 Richard van Zon on Jul 9th, 2008
#55 Allan on Jul 13th, 2008
#56 Allan on Jul 13th, 2008
#57 mogio on Jul 16th, 2008
#58 klima on Jul 17th, 2008
#59 Cherry on Jul 20th, 2008
#60 Felix on Jul 21st, 2008
#61 eugeny on Jul 22nd, 2008
#62 Nick on Jul 30th, 2008
#63 John on Jul 31st, 2008
#64 gab on Jul 31st, 2008
#65 user on Aug 2nd, 2008
#66 Eugeny on Aug 4th, 2008
#67 Cory S.N. LaViska on Aug 4th, 2008
#68 tiffany on Aug 6th, 2008
#69 Cory S.N. LaViska on Aug 6th, 2008
#70 Cory S.N. LaViska on Aug 6th, 2008
#71 tiffany on Aug 7th, 2008
#72 Ju on Aug 12th, 2008
#73 thomas on Aug 18th, 2008
#74 Ross on Aug 19th, 2008
#75 Berkowitz on Aug 21st, 2008
#76 kbrothers on Aug 24th, 2008
#77 Paul Jauregui on Aug 24th, 2008
#78 Rav on Aug 25th, 2008
#79 AddictDownload.com on Aug 26th, 2008
#80 Mike on Aug 27th, 2008
#81 Mike on Aug 27th, 2008