From 628148d0018be9017185d99638771c1635551b8c Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 7 Feb 2017 13:09:14 +0100 Subject: [PATCH 1/3] Display the contextmenu button only if contextmenu exists --- www/drive/main.js | 56 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 14 deletions(-) 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 = $('
  • ', { 'class': 'file-element element' }); addFileData(file.href, file.title, $element, false); + $element.data('path', [FILES_DATA, allfiles.indexOf(file)]); + $element.data('element', file.href); $element.prepend($icon).dblclick(function () { openFile(file.href); }); @@ -1324,6 +1342,7 @@ define([ if (APP.mobile) { var $context = $('