source: pro-bachkim-filespace/sourcecode/assets/js/grid.js @ 69

Last change on this file since 69 was 66, checked in by dungnv, 11 years ago
  • Property svn:mime-type set to text/plain
File size: 4.4 KB
Line 
1if(jQuery) (function($){
2        $.extend($.fn, {
3                violetGrid : function (o) {
4                        if( !o ) var o = {};
5                        if( o.data == undefined ) o.data = null;
6                        if( o.draggable == undefined ) o.draggable = false;
7                        if( o.manager ==  undefined) o.manager = null;
8                       
9                        var oContainer = this;
10                       
11                        var createNode = function (node) {
12                                if( !node ) var node = {};
13                                if( node.item == undefined ) node.item = null; //item.id, item.name, item.parentID
14                                if( node.isDirectory == undefined ) node.isDirectory = false;
15                                if( node.showContextMenu == undefined ) node.showContextMenu = true;
16                               
17                                var icon = (node.item.minetype != undefined) ? 'icon-' + node.item.minetype: 'icon-directory';
18                                var type = (node.item.minetype != undefined) ? node.item.minetype: 'directory';
19                                var div = $('<div></div>',{'class':icon});
20                               
21                                var inputID = $('<input />',{'class':'id', type:'hidden',value:node.item.id});
22                                var inputName = $('<input />',{'class':'name',type:'hidden',value:node.item.name});
23                                var inputType = $('<input />',{'class':'type',type:'hidden',value:type});
24                               
25                                var a = $('<a></a>',{id: node.item.id,href: '#',rel: node.item.name,text: node.item.name});
26                                var divLink = $('<div></div>',{'class':'file-name'}).append(a,inputID,inputName,inputType);
27                                var li = $('<li></li>',{'class':'vscell'}).append(div, divLink);
28                               
29                                bindNodeEvents(li);
30                               
31                                return li;
32                        }
33                       
34                        var bindNodeEvents = function (node) {
35                                $(node).bind("click", function (e){
36                                        if(e.button == 0)nodeClick(this,e);return false;});
37                        }
38                       
39                        var nodeClick = function (node, event) {
40                                if (event.ctrlKey) {
41                                        if (!isHightLight(node))
42                                                hightlightNode(node);
43                                        else
44                                                clearHightLightNode(node);
45                                }
46                                else if (event.shiftKey) {
47                                        var firstItem = $(oContainer).find('> UL > LI > DIV[class^="icon-"][class$="selected"]:first-child').parent();
48                                        var aryNode = $(oContainer).find('> UL > LI > DIV[class^="icon-"]').parent();
49                                        var start = aryNode.index(firstItem);
50                                        var finish = aryNode.index(node);
51                                        aryNode.slice(Math.min(start, finish), Math.max(start, finish) + 1).each( function (i,o){hightlightNode(o);});
52                                }
53                                else {
54                                        clearAllHightLightNode(node);
55                                        hightlightNode(node);
56                                }
57                        }
58                       
59                        var nodeDblClick = function (node) {
60                               
61                        }
62                       
63                        var hightlightNode = function (node) {
64                                $(node).find('> DIV').addClass('selected');
65                        }
66                       
67                        var isHightLight = function (node) {
68                                return $(node).find('> DIV').hasClass('selected');
69                        }
70                       
71                        var clearAllHightLightNode = function () {
72                                $(oContainer).find('> UL > LI > DIV').removeClass('selected');
73                        }
74                       
75                        var clearHightLightNode = function (node) {
76                                $(node).find('> DIV').removeClass('selected');
77                        }
78                       
79                        var initGrid = function () {
80                                var ul = $('<ul></ul>',{'class':'vsgrid'});
81                                var parentDirID = o.manager.getTreeCurrentNode();
82                                if (o.data.DIRECTORIES.length > 0) {
83                                        for (var i = 0; i < o.data.DIRECTORIES.length; i++) {
84                                                if (o.data.DIRECTORIES[i].parentID == parentDirID) {
85                                                        var li = createNode ({item: o.data.DIRECTORIES[i]});
86                                                        $(ul).append(li);
87                                                }
88                                        }
89                                }
90                               
91                                if (o.data.FILES.length > 0) {
92                                        for (var i = 0; i < o.data.FILES.length; i++) {
93                                                if (o.data.FILES[i].parentID == parentDirID) {
94                                                        var li = createNode ({item: o.data.FILES[i]});
95                                                        $(ul).append(li);
96                                                }
97                                        }
98                                }
99                               
100                                $(oContainer).find ('UL').remove();
101                                $(oContainer).append(ul);
102                               
103                                $(oContainer).attr('unselectable','on')
104                             .css({'-moz-user-select':'-moz-none',
105                                   '-moz-user-select':'none',
106                                   '-o-user-select':'none',
107                                   '-khtml-user-select':'none',
108                                   '-webkit-user-select':'none',
109                                   '-ms-user-select':'none',
110                                   'user-select':'none'
111                             }).bind('selectstart', function(){ return false;
112                             }).bind('click', function(){ clearAllHightLightNode(); return false; });
113                        }
114                       
115                        this.reloadGrid = function (nodeID) {
116                                initGrid();
117                        }
118                       
119                        this.setData = function (data) {
120                                o.data = data;
121                        }
122                       
123                        this.rename = function (item) {
124                                console.log('rename');
125                                console.log(item);
126                        }
127                       
128                        this.deletion = function (id) {
129                               
130                        }
131                       
132                        this.initialize = function () {
133                                initGrid();
134                                return this;
135                        };
136                       
137                        return this.initialize();
138                }
139        });
140})(jQuery);
Note: See TracBrowser for help on using the repository browser.