mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
[search] target from cwd, volume or all, and MIME type can be chosen
This commit is contained in:
@@ -179,6 +179,23 @@
|
||||
min-height: 26px;
|
||||
float:right;
|
||||
width:202px;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.elfinder .elfinder-button-search .elfinder-button-menu {
|
||||
font-size: 8pt;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.elfinder .elfinder-button-search .elfinder-button-menu div {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.elfinder .elfinder-button-search .elfinder-button-menu div .ui-state-hover {
|
||||
border: 1px solid;
|
||||
}
|
||||
|
||||
/* ltr/rte enviroment */
|
||||
|
||||
@@ -27,14 +27,16 @@ elFinder.prototype.commands.search = function() {
|
||||
* @param String search string
|
||||
* @return $.Deferred
|
||||
**/
|
||||
this.exec = function(q) {
|
||||
this.exec = function(q, target, mime) {
|
||||
var fm = this.fm;
|
||||
|
||||
if (typeof(q) == 'string' && q) {
|
||||
fm.trigger('searchstart', {query : q});
|
||||
target = target += '';
|
||||
mime = mime? [mime+''] : [];
|
||||
fm.trigger('searchstart', {query : q, target : target, mimes : mime});
|
||||
|
||||
return fm.request({
|
||||
data : {cmd : 'search', q : q},
|
||||
data : {cmd : 'search', q : q, target : target, mimes : mime},
|
||||
notify : {type : 'search', cnt : 1, hideCnt : true}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,6 +145,10 @@ if (elFinder && elFinder.prototype && typeof(elFinder.prototype.i18) == 'object'
|
||||
'btnApprove': 'Goto $1 & approve', // from v2.1 added 26.04.2012
|
||||
'btnUnmount': 'Unmount', // from v2.1 added 30.04.2012
|
||||
'btnConv' : 'Convert', // from v2.1 added 08.04.2014
|
||||
'btnCwd' : 'Here', // from v2.1 added 22.5.2015
|
||||
'btnVolume' : 'Volume', // from v2.1 added 22.5.2015
|
||||
'btnAll' : 'All', // from v2.1 added 22.5.2015
|
||||
'btnMime' : 'MIME Type', // from v2.1 added 22.5.2015
|
||||
|
||||
/******************************** notifications ********************************/
|
||||
'ntfopen' : 'Open folder',
|
||||
@@ -305,6 +309,8 @@ if (elFinder && elFinder.prototype && typeof(elFinder.prototype.i18) == 'object'
|
||||
'dropPasteFiles' : 'Drop or Paste files here', // from v2.1 added 07.04.2014
|
||||
'encoding' : 'Encoding', // from v2.1 added 19.12.2014
|
||||
'locale' : 'Locale', // from v2.1 added 19.12.2014
|
||||
'searchTarget' : 'Target: $1', // from v2.1 added 22.5.2015
|
||||
'searchMime' : 'Search by input MIME Type', // from v2.1 added 22.5.2015
|
||||
|
||||
/********************************** mimetypes **********************************/
|
||||
'kindUnknown' : 'Unknown',
|
||||
|
||||
@@ -138,6 +138,10 @@ if (elFinder && elFinder.prototype && typeof(elFinder.prototype.i18) == 'object'
|
||||
'btnApprove': 'Goto $1 & approve', // added 26.04.2012
|
||||
'btnUnmount': 'Unmount', // added 30.04.2012
|
||||
'btnConv' : 'Convert', // added 08.04.2014
|
||||
'btnCwd' : 'Here', // from v2.1 added 22.5.2015
|
||||
'btnVolume' : 'Volume', // from v2.1 added 22.5.2015
|
||||
'btnAll' : 'All', // from v2.1 added 22.5.2015
|
||||
'btnMime' : 'MIME Type', // from v2.1 added 22.5.2015
|
||||
|
||||
/******************************** notifications ********************************/
|
||||
'ntfopen' : 'Open folder',
|
||||
@@ -298,6 +302,8 @@ if (elFinder && elFinder.prototype && typeof(elFinder.prototype.i18) == 'object'
|
||||
'dropPasteFiles' : 'Drop or Paste files here', // added 07.04.2014
|
||||
'encoding' : 'Encoding', // from v2.1 added 19.12.2014
|
||||
'locale' : 'Locale', // from v2.1 added 19.12.2014
|
||||
'searchTarget' : 'Target: $1', // from v2.1 added 22.5.2015
|
||||
'searchMime' : 'Search by input MIME Type', // from v2.1 added 22.5.2015
|
||||
|
||||
/********************************** mimetypes **********************************/
|
||||
'kindUnknown' : 'Unknown',
|
||||
|
||||
@@ -139,6 +139,10 @@ if (elFinder && elFinder.prototype && typeof(elFinder.prototype.i18) == 'object'
|
||||
'btnApprove': '$1へ行き認可する', // added 26.04.2012
|
||||
'btnUnmount': 'アンマウント', // added 30.04.2012
|
||||
'btnConv' : '変換', // added 08.04.2014
|
||||
'btnCwd' : 'この場所', // from v2.1 added 22.5.2015
|
||||
'btnVolume' : 'ボリューム', // from v2.1 added 22.5.2015
|
||||
'btnAll' : '全て', // from v2.1 added 22.5.2015
|
||||
'btnMime' : 'MIMEタイプ', // from v2.1 added 22.5.2015
|
||||
|
||||
/******************************** notifications ********************************/
|
||||
'ntfopen' : 'フォルダーを開いています',
|
||||
@@ -299,6 +303,8 @@ if (elFinder && elFinder.prototype && typeof(elFinder.prototype.i18) == 'object'
|
||||
'dropPasteFiles' : 'ここにファイルをドロップまたは貼り付け', // added 07.04.2014
|
||||
'encoding' : '文字コード', // from v2.1 added 19.12.2014
|
||||
'locale' : 'ロケール', // from v2.1 added 19.12.2014
|
||||
'searchTarget' : '検索範囲: $1', // from v2.1 added 22.5.2015
|
||||
'searchMime' : '指定した MIME タイプで検索', // from v2.1 added 22.5.2015
|
||||
|
||||
/********************************** mimetypes **********************************/
|
||||
'kindUnknown' : '不明',
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ $.fn.elfinderpath = function(fm) {
|
||||
})
|
||||
.prependTo(fm.getUI('statusbar').show())
|
||||
|
||||
fm.bind('open searchend', function() {
|
||||
fm.bind('open searchend parents', function() {
|
||||
var dirs = [];
|
||||
|
||||
$.each(fm.parents(fm.cwd().hash), function(i, hash) {
|
||||
|
||||
+70
-10
@@ -7,27 +7,54 @@
|
||||
$.fn.elfindersearchbutton = function(cmd) {
|
||||
return this.each(function() {
|
||||
var result = false,
|
||||
button = $(this).hide().addClass('ui-widget-content elfinder-button '+cmd.fm.res('class', 'searchbtn')+''),
|
||||
fm = cmd.fm,
|
||||
id = function(name){return fm.namespace + name},
|
||||
timer = null,
|
||||
button = $(this).hide().addClass('ui-widget-content elfinder-button '+fm.res('class', 'searchbtn')+''),
|
||||
search = function() {
|
||||
var val = $.trim(input.val());
|
||||
opts.slideUp();
|
||||
var val = $.trim(input.val()),
|
||||
from = !$('#' + id('SearchFromAll')).prop('checked'),
|
||||
mime = $('#' + id('SearchMime')).prop('checked');
|
||||
if (from) {
|
||||
if ($('#' + id('SearchFromVol')).prop('checked')) {
|
||||
from = fm.root(fm.cwd().hash);
|
||||
} else {
|
||||
from = fm.cwd().hash;
|
||||
}
|
||||
}
|
||||
if (mime) {
|
||||
mime = val;
|
||||
val = '.';
|
||||
}
|
||||
if (val) {
|
||||
cmd.exec(val).done(function() {
|
||||
cmd.exec(val, from, mime).done(function() {
|
||||
result = true;
|
||||
input.focus();
|
||||
});
|
||||
|
||||
} else {
|
||||
cmd.fm.trigger('searchend');
|
||||
fm.trigger('searchend');
|
||||
}
|
||||
},
|
||||
abort = function() {
|
||||
opts.slideUp();
|
||||
input.val('');
|
||||
if (result) {
|
||||
result = false;
|
||||
cmd.fm.trigger('searchend');
|
||||
fm.trigger('searchend');
|
||||
}
|
||||
},
|
||||
input = $('<input type="text" size="42"/>')
|
||||
.focus(function(){
|
||||
timer && clearTimeout(timer);
|
||||
opts.slideDown();
|
||||
})
|
||||
.blur(function(){
|
||||
timer = setTimeout(function(){
|
||||
opts.slideUp();
|
||||
}, 500);
|
||||
})
|
||||
.appendTo(button)
|
||||
// to avoid fm shortcuts on arrows
|
||||
.keypress(function(e) {
|
||||
@@ -42,7 +69,19 @@ $.fn.elfindersearchbutton = function(cmd) {
|
||||
e.preventDefault();
|
||||
abort();
|
||||
}
|
||||
});
|
||||
}),
|
||||
opts = $('<div class="ui-widget ui-widget-content elfinder-button-menu ui-corner-all"/>')
|
||||
.append($('<div class="buttonset"/>')
|
||||
.append($('<input id="'+id('SearchFromCwd')+'" name="serchfrom" type="radio" checked="checked"/><label for="'+id('SearchFromCwd')+'">'+fm.i18n('btnCwd')+'</label>'))
|
||||
.append($('<input id="'+id('SearchFromVol')+'" name="serchfrom" type="radio"/><label for="'+id('SearchFromVol')+'">'+fm.i18n('btnVolume')+'</label>'))
|
||||
.append($('<input id="'+id('SearchFromAll')+'" name="serchfrom" type="radio"/><label for="'+id('SearchFromAll')+'">'+fm.i18n('btnAll')+'</label>'))
|
||||
)
|
||||
.append($('<div class="button"/>').
|
||||
append($('<input id="'+id('SearchMime')+'" type="checkbox"/><label for="'+id('SearchMime')+'">'+fm.i18n('btnMime')+'</label>'))
|
||||
)
|
||||
.hide()
|
||||
.zIndex(12+button.zIndex())
|
||||
.appendTo(button);
|
||||
|
||||
$('<span class="ui-icon ui-icon-search" title="'+cmd.title+'"/>')
|
||||
.appendTo(button)
|
||||
@@ -52,13 +91,23 @@ $.fn.elfindersearchbutton = function(cmd) {
|
||||
.appendTo(button)
|
||||
.click(abort);
|
||||
|
||||
$(function(){
|
||||
opts.find('div.buttonset').buttonset();
|
||||
opts.find('div.button input').button();
|
||||
$('#'+id('SearchFromAll')).next('label').attr('title', fm.i18n('searchTarget', fm.i18n('btnAll')));
|
||||
$('#'+id('SearchMime')).next('label').attr('title', fm.i18n('searchMime'));
|
||||
opts.find('input').on('click', function(){
|
||||
input.focus();
|
||||
});
|
||||
});
|
||||
|
||||
// wait when button will be added to DOM
|
||||
setTimeout(function() {
|
||||
button.parent().detach();
|
||||
cmd.fm.getUI('toolbar').prepend(button.show());
|
||||
fm.getUI('toolbar').prepend(button.show());
|
||||
// position icons for ie7
|
||||
if (cmd.fm.UA.ltIE7) {
|
||||
var icon = button.children(cmd.fm.direction == 'ltr' ? '.ui-icon-close' : '.ui-icon-search');
|
||||
if (fm.UA.ltIE7) {
|
||||
var icon = button.children(fm.direction == 'ltr' ? '.ui-icon-close' : '.ui-icon-search');
|
||||
icon.css({
|
||||
right : '',
|
||||
left : parseInt(button.width())-icon.outerWidth(true)
|
||||
@@ -66,13 +115,24 @@ $.fn.elfindersearchbutton = function(cmd) {
|
||||
}
|
||||
}, 200);
|
||||
|
||||
cmd.fm
|
||||
fm
|
||||
.select(function() {
|
||||
input.blur();
|
||||
})
|
||||
.bind('searchend', function() {
|
||||
input.val('');
|
||||
})
|
||||
.bind('open parents', function() {
|
||||
var dirs = [],
|
||||
volroot = fm.file(fm.root(fm.cwd().hash));
|
||||
|
||||
$.each(fm.parents(fm.cwd().hash), function(i, hash) {
|
||||
dirs.push(fm.file(hash).name);
|
||||
});
|
||||
|
||||
$('#'+id('SearchFromCwd')).next('label').attr('title', fm.i18n('searchTarget', dirs.join(fm.option('separator'))));
|
||||
$('#'+id('SearchFromVol')).next('label').attr('title', fm.i18n('searchTarget', volroot.name));
|
||||
})
|
||||
.shortcut({
|
||||
pattern : 'ctrl+f f3',
|
||||
description : cmd.title,
|
||||
|
||||
@@ -91,7 +91,7 @@ class elFinder {
|
||||
'put' => array('target' => true, 'content' => '', 'mimes' => false),
|
||||
'archive' => array('targets' => true, 'type' => true, 'mimes' => false),
|
||||
'extract' => array('target' => true, 'mimes' => false),
|
||||
'search' => array('q' => true, 'mimes' => false),
|
||||
'search' => array('q' => true, 'mimes' => false, 'target' => false),
|
||||
'info' => array('targets' => true),
|
||||
'dim' => array('target' => true),
|
||||
'resize' => array('target' => true, 'width' => true, 'height' => true, 'mode' => false, 'x' => false, 'y' => false, 'degree' => false),
|
||||
@@ -1783,10 +1783,16 @@ class elFinder {
|
||||
protected function search($args) {
|
||||
$q = trim($args['q']);
|
||||
$mimes = !empty($args['mimes']) && is_array($args['mimes']) ? $args['mimes'] : array();
|
||||
$target = !empty($args['target'])? $args['target'] : null;
|
||||
$result = array();
|
||||
|
||||
foreach ($this->volumes as $volume) {
|
||||
$result = array_merge($result, $volume->search($q, $mimes));
|
||||
if (!is_null($target)) {
|
||||
$volume = $this->volume($target);
|
||||
$result = $volume->search($q, $mimes, $target);
|
||||
} else {
|
||||
foreach ($this->volumes as $volume) {
|
||||
$result = array_merge($result, $volume->search($q, $mimes));
|
||||
}
|
||||
}
|
||||
|
||||
return array('files' => $result);
|
||||
|
||||
@@ -1861,10 +1861,18 @@ abstract class elFinderVolumeDriver {
|
||||
* @return array
|
||||
* @author Dmitry (dio) Levashov
|
||||
**/
|
||||
public function search($q, $mimes) {
|
||||
return $this->commandDisabled('search')
|
||||
public function search($q, $mimes, $hash = null) {
|
||||
$dir = null;
|
||||
if ($hash) {
|
||||
$dir = $this->decode($hash);
|
||||
$stat = $this->stat($dir);
|
||||
if (!$stat || $stat['mime'] !== 'directory' || !$stat['read']) {
|
||||
$q = '';
|
||||
}
|
||||
}
|
||||
return ($q === '' || $this->commandDisabled('search'))
|
||||
? array()
|
||||
: $this->doSearch($this->root, $q, $mimes);
|
||||
: $this->doSearch(is_null($dir)? $this->root : $dir, $q, $mimes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2936,7 +2944,7 @@ abstract class elFinderVolumeDriver {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($stat['hidden']) || !$this->mimeAccepted($stat['mime'])) {
|
||||
if (!empty($stat['hidden']) || !$this->mimeAccepted($stat['mime'], array_merge($mimes, $this->onlyMimes))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -659,7 +659,7 @@ class elFinderVolumeDropbox extends elFinderVolumeDriver {
|
||||
if (!isset($this->cache[$raw['path']])) {
|
||||
$stat = $this->updateCache($raw['path'], $stat);
|
||||
}
|
||||
if ($stat['mime'] !== 'directory' || $this->mimeAccepted($stat['mime'], $mimes)) {
|
||||
if ($stat['mime'] !== 'directory' || $this->mimeAccepted($stat['mime'], array_merge($mimes, $this->onlyMimes))) {
|
||||
$result[] = $this->stat($raw['path']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user