Edit File by line
/home/barbar84/www/wp-conte.../plugins/file-man.../applicat.../library/js/commands
File: getfile.js
/**
[0] Fix | Delete
* @class elFinder command "getfile".
[1] Fix | Delete
* Return selected files info into outer callback.
[2] Fix | Delete
* For use elFinder with wysiwyg editors etc.
[3] Fix | Delete
*
[4] Fix | Delete
* @author Dmitry (dio) Levashov, dio@std42.ru
[5] Fix | Delete
**/
[6] Fix | Delete
(elFinder.prototype.commands.getfile = function() {
[7] Fix | Delete
"use strict";
[8] Fix | Delete
var self = this,
[9] Fix | Delete
fm = this.fm,
[10] Fix | Delete
filter = function(files) {
[11] Fix | Delete
var o = self.options,
[12] Fix | Delete
fres = true;
[13] Fix | Delete
[14] Fix | Delete
files = $.grep(files, function(file) {
[15] Fix | Delete
fres = fres && (file.mime != 'directory' || o.folders) && file.read ? true : false;
[16] Fix | Delete
return fres;
[17] Fix | Delete
});
[18] Fix | Delete
[19] Fix | Delete
return o.multiple || files.length == 1 ? files : [];
[20] Fix | Delete
};
[21] Fix | Delete
[22] Fix | Delete
this.alwaysEnabled = true;
[23] Fix | Delete
this.callback = fm.options.getFileCallback;
[24] Fix | Delete
this._disabled = typeof(this.callback) == 'function';
[25] Fix | Delete
[26] Fix | Delete
this.getstate = function(select) {
[27] Fix | Delete
var sel = this.files(select),
[28] Fix | Delete
cnt = sel.length;
[29] Fix | Delete
[30] Fix | Delete
return this.callback && cnt && filter(sel).length == cnt ? 0 : -1;
[31] Fix | Delete
};
[32] Fix | Delete
[33] Fix | Delete
this.exec = function(hashes) {
[34] Fix | Delete
var fm = this.fm,
[35] Fix | Delete
opts = this.options,
[36] Fix | Delete
files = this.files(hashes),
[37] Fix | Delete
cnt = files.length,
[38] Fix | Delete
url = fm.option('url'),
[39] Fix | Delete
tmb = fm.option('tmbUrl'),
[40] Fix | Delete
dfrd = $.Deferred()
[41] Fix | Delete
.done(function(data) {
[42] Fix | Delete
var res,
[43] Fix | Delete
done = function() {
[44] Fix | Delete
if (opts.oncomplete == 'close') {
[45] Fix | Delete
fm.hide();
[46] Fix | Delete
} else if (opts.oncomplete == 'destroy') {
[47] Fix | Delete
fm.destroy();
[48] Fix | Delete
}
[49] Fix | Delete
},
[50] Fix | Delete
fail = function(error) {
[51] Fix | Delete
if (opts.onerror == 'close') {
[52] Fix | Delete
fm.hide();
[53] Fix | Delete
} else if (opts.onerror == 'destroy') {
[54] Fix | Delete
fm.destroy();
[55] Fix | Delete
} else {
[56] Fix | Delete
error && fm.error(error);
[57] Fix | Delete
}
[58] Fix | Delete
};
[59] Fix | Delete
[60] Fix | Delete
fm.trigger('getfile', {files : data});
[61] Fix | Delete
[62] Fix | Delete
try {
[63] Fix | Delete
res = self.callback(data, fm);
[64] Fix | Delete
} catch(e) {
[65] Fix | Delete
fail(['Error in `getFileCallback`.', e.message]);
[66] Fix | Delete
return;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
if (typeof res === 'object' && typeof res.done === 'function') {
[70] Fix | Delete
res.done(done).fail(fail);
[71] Fix | Delete
} else {
[72] Fix | Delete
done();
[73] Fix | Delete
}
[74] Fix | Delete
}),
[75] Fix | Delete
result = function(file) {
[76] Fix | Delete
return opts.onlyURL
[77] Fix | Delete
? opts.multiple ? $.map(files, function(f) { return f.url; }) : files[0].url
[78] Fix | Delete
: opts.multiple ? files : files[0];
[79] Fix | Delete
},
[80] Fix | Delete
req = [],
[81] Fix | Delete
i, file, dim;
[82] Fix | Delete
[83] Fix | Delete
for (i = 0; i < cnt; i++) {
[84] Fix | Delete
file = files[i];
[85] Fix | Delete
if (file.mime == 'directory' && !opts.folders) {
[86] Fix | Delete
return dfrd.reject();
[87] Fix | Delete
}
[88] Fix | Delete
file.baseUrl = url;
[89] Fix | Delete
if (file.url == '1') {
[90] Fix | Delete
req.push(fm.request({
[91] Fix | Delete
data : {cmd : 'url', target : file.hash},
[92] Fix | Delete
notify : {type : 'url', cnt : 1, hideCnt : true},
[93] Fix | Delete
preventDefault : true
[94] Fix | Delete
})
[95] Fix | Delete
.done(function(data) {
[96] Fix | Delete
if (data.url) {
[97] Fix | Delete
var rfile = fm.file(this.hash);
[98] Fix | Delete
rfile.url = this.url = data.url;
[99] Fix | Delete
}
[100] Fix | Delete
}.bind(file)));
[101] Fix | Delete
} else {
[102] Fix | Delete
file.url = fm.url(file.hash);
[103] Fix | Delete
}
[104] Fix | Delete
if (! opts.onlyURL) {
[105] Fix | Delete
if (opts.getPath) {
[106] Fix | Delete
file.path = fm.path(file.hash);
[107] Fix | Delete
if (file.path === '' && file.phash) {
[108] Fix | Delete
// get parents
[109] Fix | Delete
(function() {
[110] Fix | Delete
var dfd = $.Deferred();
[111] Fix | Delete
req.push(dfd);
[112] Fix | Delete
fm.path(file.hash, false, {})
[113] Fix | Delete
.done(function(path) {
[114] Fix | Delete
file.path = path;
[115] Fix | Delete
})
[116] Fix | Delete
.fail(function() {
[117] Fix | Delete
file.path = '';
[118] Fix | Delete
})
[119] Fix | Delete
.always(function() {
[120] Fix | Delete
dfd.resolve();
[121] Fix | Delete
});
[122] Fix | Delete
})();
[123] Fix | Delete
}
[124] Fix | Delete
}
[125] Fix | Delete
if (file.tmb && file.tmb != 1) {
[126] Fix | Delete
file.tmb = tmb + file.tmb;
[127] Fix | Delete
}
[128] Fix | Delete
if (!file.width && !file.height) {
[129] Fix | Delete
if (file.dim) {
[130] Fix | Delete
dim = file.dim.split('x');
[131] Fix | Delete
file.width = dim[0];
[132] Fix | Delete
file.height = dim[1];
[133] Fix | Delete
} else if (opts.getImgSize && file.mime.indexOf('image') !== -1) {
[134] Fix | Delete
req.push(fm.request({
[135] Fix | Delete
data : {cmd : 'dim', target : file.hash},
[136] Fix | Delete
notify : {type : 'dim', cnt : 1, hideCnt : true},
[137] Fix | Delete
preventDefault : true
[138] Fix | Delete
})
[139] Fix | Delete
.done(function(data) {
[140] Fix | Delete
if (data.dim) {
[141] Fix | Delete
var dim = data.dim.split('x');
[142] Fix | Delete
var rfile = fm.file(this.hash);
[143] Fix | Delete
rfile.width = this.width = dim[0];
[144] Fix | Delete
rfile.height = this.height = dim[1];
[145] Fix | Delete
}
[146] Fix | Delete
}.bind(file)));
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
if (req.length) {
[153] Fix | Delete
$.when.apply(null, req).always(function() {
[154] Fix | Delete
dfrd.resolve(result(files));
[155] Fix | Delete
});
[156] Fix | Delete
return dfrd;
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
return dfrd.resolve(result(files));
[160] Fix | Delete
};
[161] Fix | Delete
[162] Fix | Delete
}).prototype = { forceLoad : true }; // this is required command
[163] Fix | Delete
[164] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function