summaryrefslogtreecommitdiffstats
path: root/js/directive/ClickOutside.js
blob: 7021a6330bf922950e5d8658082a256316bcb825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
                    });
                }
            });
        }
    };
});