@@ -374,35 +374,43 @@ elFinder.prototype.commands.rm = function() {
374374 this . value = 'rm' ;
375375
376376 this . init = function ( ) {
377- // re-assign for extended command
378- self = this ;
379- fm = this . fm ;
380- // bind function of change
381- self . change ( function ( ) {
377+ var update = function ( origin ) {
382378 var targets ;
383379 delete self . extra ;
384380 self . title = fm . i18n ( 'cmd' + self . value ) ;
385381 self . className = self . value ;
386382 self . button && self . button . children ( 'span.elfinder-button-icon' ) [ self . value === 'trash' ? 'addClass' : 'removeClass' ] ( 'elfinder-button-icon-trash' ) ;
387- if ( self . value === 'trash' ) {
388- self . extra = {
389- icon : 'rm' ,
390- node : $ ( '<span></span>' )
391- . attr ( { title : fm . i18n ( 'cmdrm' ) } )
392- . on ( 'ready' , function ( e , data ) {
393- targets = data . targets ;
394- } )
395- . on ( 'click touchstart' , function ( e ) {
396- if ( e . type === 'touchstart' && e . originalEvent . touches . length > 1 ) {
397- return ;
398- }
399- e . stopPropagation ( ) ;
400- e . preventDefault ( ) ;
401- fm . getUI ( ) . trigger ( 'click' ) ; // to close the context menu immediately
402- fm . exec ( 'rm' , targets , { _userAction : true , forceRm : true } ) ;
403- } )
404- } ;
383+ if ( origin && origin !== 'cwd' && ( self . state > - 1 || origin === 'navbar' ) ) {
384+ if ( self . value === 'trash' ) {
385+ self . extra = {
386+ icon : 'rm' ,
387+ node : $ ( '<span></span>' )
388+ . attr ( { title : fm . i18n ( 'cmdrm' ) } )
389+ . on ( 'ready' , function ( e , data ) {
390+ targets = data . targets ;
391+ } )
392+ . on ( 'click touchstart' , function ( e ) {
393+ if ( e . type === 'touchstart' && e . originalEvent . touches . length > 1 ) {
394+ return ;
395+ }
396+ e . stopPropagation ( ) ;
397+ e . preventDefault ( ) ;
398+ fm . getUI ( ) . trigger ( 'click' ) ; // to close the context menu immediately
399+ fm . exec ( 'rm' , targets , { _userAction : true , forceRm : true } ) ;
400+ } )
401+ } ;
402+ }
405403 }
404+ } ;
405+ // re-assign for extended command
406+ self = this ;
407+ fm = this . fm ;
408+ // bind function of change
409+ self . change ( function ( ) {
410+ update ( ) ;
411+ } ) ;
412+ fm . bind ( 'contextmenucreate' , function ( e ) {
413+ update ( e . data . type ) ;
406414 } ) ;
407415 } ;
408416
0 commit comments