: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @class elFinder toolbar
* @author Dmitry (dio) Levashov
jQuery.fn.elfindertoolbar = function(fm, opts) {
this.not('.elfinder-toolbar').each(function() {
var commands = fm._commands,
self = jQuery(this).addClass('ui-helper-clearfix ui-widget-header elfinder-toolbar'),
labelExcludeUA: ['Mobile'],
showPreferenceButton: 'none'
filter = function(opts) {
return jQuery.grep(opts, function(v) {
if (jQuery.isPlainObject(v)) {
options = Object.assign(options, v);
render = function(disabled){
jQuery.each(buttons, function(i, b) { b.detach(); });
panel = jQuery('<div class="ui-widget-content ui-corner-all elfinder-buttonset"></div>');
if ((!disabled || !disabled[name]) && (cmd = commands[name])) {
button = 'elfinder'+cmd.options.ui;
if (! buttons[name] && jQuery.fn[button]) {
buttons[name] = jQuery('<div></div>')[button](cmd);
buttons[name].children('.elfinder-button-text')[textLabel? 'show' : 'hide']();
panel.prepend(buttons[name]);
panel.children().length && self.prepend(panel);
panel.children(':gt(0)').before('<span class="ui-widget-content elfinder-toolbar-button-separator"></span>');
if (cmdPref = commands['preference']) {
//cmdPref.state = !self.children().length? 0 : -1;
if (options.showPreferenceButton === 'always' || (!self.children().length && options.showPreferenceButton === 'auto')) {
panel = jQuery('<div class="ui-widget-content ui-corner-all elfinder-buttonset"></div>');
button = 'elfinder'+cmd.options.ui;
buttons[name] = jQuery('<div></div>')[button](cmdPref);
buttons[name].children('.elfinder-button-text')[textLabel? 'show' : 'hide']();
panel.prepend(buttons[name]);
(! self.data('swipeClose') && self.children().length)? self.show() : self.hide();
prevHeight = self[0].clientHeight;
fm.trigger('toolbarload').trigger('uiresize');
panels = filter(opts || []),
l, i, cmd, panel, button, swipeHandle, autoHide, textLabel, resizeTm;
options.showPreferenceButton = options.showPreferenceButton.toLowerCase();
if (options.displayTextLabel !== 'none') {
// correction of options.displayTextLabel
textLabel = fm.storage('toolbarTextLabel');
if (textLabel === null) {
textLabel = (options.displayTextLabel && (! options.labelExcludeUA || ! options.labelExcludeUA.length || ! jQuery.grep(options.labelExcludeUA, function(v){ return fm.UA[v]? true : false; }).length));
textLabel = (textLabel == 1);
label : fm.i18n('textLabel'),
self.css('height', '').find('.elfinder-button-text')[textLabel? 'show':'hide']();
fm.trigger('uiresize').storage('toolbarTextLabel', textLabel? '1' : '0');
if (options.preferenceInContextmenu && commands['preference']) {
label : fm.i18n('toolbarPref'),
fm.exec('preference', void(0), {tab: 'toolbar'});
self.on('contextmenu', function(e) {
fm.trigger('contextmenu', {
}).on('touchstart', function(e) {
if (e.originalEvent.touches.length > 1) {
self.data('tmlongtap') && clearTimeout(self.data('tmlongtap'));
self.removeData('longtap')
.data('longtap', {x: e.originalEvent.touches[0].pageX, y: e.originalEvent.touches[0].pageY})
.data('tmlongtap', setTimeout(function() {
self.removeData('longtapTm')
pageX: self.data('longtap').x,
pageY: self.data('longtap').y
.data('longtap', {longtap: true});
}).on('touchmove touchend', function(e) {
if (self.data('tmlongtap')) {
if (e.type === 'touchend' ||
( Math.abs(self.data('longtap').x - e.originalEvent.touches[0].pageX)
+ Math.abs(self.data('longtap').y - e.originalEvent.touches[0].pageY)) > 4)
clearTimeout(self.data('tmlongtap'));
self.removeData('longtapTm');
}).on('click', function(e) {
if (self.data('longtap') && self.data('longtap').longtap) {
e.stopImmediatePropagation();
}).on('touchend click', '.elfinder-button', function(e) {
if (self.data('longtap') && self.data('longtap').longtap) {
e.stopImmediatePropagation();
self.prev().length && self.parent().prepend(this);
fm.bind('open sync select toolbarpref', function() {
var disabled = Object.assign({}, fm.option('disabledFlip')),
userHides = fm.storage('toolbarhides'),
doRender, sel, disabledKeys;
if (! userHides && Array.isArray(options.defaultHides)) {
jQuery.each(options.defaultHides, function() {
fm.storage('toolbarhides', userHides);
if (this.type === 'select') {
if (fm.searchStatus.state < 2) {
disabled = fm.getDisabledCmds(sel, true);
jQuery.each(userHides, function(n) {
if (Object.keys(fm.commandMap).length) {
jQuery.each(fm.commandMap, function(from, to){
disabledKeys = Object.keys(disabled);
if (!dispre || dispre.toString() !== disabledKeys.sort().toString()) {
render(disabledKeys.length? disabled : null);
dispre = disabledKeys.sort();
if (doRender || uiCmdMapPrev !== JSON.stringify(fm.commandMap)) {
uiCmdMapPrev = JSON.stringify(fm.commandMap);
jQuery.each(jQuery('div.elfinder-button'), function(){
var origin = jQuery(this).data('origin');
jQuery(this).after(origin).detach();
if (Object.keys(fm.commandMap).length) {
jQuery.each(fm.commandMap, function(from, to){
var cmd = fm._commands[to],
button = cmd? 'elfinder'+cmd.options.ui : null,
if (button && jQuery.fn[button]) {
if (! buttons[to] && jQuery.fn[button]) {
buttons[to] = jQuery('<div></div>')[button](cmd);
buttons[to].children('.elfinder-button-text')[textLabel? 'show' : 'hide']();
buttons[to].children('span.elfinder-button-icon').addClass('elfinder-button-icon-' + cmd.extendsCmd);
buttons[to].data('origin', btn.detach());
}).bind('resize', function(e) {
resizeTm && cancelAnimationFrame(resizeTm);
resizeTm = requestAnimationFrame(function() {
var h = self[0].clientHeight;
autoHide = fm.storage('autoHide') || {};
if (typeof autoHide.toolbar === 'undefined') {
autoHide.toolbar = (options.autoHideUA && options.autoHideUA.length > 0 && jQuery.grep(options.autoHideUA, function(v){ return fm.UA[v]? true : false; }).length);
fm.storage('autoHide', autoHide);
fm.one('init', function() {
fm.uiAutoHide.push(function(){ self.stop(true, true).trigger('toggle', { duration: 500, init: true }); });
fm.bind('load', function() {
swipeHandle = jQuery('<div class="elfinder-toolbar-swipe-handle"></div>').hide().appendTo(fm.getUI());
if (swipeHandle.css('pointer-events') !== 'none') {
self.on('toggle', function(e, data) {
var wz = fm.getUI('workzone'),
toshow= self.is(':hidden'),
tbh = self.outerHeight(true),
wz.height(wzh + (toshow? (now + delta) * -1 : h - now));
requestAnimationFrame(function() {
swipeHandle.stop(true, true).hide();
swipeHandle.height(data.handleH? data.handleH : '');
fm.resources.blink(swipeHandle, 'slowonce');
toshow && self.scrollTop('0px');
data.init && fm.trigger('uiautohide');
self.data('swipeClose', ! toshow).stop(true, true).animate({height : 'toggle'}, opt);
autoHide.toolbar = !toshow;
fm.storage('autoHide', Object.assign(fm.storage('autoHide'), {toolbar: autoHide.toolbar}));
}).on('touchstart', function(e) {
if (self.scrollBottom() > 5) {
e.originalEvent._preventSwipeY = true;