Home directory for Malawi's wwwroot
Duncan Ewan
2021-02-19 3e758c29e0fde36fc088efcfc88f9a3014432b64
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// 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($){
    
    $.extend($.fn, {
        fileTree: function(o, h) {
            // Defaults
            if( !o ) var o = {};
            if( o.root == undefined ) o.root = 'root';
            if( o.script == undefined ) o.script = 'jqueryFileTree.cfm';
            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 = false;
            if( o.loadMessage == undefined ) o.loadMessage = 'Loading...';
            if( o.expanded == undefined ) o.expanded ='';
            currentnode = "";
            
            $(this).each( function() {
                
            
                currentnode = $(this);
                //currentnode.addClass('nodeclickhighlight');
                hasexpanded = 'false';
                function showTree(c, t) {
                    $(c).addClass('wait');
                    $(".jqueryFileTree.start").remove();
                    $.post(o.script, { dir: unescape(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);
 
 
                 if (o.expanded != null && hasexpanded == 'false') {
                    $(c).find('.directory.collapsed').each(function (i, f) {
                             if ((o.expanded).match($(f).children().attr('rel'))) {
                                showTree($(f), escape($(f).children().attr('rel').match(/.*\//)));
                                $(f).removeClass('collapsed').addClass('expanded');
                                currentnode.removeClass('nodeclickhighlight');
                                currentnode =  $(f).children();
                                currentnode.addClass('nodeclickhighlight');
                                
                              };
                         });
                 }
 
             });
 
             
        }        
                function folderNav(t,flag)
                {
                    var folderlist = (t).find('LI A');
                    var len = (t).find('LI A').length;
                    var x, brkCondition ;
                    if(flag == 1)
                    {
                        x = 0;
                        brkCondition = len -1;
                        if( brkCondition == 0 && $(folderlist[0]).hasClass('nodeclickhighlight'))
                        {
                            $(folderlist[0]).removeClass('nodeclickhighlight');
                            $(folderlist[1]).addClass('nodeclickhighlight');
                        }
                        
                    }
                    else
                    {
                        x = len-1;
                        brkCondition = 0;
                        if( x == 0 && $(folderlist[1]).hasClass('nodeclickhighlight'))
                        {
                            $(folderlist[1]).removeClass('nodeclickhighlight');
                            $(folderlist[0]).addClass('nodeclickhighlight');
                        }
                    }
                    while(x != brkCondition)
                    {
                        if($(folderlist[x]).hasClass('nodeclickhighlight'))
                        {
                            $(folderlist[x]).removeClass('nodeclickhighlight');
                            $(folderlist[(x+flag)]).addClass('nodeclickhighlight');
                            currentnode = $(folderlist[(x+flag)]);
                            break;
                        }
                        x= x+flag;
                    }
                }
                function bindTree(t) {
                    $(document).bind('keydown', function(e) {
                        if(e.keyCode == 40) //downarrowkey
                        {
                            folderNav($(t),1);                
                        }
                        if(e.keyCode == 38) //uparrowkey
                        {
                            folderNav($(t),-1);                
                        }
                        if(e.keyCode == 37) //leftarrowkey
                        {
                            hasexpanded = 'true';
                            if(currentnode.parent().hasClass('directory'))
                            {
                                if(currentnode.parent().hasClass('expanded'))
                                {
                                    currentnode.parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
                                    currentnode.parent().find('UL').remove();
                                    currentnode.parent().removeClass('expanded').addClass('collapsed');
                                }
                                else
                                {                                    
                                    
                                    var folderlist = $(t).find('LI A');
                                    var x = 0;                                    
                                    var len = $(t).find('LI A').length;
                                    while( x < len)
                                    {
                                        if( $(folderlist[x]).attr('rel') == currentnode.attr('rel'))
                                        {        
                                            break;
                                        }
                                        x = x +1;
                                    }
                                    x = x-1;
                                    while(x >= 0)
                                    {
                                        if($(folderlist[x]).parent().hasClass('expanded'))
                                        {
                                            currentnode.removeClass('nodeclickhighlight');
                                            $(folderlist[x]).addClass('nodeclickhighlight');
                                            currentnode = $(folderlist[x]);
                                            break;
                                        }
                                        x= x-1;        
                                    }
                                }    
                            }
                                                        
                        }
                        if(e.keyCode == 39) //rightarrowkey
                        {
                            hasexpanded = 'true';
                            if(currentnode.parent().hasClass('directory'))
                            {
                                if(currentnode.parent().hasClass('collapsed'))
                                {
                                    if( !o.multiFolder ) {
                                        currentnode.parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
                                        currentnode.parent().parent().find('UL').remove();
                                        currentnode.parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed');
                                    }
                                    currentnode.parent().find('UL').remove(); // cleanup
                                    showTree( currentnode.parent(), escape(currentnode.attr('rel').match( /.*\// )) );
                                    currentnode.parent().removeClass('collapsed').addClass('expanded');
                                }
                                else
                                {
                                    folderNav($(t),1);
                                }
                            }
                            
                        }
                        h(currentnode.attr('rel'));    
                        e.stopImmediatePropagation(); 
                        e.preventDefault();
                    });
                    $(t).find('LI A').bind(o.folderEvent, function() {
                         hasexpanded = 'true';
                        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('UL').remove();
                                    $(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().find('UL').remove();
                                $(this).parent().removeClass('expanded').addClass('collapsed');
                            }
                            
                        } else {
                            h($(this).attr('rel'));
                        }
                        if( $(this).attr('rel') != currentnode.attr('rel'))
                        {
                             $(this).addClass('nodeclickhighlight');
                             currentnode.removeClass('nodeclickhighlight');
                             currentnode =$(this) ;
                        }
                        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) );
            });
        }
    });
    
})(jQuery);