* @class elFinder command "getfile".
* Return selected files info into outer callback.
* For use elFinder with wysiwyg editors etc.
* @author Dmitry (dio) Levashov, dio@std42.ru
(elFinder.prototype.commands.getfile = function() {
filter = function(files) {
files = $.grep(files, function(file) {
fres = fres && (file.mime != 'directory' || o.folders) && file.read ? true : false;
return o.multiple || files.length == 1 ? files : [];
this.alwaysEnabled = true;
this.callback = fm.options.getFileCallback;
this._disabled = typeof(this.callback) == 'function';
this.getstate = function(select) {
var sel = this.files(select),
return this.callback && cnt && filter(sel).length == cnt ? 0 : -1;
this.exec = function(hashes) {
files = this.files(hashes),
tmb = fm.option('tmbUrl'),
if (opts.oncomplete == 'close') {
} else if (opts.oncomplete == 'destroy') {
if (opts.onerror == 'close') {
} else if (opts.onerror == 'destroy') {
error && fm.error(error);
fm.trigger('getfile', {files : data});
res = self.callback(data, fm);
fail(['Error in `getFileCallback`.', e.message]);
if (typeof res === 'object' && typeof res.done === 'function') {
res.done(done).fail(fail);
result = function(file) {
? opts.multiple ? $.map(files, function(f) { return f.url; }) : files[0].url
: opts.multiple ? files : files[0];
for (i = 0; i < cnt; i++) {
if (file.mime == 'directory' && !opts.folders) {
data : {cmd : 'url', target : file.hash},
notify : {type : 'url', cnt : 1, hideCnt : true},
var rfile = fm.file(this.hash);
rfile.url = this.url = data.url;
file.url = fm.url(file.hash);
file.path = fm.path(file.hash);
if (file.path === '' && file.phash) {
fm.path(file.hash, false, {})
if (file.tmb && file.tmb != 1) {
file.tmb = tmb + file.tmb;
if (!file.width && !file.height) {
dim = file.dim.split('x');
} else if (opts.getImgSize && file.mime.indexOf('image') !== -1) {
data : {cmd : 'dim', target : file.hash},
notify : {type : 'dim', cnt : 1, hideCnt : true},
var dim = data.dim.split('x');
var rfile = fm.file(this.hash);
rfile.width = this.width = dim[0];
rfile.height = this.height = dim[1];
$.when.apply(null, req).always(function() {
dfrd.resolve(result(files));
return dfrd.resolve(result(files));
}).prototype = { forceLoad : true }; // this is required command