Ignore:
Timestamp:
Jun 13, 2014 10:38:13 AM (11 years ago)
Author:
dungnv
Message:
 
File:
1 moved

Legend:

Unmodified
Added
Removed
  • TabularUnified pro-bachkim-filespace/sourcecode/assets/js/vstree.js ΒΆ

    r14 r15  
    241241
    242242                        return this.initialize();
    243                 },
    244 
    245                 violetGrid: function (o) {
    246                         if( !o ) var o = {};
    247                         if( o.container == undefined ) o.container = $(this);
    248                         if( o.defaultViewMode == undefined ) o.defaultViewMode = 'thumbnail';//or 'list'
    249                         if( o.directoryTreeData == undefined ) o.directoryTreeData = null;
    250                         if( o.dirIDprefix == undefined ) o.dirIDprefix = null;
    251                        
    252                         var createNode = function (d) {
    253                                 if( !d ) var d = {};
    254                                 if( d.id == undefined ) d.id = null;
    255                                 if( d.name == undefined ) d.name = null;
    256                                 if( d.minetype == undefined ) d.minetype = 'directory';
    257                                 if( d.parentID == undefined ) d.parentID = null;
    258                                 if( d.clickEvent == undefined ) d.clickEvent = null;
    259                                 if( d.customEvent == undefined ) d.customEvent = null;
    260 
    261                                 var strHTML = '<div class="vscell" rel="id:' + d.id + '">';
    262                                         strHTML += '<div class="selector unselected">';
    263                                         strHTML +=      '<div class="icon-' + d.minetype + '"></div>';
    264                                         strHTML += '</div>';
    265                                         strHTML += '<div class="file-name unselected">' + d.name + '</div>';
    266                                         strHTML += '</div>';
    267                                
    268                                 var disabledItemsList = null;
    269                                
    270                                 if (d.minetype == 'directory') {
    271                                         disabledItemsList = ['preview'];
    272                                 }
    273                                
    274                                 $(o.container).append(strHTML);
    275 
    276                                 $('div[rel="id:'+ d.id +'"]').bind('click',function(e){itemClick(this)});                               
    277                                 $('div[rel="id:'+ d.id +'"]').contextMenu({
    278                                         menu: 'gridMenu',
    279                                         disabledItems: disabledItemsList
    280                                 }, function(action, el, pos) {
    281                                
    282                                         switch(action) {
    283                                                 case 'rename':
    284                                                         itemClick(el);
    285                                                         rename(el);
    286                                                         break;
    287                                                 default:
    288                                                         break;
    289                                         }
    290                                        
    291                                 });
    292                         }
    293                        
    294                         var keyboardRename = function () {
    295                                 $(document).keypress( function(e) {
    296                                         var selectedItem = $('.selector.selected').parent();
    297                                         switch( e.keyCode ) {
    298                                                 case 113:
    299                                                         rename(selectedItem);
    300                                                         break;
    301                                                 default:
    302                                                         break;
    303                                         }
    304                                         return false;
    305                                 });
    306                         }
    307 
    308                         var itemClick = function (i) {
    309                                 $(i).parent().find('.selector').removeClass('selected');
    310                                 $(i).parent().find('.selector').addClass('unselected');
    311                                 $(i).parent().find('.file-name').removeClass('selected');
    312                                 $(i).parent().find('.file-name').addClass('unselected');
    313 
    314                                 $(i).find('.file-name').removeClass('unselected');
    315                                 $(i).find('.file-name').addClass('selected');
    316                                 $(i).find('.selector').removeClass('unselected');
    317                                 $(i).find('.selector').addClass('selected');
    318                         }
    319 
    320                         var renderGrid = function (o) {
    321                                 $(o.container).find ('.vscell').remove();
    322                                
    323                                 var childDir = o.directoryTreeData.DIRECTORIES;
    324                                 var childFile = o.directoryTreeData.FILES;
    325                                 var curentDirID = o.curentParent.substring(o.dirIDprefix.length, o.curentParent.length);
    326                                
    327                                 for (var i = 0 ; i < childDir.length; i++) {
    328                                         if (childDir[i].parentID != curentDirID) continue;
    329                                         createNode ({
    330                                                 id: childDir[i].id,
    331                                                 name: childDir[i].name,
    332                                                 parentID: curentDirID,
    333                                         });
    334                                 }
    335 
    336                                 for (var i = 0 ; i < childFile.length; i++) {
    337                                         if (childFile[i].parentID != curentDirID) continue;
    338                                         createNode ({
    339                                                 id: childFile[i].id,
    340                                                 name: childFile[i].name,
    341                                                 parentID: curentDirID,
    342                                                 minetype: childFile[i].minetype,
    343                                         });
    344                                 }
    345                         }
    346                        
    347                         var rename = function (e) {
    348                                 var nameObj = $(e).find('.file-name');
    349                                 var oldName = $(nameObj).text();
    350                                 var editor = document.createElement ('INPUT');
    351                                 editor.type = 'text';
    352                                 editor.className = 'rename';
    353                                 editor.value = oldName;
    354                                
    355                                 $(nameObj).text('');
    356                                 $(nameObj).append(editor);
    357                                 editor.focus();
    358                                 $(editor).select();
    359                         }
    360                        
    361                         var cancelRename = function () {
    362                                
    363                         }
    364 
    365                         this.getData = function (data) {
    366                                 o.directoryTreeData = data.directoryTreeData;
    367                                 o.curentParent = data.curentParent;
    368                                 o.dirIDprefix = data.dirIDprefix
    369                                 renderGrid(o);
    370                                 keyboardRename();
    371                         }
    372 
    373                         this.initialize = function() {
    374                         return this;
    375                 };
    376 
    377                         return this.initialize();
    378243                }
    379244        });
Note: See TracChangeset for help on using the changeset viewer.