Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new command to the contextual menu and tool bar #257

Closed
dmekala opened this issue Apr 5, 2012 · 8 comments
Closed

Adding a new command to the contextual menu and tool bar #257

dmekala opened this issue Apr 5, 2012 · 8 comments

Comments

@dmekala
Copy link

dmekala commented Apr 5, 2012

In order to use elfinder in my application I would need to create a new command and tie it to a specific action. Is there any documentation available on how to add a new command?

@troex
Copy link
Member

troex commented Apr 5, 2012

The basic scenario - you take one of the commands/buttons from https://github.com/Studio-42/elFinder/tree/2.x/js/commands and redefine it or add your own based on them. extending connector is also not a hard task, just inherit and extend the base classes

@mgamarra
Copy link

I'm try extend the info command (infoextended) and, add a string 'infoextended' in my array of cammands.

var myCommands = elFinder.prototype._options.commands;
myCommands.push('infoextended');
.....
elf = $('#elfinder').elfinder({
commands : myCommands
}).elfinder('instance');

The plugins is initialized but the button is not showed.
Whats wrong?

Att

@giosakti
Copy link

I know this is an old topic, but just want to share some of my experiences adding a new context menu:

  1. Create a new command by duplicating other command behaviour. Mine is: 'commands/ftpsend.js'.
  2. I use these lines to add new command within elfinder context menu:
    // Customize elfinder with new menu
    elFinder.prototype._options.commands.push('ftpsend')
    elFinder.prototype._options.contextmenu.files.push('ftpsend')
    elFinder.prototype.i18.en.messages['cmdftpsend'] = 'Send file using FTP'

@rdinicut
Copy link

To add a custom command you must follow this steps:

  1. add the name of your custom command on document ready
$().ready(function() {
                var elf = $('#elfinder').elfinder({
                    url : 'php/connector.php',
                    commands : [
                        'custom','open', 'reload', 'home', 'up', 'back', 'forward', 'getfile', 'quicklook', 
                        'download', 'rm', 'duplicate', 'rename', 'mkdir', 'mkfile', 'upload', 'copy', 
                        'cut', 'paste', 'edit', 'extract', 'archive', 'search', 'info', 'view', 'help', 'resize', 'sort', 'netmount'
                    ],
                    contextmenu : {
                        // navbarfolder menu
                        navbar : ['open', '|', 'copy', 'cut', 'paste', 'duplicate', '|', 'rm', '|', 'info'],
                        // current directory menu
                        cwd    : ['reload', 'back', '|', 'upload', 'mkdir', 'mkfile', 'paste', '|', 'sort', '|', 'info'],
                        // current directory file menu
                        files  : ['getfile', '|','custom', 'quicklook', '|', 'download', '|', 'copy', 'cut', 'paste', 'duplicate', '|', 'rm', '|', 'edit', 'rename', 'resize', '|', 'archive', 'extract', '|', 'info']
                    },

                }).elfinder('instance');
            });
  1. add the command name your language file :
'cmdcustom'      : 'Custom command',
  1. create a custom command file(you can copy an existing command from source) and include it in your main html
elFinder.prototype.commands.custom= function() {
          this.exec = function(hashes) {
                //implement what the custom command should do here
          }
}
  1. add a css rule for your command. It should be:
.elfinder-button-icon-custom{ //css here }

@troex
Copy link
Member

troex commented Apr 8, 2016

@troex troex closed this as completed Apr 8, 2016
@biswajit-paul
Copy link

Hi,

Can the context menu item be displayed only for selecting one file?

Thanks in advance.

@rdinicut
Copy link

rdinicut commented Feb 8, 2018

Yes you can. Just check the selection length in the getState function of you command and return -1 if you selected multiple files.

this.getstate = function(select) {
	let numberOfSelectedFilesAndFolders = this.files(select).length,
	return numberOfSelectedFilesAndFolders == 1 ? 0 : -1;
};

If you want to filter out folders you can look at the getfile command for inspiration:

filter = function(files) {

@biswajit-paul
Copy link

biswajit-paul commented Feb 9, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants