summaryrefslogtreecommitdiffstats
path: root/coffee/directives/clickslidetoggle.coffee
blob: 51bf76bd23c74754c71f82eec8ba8d3455c9b849 (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
47
48
49
50
51
52
53
54
55
###
# 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',
['$rootScope', ($rootScope) ->

	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 ->
                                $rootScope.$broadcast 'lostFocus'

                        $rootScope.$on 'lostFocus', (scope, params) ->
                                if params != slideArea
                                        if slideArea.is(':visible') and not slideArea.is(':animated')
                                                slideArea.slideUp()

			slideArea.click (e) ->
                                $rootScope.$broadcast 'lostFocus', slideArea
				e.stopPropagation()

			elm.click (e) ->
                                $rootScope.$broadcast 'lostFocus', slideArea
				e.stopPropagation()

]