PageSourceSearch

https://manorschool.northants.sch.uk/components/com_dropfiles/assets/js/jaofoldertree.js

js manorschool.northants.sch.uk collected 2026-10-09 18:28:43 UTC 9,302 bytes, 230 lines download raw bytes

1// jQuery File Tree Plugin
2//
3// Version 1.0
4//
5// Base on the work of Cory S.N. LaViska  A Beautiful Site (http://abeautifulsite.net/)
6// Dual-licensed under the GNU General Public License and the MIT License
7// Icons from famfamfam silk icon set thanks to http://www.famfamfam.com/lab/icons/silk/
8//
9// Usage : $('#jao').jaofoldertree(options);
10//
11// Author: Damien Barrère
12// Website: http://www.crac-design.com
13
14(function( $ ) {
15  
16    var options =  {
17      'root'            : '/',
18      'script'          : 'connectors/jaoconnector.php',
19      'showroot'        : 'root',
20      'onclick'         : function(elem,type,file){},
21      'oncheck'         : function(elem,checked,type,file){},
22      'onChanges'       : function(folderTree, newFolders){},
23      'usecheckboxes'   : true, // Can be true files dirs or false
24      'expandSpeed'     : 500,
25      'collapseSpeed'   : 500,
26      'expandEasing'    : null,
27      'collapseEasing'  : null,
28      'canselect'       : true
29    };
30
31    var newFolders = [];
32
33    var methods = {
34        init : function( o ) {
35            if($(this).length==0){
36                return;
37            }
38            $this = $(this);
39            $.extend(options,o);
40            $(this).data('jaofoldertree', $.extend({}, options));
41            if(options.showroot!=''){
42
43                $this.html('<ul class="jaofoldertree">
43<li class="drive directory collapsed selected">' +
44                    '<div class="icon-open-close" data-id="'+options.root+'" data-parent_id="0" data-file="'+options.root+'"></div>'
45                    +'<i class="zmdi zmdi-folder dropfiles-folder"></i><a class="catlinks" href="#" data-file="'+options.root+'" data-type="dir">'+options.showroot+'</a></li></ul>');
46            }else {
47                $this.html('<ul class="jaofoldertree"><li class="drive directory collapsed selected">' +
48                    '<div class="icon-open-close" ></div>'
49                    +'<a class="catlinks" href="#" data-file="'+options.root+'" data-type="dir"><i class="zmdi zmdi-folder dropfiles-folder"></i></a></li></ul>');
50            }
51            openfolder(options.root, $this);
52        },
53        open : function(dir, $this){
54            openfolder(dir, $this);
55        },
56        close : function(dir, $this){
57            closedir(dir, $this);
58        },
59        getchecked : function(){
60            var list = new Array();            
61            var ik = 0;
62            $this.find('input:checked + a').each(function(){
63                list[ik] = {
64                    type : $(this).attr('data-type'),
65                    file : $(this).attr('data-file')
66                }                
67                ik++;
68            });
69	    return list;
70        },
71        getselected : function(){
72            var list = new Array();            
73            var ik = 0;
74            $this.find('li.selected > a').each(function(){
75                list[ik] = {
76                    type : $(this).attr('data-type'),
77                    file : $(this).attr('data-file')
78                }                
79                ik++;
80            });
81	    return list;
82        }
83    };
84
85    openfolder = function(dir, $this) {
86        if (typeof ($this) === "undefined") {
87            return false;
88        }
89	    if($this.find('a[data-file="'+dir+'"]').parent().hasClass('expanded')) {
90		    return;
91	    }
92            var ret;
93            ret = $.ajax({
94                url : options.script,
95                data : {id : dir},
96                context : $this,
97		        dataType: 'json',
98                beforeSend : function(){this.find('a[data-file="'+dir+'"]').parent().addClass('wait');}
99            }).done(function(datas) {
100                ret = '<ul class="jaofoldertree" style="display: none">';
101                for(ij=0; ij<datas.length; ij++){
102                    classe = 'directory collapsed';                                         
103                    ret += '<li class="'+classe+'">';
104                    if(datas[ij].count_child > 0){
105                        ret += '<div class="icon-open-close" data-id="' + datas[ij].id + '" data-parent_id="' + datas[ij].parent_id + '" data-file="' +datas[ij].id + '" ></div>';
106                    }else{
107                        ret += '<div class="icon-open-close no-child" data-id="' + datas[ij].id + '" data-parent_id="' + datas[ij].parent_id + '" data-file="' +datas[ij].id + '" ></div>';
108                    }
109                    selectedId = dir;
110                    if(datas[ij].id === selectedId.toString()) {
111                            ret += '<i class="zmdi zmdi-folder zmdi-folder"></i></i>';
112                    }else {
113                            ret += '<i class="zmdi zmdi-folder dropfiles-folder"></i>';
114                    }
115                    
116                    ret += '<a href="#" data-file="'+datas[ij].id+'" >'+datas[ij].title+'</a>';
117                    ret += '</li>';
118                }
119                ret += '</ul>';
120
121                this.find('a[data-file="'+dir+'"]').parent().removeClass('wait').removeClass('collapsed').addClass('expanded');
122                if (datas.length) {
123                    this.find('a[data-file="'+dir+'"]').after(ret);
124                }
125                this.find('a[data-file="'+dir+'"]').next().slideDown(options.expandSpeed,options.expandEasing);
126                newFolders = datas;
127                setevents($this);
128            }).done(function(){
129                //Trigger custom event
130                $this.trigger('afteropen');
131                $this.trigger('afterupdate');
132            });
133    };
134
135    closedir = function(dir, $this) {
136        if (typeof ($this) === "undefined") {
137            return false;
138        }
139
140        $this.find('a[data-file="'+dir+'"]').next().slideUp(options.collapseSpeed,options.collapseEasing,function(){$(this).remove();});
141        $this.find('a[data-file="'+dir+'"]').parent().removeClass('expanded').addClass('collapsed');
142        setevents($this);
143
144        //Trigger custom event
145        $this.trigger('afterclose');
146        $this.trigger('afterupdate');
147    };
148
149    setevents = function($this){
150        var options = $this.data('jaofoldertree');
151        $this.find('li a, li .icon-open-close').unbind('click');
152
153        options.onChanges($this, newFolders);
154        newFolders = [];
155
156        //Bind userdefined function on click an element
157        $this.find('li.directory a').bind('click', function(e) {
158            $this.find('li').removeClass('selected');
159            $this.find('i.zmdi').removeClass('zmdi-folder').addClass("zmdi-folder");
160            $(this).parent().addClass('selected');
161            $(this).parent().find(' > i.zmdi').addClass("zmdi-folder");
162            var $el = $(this);
163            if($el.data('clicked')){
164                // Previously clicked, stop actions
165                e.preventDefault();
166                e.stopPropagation();
167            }else{
168                // Mark to ignore next click
169                $el.data('clicked', true);
170                options.onclick(this, $(this).attr('data-file'));
171                // Unmark after 1 second
172                window.setTimeout(function(){
173                    $el.removeData('clicked');
174                }, 1000)
175            }
176            return false;
177        });
178      
179        //Bind for collapse or expand elements
180        //$this.find('li.directory.collapsed a').bind('click', function() {methods.open($(this).attr('data-file'));return false;});
181       // $this.find('li.directory.expanded a').bind('click', function() {methods.close($(this).attr('data-file'));return false;});
182
183        $this.find('li.directory.collapsed .icon-open-close').bind('click', function (e) {
184            e.preventDefault;
185            var $el = $(this);
186            if($el.data('clicked')){
187                // Previously clicked, stop actions
188                e.preventDefault();
189                e.stopPropagation();
190            }else{
191                // Mark to ignore next click
192                $el.data('clicked', true);
193                methods.open($(this).attr('data-file'), $this);
194                // Unmark after 1 second
195                window.setTimeout(function(){
196                    $el.removeData('clicked');
197                }, 1000)
198            }
199        });
200
201        $this.find('li.directory.expanded .icon-open-close').bind('click', function (e) {
202            e.preventDefault;
203            var $el = $(this);
204            if($el.data('clicked')){
205                // Previously clicked, stop actions
206                e.preventDefault();
207                e.stopPropagation();
208            }else{
209                // Mark to ignore next click
210                $el.data('clicked', true);
211                methods.close($(this).attr('data-file'), $this);
212                // Unmark after 1 second
213                window.setTimeout(function(){
214                    $el.removeData('clicked');
215                }, 1000)
216            }
217        });
218    }
219
220    $.fn.jaofoldertree = function( method ) {
221        // Method calling logic
222        if ( methods[method] ) {
223            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
224        } else if ( typeof method === 'object' || ! method ) {
225            return methods.init.apply( this, arguments );
226        } else {
227            //error
228        }    
229  };
230})( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.