Skip to content

Commit

Permalink
[js:core] fix #2403 backward compatibility with API 2.0 is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Feb 26, 2018
1 parent fb2995a commit dc6da9e
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions js/elFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,12 +1355,12 @@ var elFinder = function(elm, opts, bootCallback) {
* @return mixed
*/
this.option = function(name, target) {
var res;
var res, item;
target = target || cwd;
if (self.optionsByHashes[target] && typeof self.optionsByHashes[target][name] !== 'undefined') {
return self.optionsByHashes[target][name];
}
if (cwd !== target) {
if (self.hasVolOptions && cwd !== target && (!(item = self.file(target)) || item.phash !== cwd)) {
res = '';
$.each(self.volOptions, function(id, opt) {
if (target.indexOf(id) === 0) {
Expand Down Expand Up @@ -1557,7 +1557,7 @@ var elFinder = function(elm, opts, bootCallback) {
return file.url;
}

baseUrl = (file.hash.indexOf(self.cwd().volumeid) === 0)? cwdOptions.url : self.option('url', file.hash);
baseUrl = self.option('url', file.phash || file.hash);

if (baseUrl) {
return baseUrl + $.map(self.path2array(hash), function(n) { return encodeURIComponent(n); }).slice(1).join('/');
Expand Down Expand Up @@ -1946,11 +1946,12 @@ var elFinder = function(elm, opts, bootCallback) {
// Set currrent request command name
self.currentReqCmd = cmd;

if (response.debug && (!d || (d !== 'all' && !d['backend-error']))) {
if (response.debug && (!d || d !== 'all')) {
if (!d) {
self.options.debug = {};
d = self.options.debug = {};
}
self.options.debug['backend-error'] = true;
d['backend-error'] = true;
d['warning'] = true;
}

if (raw) {
Expand Down Expand Up @@ -3805,6 +3806,13 @@ var elFinder = function(elm, opts, bootCallback) {
*/
this.volOptions = {};

/**
* Has volOptions data
*
* @type Boolean
*/
this.hasVolOptions = false;

/**
* Hash of trash holders
* key: trash folder hash
Expand Down Expand Up @@ -6798,7 +6806,7 @@ elFinder.prototype = {
vid, targetOptions, isRoot;

if (file && file.hash && file.name && file.mime) {
if (file.mime == 'application/x-empty') {
if (file.mime === 'application/x-empty') {
file.mime = 'text/plain';
}

Expand All @@ -6824,6 +6832,7 @@ elFinder.prototype = {
vid = file.volumeid;

if (isRoot) {
self.hasVolOptions = true;
if (! self.volOptions[vid]) {
self.volOptions[vid] = {
// set dispInlineRegex
Expand All @@ -6846,6 +6855,11 @@ elFinder.prototype = {
targetOptions.tmbUrl = file.tmbUrl;
}

// '/' required at the end of url
if (targetOptions.url && targetOptions.url.substr(-1) !== '/') {
targetOptions.url += '/';
}

// check uiCmdMap
chkCmdMap(targetOptions);

Expand Down Expand Up @@ -6970,6 +6984,7 @@ elFinder.prototype = {

if (data.cwd) {
if (data.cwd.volumeid && data.options && Object.keys(data.options).length && self.isRoot(data.cwd)) {
self.hasVolOptions = true;
self.volOptions[data.cwd.volumeid] = data.options;
}
data.cwd = filter(data.cwd, true);
Expand Down Expand Up @@ -6997,6 +7012,11 @@ elFinder.prototype = {
if (data.cwd && data.cwd.options && data.options) {
Object.assign(data.options, normalizeOptions(data.cwd.options));
}

// '/' required at the end of url
if (data.options && data.options.url && data.options.url.substr(-1) !== '/') {
data.options.url += '/';
}

// check error
if (error.length) {
Expand Down

0 comments on commit dc6da9e

Please sign in to comment.