summaryrefslogtreecommitdiffstats
path: root/coffee/directives/clickslidetoggle.coffee
blob: cea8560c0a322567e190a90b39e18710b914765e (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
###
# ownCloud news app
#
# @author Alessandro Cosentino
# @author Bernhard Posselt
# Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
# Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
#
# This file is licensed under the Affero General Public License version 3 or
# later.
#
# See the COPYING-README file
#
###

###
Used to slide up an area and can be customized by passing an expression.
If selector is defined, a different area is slid up on click
If hideOnFocusLost is defined, the slid up area will hide when the focus is lost
###
angular.module('News').directive 'clickSlideToggle', ->

        return (scope, elm, attr) ->
                options = scope.$eval(attr.clickSlideToggle)

                if angular.isDefined(options.selector)
                        slideArea = $(options.selector)
                else
                        slideArea = elm

                elm.click ->
                        if slideArea.is(':visible') and not slideArea.is(':animated')
                                slideArea.slideUp()
                        else
                                slideArea.slideDown()

                if angular.isDefined(options.hideOnFocusLost) and options.hideOnFocusLost
                        $(document.body).click ->
                                if slideArea.is(':visible') and not slideArea.is(':animated')
                                        slideArea.slideUp()

                        slideArea.click (e) ->
                                e.stopPropagation()

                        elm.click (e) ->
                                e.stopPropagation()