From 2e316f8f641f2cd48511ee57ffa9d031db34af39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= Date: Sun, 14 Mar 2021 22:11:24 +0100 Subject: Add directive ClickOutside for hide dropdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aurélien --- js/controller/ContentController.js | 14 +++- js/controller/ShareController.js | 6 -- js/directive/ClickOutside.js | 31 +++++++++ templates/part.content.php | 129 +++++++++++++++++++------------------ 4 files changed, 109 insertions(+), 71 deletions(-) create mode 100644 js/directive/ClickOutside.js diff --git a/js/controller/ContentController.js b/js/controller/ContentController.js index 15459c01b..ab01bf0cd 100644 --- a/js/controller/ContentController.js +++ b/js/controller/ContentController.js @@ -12,6 +12,7 @@ app.controller('ContentController', function (Publisher, FeedResource, ItemResou $filter) { 'use strict'; + this.showDropdown = []; var self = this; ItemResource.clear(); @@ -222,4 +223,15 @@ app.controller('ContentController', function (Publisher, FeedResource, ItemResou }; this.activeItem = this.getFirstItem(); -}); \ No newline at end of file + + this.openDropdown = function(itemId){ + let actualItem = this.showDropdown[itemId]; + this.showDropdown = []; + this.showDropdown[itemId] = !actualItem; + }; + + this.hide = function(){ + this.showDropdown = []; + }; + +}); diff --git a/js/controller/ShareController.js b/js/controller/ShareController.js index 8d7235d89..eb056ce19 100644 --- a/js/controller/ShareController.js +++ b/js/controller/ShareController.js @@ -12,12 +12,6 @@ app.controller('ShareController', function (ShareResource, Loading) { 'use strict'; - this.showDropDown = false; - - this.toggleDropdown = function() { - this.showDropDown = !this.showDropDown; - }; - /** Array containing users to share an item with */ this.userList = []; diff --git a/js/directive/ClickOutside.js b/js/directive/ClickOutside.js new file mode 100644 index 000000000..7021a6330 --- /dev/null +++ b/js/directive/ClickOutside.js @@ -0,0 +1,31 @@ +/** +* Nextcloud - News +* +* This file is licensed under the Affero General Public License version 3 or +* later. See the COPYING file. +* +* @author Marco Nassabain +* @author Nicolas Wendling +* @author Jimmy Huynh +* @author Aurélien David +*/ +app.directive('clickOutside', function ($document) { + 'use strict'; + + return { + restrict: 'A', + scope: { + clickOutside: '&' + }, + link: function (scope, el) { + + $document.on('click', function (e) { + if (el !== e.target && !el[0].contains(e.target)) { + scope.$apply(function () { + scope.$eval(scope.clickOutside); + }); + } + }); + } + }; +}); diff --git a/templates/part.content.php b/templates/part.content.php index e02713bee..e8c909bfc 100644 --- a/templates/part.content.php +++ b/templates/part.content.php @@ -88,74 +88,75 @@ ?>"> + - + +
  • -- cgit v1.2.3