Skip to content

Commit

Permalink
[cmd:open] fix #1844 make configurable to open into tab(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Jan 12, 2017
1 parent 69b75fb commit 59e63c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
62 changes: 37 additions & 25 deletions js/commands/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
cnt = files.length,
thash = (typeof opts == 'object')? opts.thash : false,
opts = this.options,
into = opts.into || 'window',
file, url, s, w, imgW, imgH, winW, winH, reg, link, html5dl, inline;

if (!cnt && !thash) {
Expand Down Expand Up @@ -61,6 +62,8 @@
}

var doOpen = function() {
var wnd, target;

try {
reg = new RegExp(fm.option('dispInlineRegex'));
} catch(e) {
Expand All @@ -72,6 +75,7 @@
html5dl = (typeof link.get(0).download === 'string');
cnt = files.length;
while (cnt--) {
target = 'elf_open_window';
file = files[cnt];

if (!file.read) {
Expand All @@ -93,34 +97,40 @@
}
}
} else {

// set window size for image if set
imgW = winW = Math.round(2 * $(window).width() / 3);
imgH = winH = Math.round(2 * $(window).height() / 3);
if (parseInt(file.width) && parseInt(file.height)) {
imgW = parseInt(file.width);
imgH = parseInt(file.height);
} else if (file.dim) {
s = file.dim.split('x');
imgW = parseInt(s[0]);
imgH = parseInt(s[1]);
if (url.indexOf(fm.options.url) === 0) {
url = '';
}
if (winW >= imgW && winH >= imgH) {
winW = imgW;
winH = imgH;
} else {
if ((imgW - winW) > (imgH - winH)) {
winH = Math.round(imgH * (winW / imgW));
if (into === 'window') {
// set window size for image if set
imgW = winW = Math.round(2 * $(window).width() / 3);
imgH = winH = Math.round(2 * $(window).height() / 3);
if (parseInt(file.width) && parseInt(file.height)) {
imgW = parseInt(file.width);
imgH = parseInt(file.height);
} else if (file.dim) {
s = file.dim.split('x');
imgW = parseInt(s[0]);
imgH = parseInt(s[1]);
}
if (winW >= imgW && winH >= imgH) {
winW = imgW;
winH = imgH;
} else {
winW = Math.round(imgW * (winH / imgH));
if ((imgW - winW) > (imgH - winH)) {
winH = Math.round(imgH * (winW / imgW));
} else {
winW = Math.round(imgW * (winH / imgH));
}
}
w = 'width='+winW+',height='+winH;
wnd = window.open(url, target, w + ',top=50,left=50,scrollbars=yes,resizable=yes');
} else {
if (into === 'tabs') {
target = file.hash;
}
wnd = window.open('about:blank', target);
}
w = 'width='+winW+',height='+winH;

if (url.indexOf(fm.options.url) === 0) {
url = '';
}
var wnd = window.open(url, 'new_window', w + ',top=50,left=50,scrollbars=yes,resizable=yes');

if (!wnd) {
return dfrd.reject('errPopup');
}
Expand All @@ -129,7 +139,7 @@
var form = document.createElement("form");
form.action = fm.options.url;
form.method = typeof opts.method === 'string' && opts.method.toLowerCase() === 'get'? 'GET' : 'POST';
form.target = 'new_window';
form.target = target;
form.style.display = 'none';
var params = $.extend({}, fm.options.customData, {
cmd: 'file',
Expand All @@ -145,6 +155,8 @@

document.body.appendChild(form);
form.submit();
} else if (into !== 'window') {
wnd.location = url;
}
wnd.focus();

Expand Down
5 changes: 4 additions & 1 deletion js/elFinder.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ elFinder.prototype._options = {
// If you set to "get" will be displayed request parameter in the browser's location field
// so if you want to conceal its parameters should be given "post".
// Nevertheless, please specify "get" if you want to enable the partial request by HTTP Range header.
method : 'post'
method : 'post',
// Where to open into : 'window'(default), 'tab' or 'tabs'
// 'tabs' opens in each tabs
into : 'window'
},
// "upload" command options.
upload : {
Expand Down

0 comments on commit 59e63c4

Please sign in to comment.