diff --git a/www/drive/main.js b/www/drive/main.js index 43f469aff..5e5cb7451 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -334,6 +334,29 @@ define([ }); }; + var updateContextButton = function () { + var $li = $content.find('.selected'); + if ($li.length !== 1) { + $li = $tree.find('.element.active').closest('li'); + } + var $button = $driveToolbar.find('#contextButton'); + if ($li.length !== 1 + || !$._data($li[0], 'events').contextmenu + || $._data($li[0], 'events').contextmenu.length === 0) { + $button.hide(); + return; + } + $button.show(); + $button.css({ + background: '#000' + }); + window.setTimeout(function () { + $button.css({ + background: '' + }); + }, 500); + }; + // Add the "selected" class to the "li" corresponding to the clicked element var onElementClick = function (e, $element, path) { // If "Ctrl" is pressed, do not remove the current selection @@ -354,14 +377,7 @@ define([ } else { $element.removeClass("selected"); } - $driveToolbar.find('#contextButton').css({ - background: '#000' - }); - window.setTimeout(function () { - $driveToolbar.find('#contextButton').css({ - background: '' - }); - }, 500); + updateContextButton(); }; // Open the selected context menu on the closest "li" element @@ -408,7 +424,7 @@ define([ var openDirectoryContextMenu = function (e) { var $element = $(e.target).closest('li'); $contextMenu.find('li').show(); - if ($element.find('.file-element').length) { + if ($element.is('.file-element')) { $contextMenu.find('a.newfolder').parent('li').hide(); } else { $contextMenu.find('a.open_ro').parent('li').hide(); @@ -420,7 +436,7 @@ define([ var openDefaultContextMenu = function (e) { var $element = $(e.target).closest('li'); $defaultContextMenu.find('li').show(); - if ($element.find('.file-element').length) { + if ($element.is('.file-element')) { $defaultContextMenu.find('a.newfolder').parent('li').hide(); } else { $defaultContextMenu.find('a.open_ro').parent('li').hide(); @@ -1215,6 +1231,8 @@ define([ var $icon = getFileIcon(file.href); var $element = $('