- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjqueryFileTree.js
More file actions
Latest commit
105 lines (103 loc) · 4.22 KB
/
Copy pathjqueryFileTree.js
File metadata and controls
105 lines (103 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// jQuery File Tree Plugin
//
// Version 1.02, 30 March 2013
//
// Cory S.N. LaVisk, A Beautiful Site (http://abeautifulsite.net/) and others
//
// 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 = 200 (ms); use -1 for no animation
// collapseSpeed - default = 200 (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)
// initialFolder - Folder to be expanded initially
//
// History:
//
// 1.02 - support for initially expanded folder (initialFolder) (30 March 2013), erevilla@tangrambpm.es
// 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($){
$.extend($.fn,{
fileTree: function(o,h){
// Defaults
if(!o)varo={};
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=200;
if(o.collapseSpeed==undefined)o.collapseSpeed=200;
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...';
if(o.initialFolder==undefined)o.initialFolder='';
varcurPath='';
varpaths=o.initialFolder.split('/');
$(this).each(function(){
functionshowTree(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);
// open initial folder
if(paths!=[]){
varpath=paths[0];
paths.shift();
if(path){
path+='/';
curPath+=path;
$(c).find('A[rel="'+curPath+'"]').click();
}
}
});
}
functionbindTree(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'));
}
returnfalse;
});
// Prevent A from triggering the # on non-click events
if(o.folderEvent.toLowerCase!='click')$(t).find('LI A').bind('click',function(){returnfalse;});
}
// 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));
});
}
});
})(jQuery);