From 539e784a7a16d906dba8434354fcfea7c9905b57 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 26 Feb 2019 16:24:38 +0100 Subject: [PATCH] Add an X icon to cancel a search in the drive --- www/drive/app-drive.less | 22 +++++++++++++++++++--- www/drive/inner.js | 21 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/www/drive/app-drive.less b/www/drive/app-drive.less index fecbb9ca6..5bf6a7ea8 100644 --- a/www/drive/app-drive.less +++ b/www/drive/app-drive.less @@ -269,8 +269,11 @@ text-align: center; padding: 0; position: relative; + display: flex; + background: lighten(@colortheme_drive-bg, 8%); + border-right: 1px solid lighten(@colortheme_drive-bg, 16%); input { - background: lighten(@colortheme_drive-bg, 8%); + background: transparent; color: @colortheme_drive-color; .tools_placeholder-color(@colortheme_drive-color); outline-width: 0px; @@ -278,16 +281,29 @@ width: 100%; //border: 1px solid #ccc; border: 0; - border-right: 1px solid lighten(@colortheme_drive-bg, 16%); //border-right: 0; height: @variables_bar-height; padding: 0 5px; padding-left: 45px; + flex: 1; + min-width: 0; &:focus { outline-width: 0px; } + &.cp-app-drive-search-active { + & ~ .cp-app-drive-tree-search-icon { + display: none; + } + & ~ .cp-app-drive-search-cancel { + display: inline-block; + } + } + } + .cp-app-drive-search-cancel { + display: none; + cursor: pointer; } - .cp-app-drive-tree-search-con { + .cp-app-drive-tree-search-icon, .cp-app-drive-search-cancel { color: @colortheme_drive-color; position: absolute; left: 20px; // TODO align with drive categories diff --git a/www/drive/inner.js b/www/drive/inner.js index 956ec6a5d..4601533b9 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -111,7 +111,7 @@ define([ var $sortDescIcon = $('', {"class": "fa fa-angle-down sortdesc"}); var $closeIcon = $('', {"class": "fa fa-window-close"}); //var $backupIcon = $('', {"class": "fa fa-life-ring"}); - var $searchIcon = $('', {"class": "fa fa-search cp-app-drive-tree-search-con"}); + var $searchIcon = $('', {"class": "fa fa-search cp-app-drive-tree-search-icon"}); var $addIcon = $('', {"class": "fa fa-plus"}); var $renamedIcon = $('', {"class": "fa fa-flag"}); var $readonlyIcon = $('', {"class": "fa " + faReadOnly}); @@ -2971,6 +2971,13 @@ define([ else { displayDirectory([ROOT]); } return; } + if ($input.val()) { + if (!$input.hasClass('cp-app-drive-search-active')) { + $input.addClass('cp-app-drive-search-active'); + } + } else { + $input.removeClass('cp-app-drive-search-active'); + } if (APP.mobile()) { return; } search.to = window.setTimeout(function () { if (!isInSearchTmp) { search.oldLocation = currentPath.slice(); } @@ -2979,8 +2986,18 @@ define([ if (!manager.comparePath(newLocation, currentPath.slice())) { displayDirectory(newLocation); } }, 500); }).appendTo($div); + var cancel = h('span.fa.fa-times.cp-app-drive-search-cancel', {title:Messages.cancel}); + cancel.addEventListener('click', function () { + $input.val(''); + setSearchCursor(0); + if (search.oldLocation && search.oldLocation.length) { displayDirectory(search.oldLocation); } + }); + $div.append(cancel); $searchIcon.clone().appendTo($div); - if (isInSearch) { $input.val(currentPath[1] || ''); } + if (isInSearch) { + $input.val(currentPath[1] || ''); + if ($input.val()) { $input.addClass('cp-app-drive-search-active'); } + } $container.append($div); };