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/directive/ClickOutside.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 js/directive/ClickOutside.js (limited to 'js/directive') 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); + }); + } + }); + } + }; +}); -- cgit v1.2.3