1 | if(jQuery) (function($){
|
---|
2 |
|
---|
3 | $.extend($.fn, {
|
---|
4 | violetTree: function(o) {
|
---|
5 | var loadedNode = null;
|
---|
6 |
|
---|
7 | if( !o ) var o = {};
|
---|
8 | if( o.user == undefined ) o.user = null;
|
---|
9 | if( o.homeDirNameDisplay == undefined ) o.homeDirNameDisplay = 'Home';
|
---|
10 | if( o.script == undefined ) o.script = null;
|
---|
11 | if( o.dataSource == undefined ) o.dataSource = 'AJAX'; //'LOADED'
|
---|
12 | if( o.data == undefined ) o.data = null;
|
---|
13 | if( o.container == undefined ) o.container = $(this);
|
---|
14 | if( o.dirIDprefix == undefined ) o.dirIDprefix = 'vsdir_';
|
---|
15 |
|
---|
16 | if( o.expandSpeed == undefined ) o.expandSpeed= 500;
|
---|
17 | if( o.collapseSpeed == undefined ) o.collapseSpeed= 500;
|
---|
18 | if( o.expandEasing == undefined ) o.expandEasing = null;
|
---|
19 | if( o.collapseEasing == undefined ) o.collapseEasing = null;
|
---|
20 |
|
---|
21 | $(this).each( function() {
|
---|
22 | function loadTree() {
|
---|
23 | if (o.dataSource == 'AJAX') {
|
---|
24 | $.post(o.script,
|
---|
25 | function(data){
|
---|
26 | if (!data) return;
|
---|
27 | var parsedData = $.parseJSON(data);
|
---|
28 | o.data = parsedData;
|
---|
29 | renderTree ();
|
---|
30 | }
|
---|
31 | )
|
---|
32 | .done(function() {
|
---|
33 | //alert( "second success" );
|
---|
34 | })
|
---|
35 | .fail(function() {
|
---|
36 | //alert( "error" );
|
---|
37 | })
|
---|
38 | .always(function() {
|
---|
39 | //alert( "finished" );
|
---|
40 | });
|
---|
41 | }
|
---|
42 | };
|
---|
43 |
|
---|
44 | function renderTree () {
|
---|
45 | $(o.container).click(function(){return false;}).mousedown(function(){return false;});
|
---|
46 | $(o.container).bind("contextmenu",function(e){e.preventDefault();});
|
---|
47 |
|
---|
48 | //Home directory
|
---|
49 | strHTML = '<ul class="jqueryFileTree"><li id="' + o.dirIDprefix + 0 + '" class="home"><a href="#" rel="spacehome">' + o.homeDirNameDisplay + '</a></li></ul>';
|
---|
50 | $(o.container).append(strHTML);
|
---|
51 | $('#' + o.dirIDprefix + 0).find('a').click(function(){return false;}).mousedown(function(){return false;});
|
---|
52 | $('#' + o.dirIDprefix + 0).find('a').bind("contextmenu",function(e){
|
---|
53 | e.preventDefault();
|
---|
54 | showContextMenu (this);
|
---|
55 | });
|
---|
56 |
|
---|
57 | if (o.data != null) {
|
---|
58 | for (var i = 0; i < o.data.length ; i++) {
|
---|
59 | strHTML = '<ul class="jqueryFileTree"><li id="' + o.dirIDprefix + o.data[i].id + '" class="directory collapsed"><a href="#" rel="' + o.data[i].name + '">' + o.data[i].name + '</a></li></ul>';
|
---|
60 |
|
---|
61 | if (o.data[i].parentID > 0){
|
---|
62 | $('#' + o.dirIDprefix + o.data[i].parentID).append(strHTML);
|
---|
63 | $('#' + o.dirIDprefix + o.data[i].id).parent().css('display','none');
|
---|
64 | }
|
---|
65 | else {
|
---|
66 |
|
---|
67 | $('#' + o.dirIDprefix + 0).append(strHTML);
|
---|
68 | }
|
---|
69 |
|
---|
70 | $('#' + o.dirIDprefix + o.data[i].id).find('a').click(function(){openDir(this);return false;}).mousedown(function(){return false;});
|
---|
71 | $('#' + o.dirIDprefix + o.data[i].id).find('a').bind("contextmenu",function(e){
|
---|
72 | e.preventDefault();
|
---|
73 | showContextMenu (this);
|
---|
74 | });
|
---|
75 | };
|
---|
76 | }
|
---|
77 | };
|
---|
78 |
|
---|
79 | function openDir (o) {
|
---|
80 | if( $(o).parent().hasClass('collapsed') ) {
|
---|
81 | $(o).parent().find('> UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing });
|
---|
82 | $(o).parent().removeClass('collapsed').addClass('expanded');
|
---|
83 | }
|
---|
84 | else if( $(o).parent().hasClass('expanded') ) {
|
---|
85 | $(o).parent().find('> UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
|
---|
86 | $(o).parent().removeClass('expanded').addClass('collapsed');
|
---|
87 | }
|
---|
88 | selectDir(o);
|
---|
89 | }
|
---|
90 |
|
---|
91 | function selectDir(o) {
|
---|
92 | $('.currentDir').removeClass('currentDir');
|
---|
93 | $(o).addClass('currentDir');
|
---|
94 | }
|
---|
95 |
|
---|
96 | function showContextMenu (n) {
|
---|
97 | alert ('showContextMenu on ' + $(n).text());
|
---|
98 | };
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | loadTree();
|
---|
103 | });
|
---|
104 |
|
---|
105 | this.expandAll = function() {
|
---|
106 | $(o.container).find('UL:hidden').slideDown({ duration: o.expandSpeed, easing: o.expandEasing });
|
---|
107 | };
|
---|
108 |
|
---|
109 | this.getCurrentDir = function() {
|
---|
110 | return $(o.container).find('.currentDir').attr('rel');
|
---|
111 | };
|
---|
112 |
|
---|
113 | this.createDir = function() {
|
---|
114 | /**
|
---|
115 | * 1. Send request create directory to server
|
---|
116 | * 2. Get ID of new directory from server
|
---|
117 | * 3. Create node of tree
|
---|
118 | */
|
---|
119 |
|
---|
120 |
|
---|
121 | $.post(o.script,{action:"create_dir",parentID:pid}, function (data) {
|
---|
122 |
|
---|
123 | });
|
---|
124 | }
|
---|
125 |
|
---|
126 | this.initialize = function() {
|
---|
127 | return this;
|
---|
128 | };
|
---|
129 |
|
---|
130 | return this.initialize();
|
---|
131 | },
|
---|
132 |
|
---|
133 |
|
---|
134 | /*violetGrid: function(o, h) {
|
---|
135 |
|
---|
136 | }*/
|
---|
137 | });
|
---|
138 |
|
---|
139 | })(jQuery); |
---|