diff options
author | Aurélien <dav.aurelien@gmail.com> | 2021-03-14 22:11:24 +0100 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-04-08 23:17:31 +0200 |
commit | 2e316f8f641f2cd48511ee57ffa9d031db34af39 (patch) | |
tree | 6d3b14a1a8cb12aa5c562ed6a25cb7d9e05646e8 /js/directive | |
parent | 792082e2e0fcca32fffc7693a210ae2fa64d4c06 (diff) |
Add directive ClickOutside for hide dropdown
Signed-off-by: Aurélien <dav.aurelien@gmail.com>
Diffstat (limited to 'js/directive')
-rw-r--r-- | js/directive/ClickOutside.js | 31 |
1 files changed, 31 insertions, 0 deletions
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 <marco.nassabain@hotmail.com> +* @author Nicolas Wendling <nicolas.wendling1011@gmail.com> +* @author Jimmy Huynh <natorisaki@gmail.com> +* @author Aurélien David <dav.aurelien@gmail.com> +*/ +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); + }); + } + }); + } + }; +}); |