mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
34dc4b95d1
`jQuery.browser` removed from "jQuery 1.9". This change is replace jQuery.browser to new elFinder object `UA`.
87 lines
1.9 KiB
JavaScript
87 lines
1.9 KiB
JavaScript
"use strict"
|
|
/**
|
|
* @class elFinder toolbar search button widget.
|
|
*
|
|
* @author Dmitry (dio) Levashov
|
|
**/
|
|
$.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')+''),
|
|
search = function() {
|
|
var val = $.trim(input.val());
|
|
if (val) {
|
|
cmd.exec(val).done(function() {
|
|
result = true;
|
|
input.focus();
|
|
});
|
|
|
|
} else {
|
|
cmd.fm.trigger('searchend')
|
|
}
|
|
},
|
|
abort = function() {
|
|
input.val('');
|
|
if (result) {
|
|
result = false;
|
|
cmd.fm.trigger('searchend');
|
|
}
|
|
},
|
|
input = $('<input type="text" size="42"/>')
|
|
.appendTo(button)
|
|
// to avoid fm shortcuts on arrows
|
|
.keypress(function(e) {
|
|
e.stopPropagation();
|
|
})
|
|
.keydown(function(e) {
|
|
e.stopPropagation();
|
|
|
|
e.keyCode == 13 && search();
|
|
|
|
if (e.keyCode== 27) {
|
|
e.preventDefault();
|
|
abort();
|
|
}
|
|
});
|
|
|
|
$('<span class="ui-icon ui-icon-search" title="'+cmd.title+'"/>')
|
|
.appendTo(button)
|
|
.click(search);
|
|
|
|
$('<span class="ui-icon ui-icon-close"/>')
|
|
.appendTo(button)
|
|
.click(abort)
|
|
|
|
// wait when button will be added to DOM
|
|
setTimeout(function() {
|
|
button.parent().detach();
|
|
cmd.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');
|
|
icon.css({
|
|
right : '',
|
|
left : parseInt(button.width())-icon.outerWidth(true)
|
|
});
|
|
}
|
|
}, 200);
|
|
|
|
cmd.fm
|
|
.error(function() {
|
|
input.unbind('keydown');
|
|
})
|
|
.select(function() {
|
|
input.blur();
|
|
})
|
|
.bind('searchend', function() {
|
|
input.val('');
|
|
})
|
|
.viewchange(abort)
|
|
.shortcut({
|
|
pattern : 'ctrl+f f3',
|
|
description : cmd.title,
|
|
callback : function() { input.select().focus(); }
|
|
});
|
|
|
|
});
|
|
} |