Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

work in progress

  • Loading branch information...
commit f98aacd82ff0865fb790e583d9f5ac26aeeb8158 1 parent a8a423a
@jak authored
View
14 connectors/jqueryFileTree.php
@@ -4,7 +4,7 @@
$hideDotFiles = true;
$rootDirectory = './'; // Must have trailing slash
-// Define the path
+// Define the path (via get for web, or command line)
$dir = $_GET['dir'] ? $_GET['dir'] : $argv[1];
// Sanitize user input
@@ -18,6 +18,15 @@
$dir .= DIRECTORY_SEPARATOR;
}
+// Sorting function
+function filelistsort($a, $b) {
+ if ($a['dir'] == $b['dir']) {
+ return strnatcasecmp($a['name'], $b['name']);
+ }
+ if ($a['dir']) return -1;
+ return 1;
+}
+
$dir = $rootDirectory . $dir;
if (is_dir($dir)) {
@@ -30,10 +39,11 @@
$entry = array(
'name' => $name,
'dir' => is_dir($dir . $name)
- );
+ );
$results[] = $entry;
}
+ usort($results, 'filelistsort');
echo json_encode($results);
} else {
// If the parameter is not a directory, die.
View
2  jqueryFileTree.css
@@ -26,7 +26,7 @@ UL.jqueryFileTree A:hover {
}
/* Core Styles */
-.jqueryFileTree LI.directory { background: url(images/directory.png) left top no-repeat; }
+.jqueryFileTree LI.dir { background: url(images/directory.png) left top no-repeat; }
.jqueryFileTree LI.expanded { background: url(images/folder_open.png) left top no-repeat; }
.jqueryFileTree LI.file { background: url(images/file.png) left top no-repeat; }
.jqueryFileTree LI.wait { background: url(images/spinner.gif) left top no-repeat; }
View
110 jqueryFileTree.js
@@ -1,93 +1,37 @@
// jQuery File Tree Plugin
//
-// Version 1.01
-//
-// Cory S.N. LaViska
-// A Beautiful Site (http://abeautifulsite.net/)
-// 24 March 2008
-//
-// Visit http://abeautifulsite.net/notebook.php?article=58 for more information
-//
-// Usage: $('.fileTreeDemo').fileTree( options, callback )
-//
-// Options: root - root folder to display; default = /
-// script - location of the serverside AJAX file to use; default = jqueryFileTree.php
-// folderEvent - event to trigger expand/collapse; default = click
-// expandSpeed - default = 500 (ms); use -1 for no animation
-// collapseSpeed - default = 500 (ms); use -1 for no animation
-// expandEasing - easing function to use on expand (optional)
-// collapseEasing - easing function to use on collapse (optional)
-// multiFolder - whether or not to limit the browser to one subfolder at a time
-// loadMessage - Message to display while initial tree loads (can be HTML)
-//
-// History:
-//
-// 1.01 - updated to work with foreign characters in directory/file names (12 April 2008)
-// 1.00 - released (24 March 2008)
-//
-// TERMS OF USE
-//
-// This plugin is dual-licensed under the GNU General Public License and the MIT License and
-// is copyright 2008 A Beautiful Site, LLC.
-//
-if(jQuery) (function($){
+
+if (jQuery) (function($){
$.extend($.fn, {
- fileTree: function(o, h) {
+ fileTree: function(options, callback) {
// Defaults
- if( !o ) var o = {};
- if( o.root == undefined ) o.root = '/';
- if( o.script == undefined ) o.script = 'jqueryFileTree.php';
- if( o.folderEvent == undefined ) o.folderEvent = 'click';
- if( o.expandSpeed == undefined ) o.expandSpeed= 500;
- if( o.collapseSpeed == undefined ) o.collapseSpeed= 500;
- if( o.expandEasing == undefined ) o.expandEasing = null;
- if( o.collapseEasing == undefined ) o.collapseEasing = null;
- if( o.multiFolder == undefined ) o.multiFolder = true;
- if( o.loadMessage == undefined ) o.loadMessage = 'Loading...';
+ var defaults = {
+ script: 'jqueryFileTree.php',
+ root: '/',
+ loadingMessage: 'Loading...'
+ };
+ // Expand the defaults with the supplied options
+ options = $.extend(defaults, options);
- $(this).each( function() {
-
- function showTree(c, t) {
- $(c).addClass('wait');
- $(".jqueryFileTree.start").remove();
- $.post(o.script, { dir: t }, function(data) {
- $(c).find('.start').html('');
- $(c).removeClass('wait').append(data);
- if( o.root == t ) $(c).find('UL:hidden').show(); else $(c).find('UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing });
- bindTree(c);
- });
- }
+ $(this).each(function() {
+ var $this = $(this);
+
+ $this.html('<ul class="jqueryFileTree start"><li class="wait">' + options.loadingMessage + '<li></ul>');
- function bindTree(t) {
- $(t).find('LI A').bind(o.folderEvent, function() {
- if( $(this).parent().hasClass('directory') ) {
- if( $(this).parent().hasClass('collapsed') ) {
- // Expand
- if( !o.multiFolder ) {
- $(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
- $(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed');
- }
- $(this).parent().find('UL').remove(); // cleanup
- showTree( $(this).parent(), escape($(this).attr('rel').match( /.*\// )) );
- $(this).parent().removeClass('collapsed').addClass('expanded');
- } else {
- // Collapse
- $(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
- $(this).parent().removeClass('expanded').addClass('collapsed');
- }
- } else {
- h($(this).attr('rel'));
- }
- return false;
- });
- // Prevent A from triggering the # on non-click events
- if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return false; });
- }
- // Loading message
- $(this).html('<ul class="jqueryFileTree start"><li class="wait">' + o.loadMessage + '<li></ul>');
- // Get the initial file list
- showTree( $(this), escape(o.root) );
+ $.get(options.script, {dir: 'nothingyet'}, function (data) {
+ var listHtml = '';
+ for (var i in data) {
+ if (data.hasOwnProperty(i)) {
+ var item = data[i],
+ classHtml = (item.dir?' class="dir"':'');
+ console.log(item);
+ listHtml += '<li' + classHtml + '>' + item.name + '</li>';
+ console.log(listHtml);
+ }
+ };
+ $this.find('.start').html(listHtml);
+ }, 'json');
});
}
});
View
23 test.html
@@ -0,0 +1,23 @@
+<html>
+<head>
+<link rel="stylesheet" href="jqueryFileTree.css" />
+</head>
+<body>
+
+<h1>Demo page</h1>
+
+<div id="a">
+</div>
+
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
+<script src="jqueryFileTree.js" type="text/javascript"></script>
+<script type="text/javascript">
+$(document).ready(function () {
+ $("#a").fileTree({
+ script: 'test.json'
+ });
+ console.log('hi');
+});
+</script>
+</body>
+</html>
View
1  test.json
@@ -0,0 +1 @@
+[{"name":"connectors","dir":true},{"name":"images","dir":true},{"name":"jqueryFileTree.css","dir":false},{"name":"jqueryFileTree.js","dir":false},{"name":"README.md","dir":false},{"name":"test.html","dir":false},{"name":"test.json","dir":false}]
Please sign in to comment.
Something went wrong with that request. Please try again.