diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-12 15:24:15 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-12 15:25:11 +0100 |
commit | a658eac21f9b2131750f9253ca2a608454d355f4 (patch) | |
tree | 5738b542e03da4831a3ac50468fc9c2be2d62531 | |
parent | e904f00e2002d12d7e5b7b9632e964ce2825e498 (diff) |
also slide down other elements that have the click slide handler and listeners on focus lost when an element wit this directive is clicked
-rw-r--r-- | coffee/directives/clickslidetoggle.coffee | 15 | ||||
-rw-r--r-- | coffee/lib/services/notification.coffee | 0 | ||||
-rw-r--r-- | js/app.js | 59 |
3 files changed, 46 insertions, 28 deletions
diff --git a/coffee/directives/clickslidetoggle.coffee b/coffee/directives/clickslidetoggle.coffee index f9399e352..51bf76bd2 100644 --- a/coffee/directives/clickslidetoggle.coffee +++ b/coffee/directives/clickslidetoggle.coffee @@ -18,7 +18,8 @@ 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', -> +angular.module('News').directive 'clickSlideToggle', +['$rootScope', ($rootScope) -> return (scope, elm, attr) -> options = scope.$eval(attr.clickSlideToggle) @@ -36,11 +37,19 @@ angular.module('News').directive 'clickSlideToggle', -> if angular.isDefined(options.hideOnFocusLost) and options.hideOnFocusLost $(document.body).click -> - if slideArea.is(':visible') and not slideArea.is(':animated') - slideArea.slideUp() + $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() + +]
\ No newline at end of file diff --git a/coffee/lib/services/notification.coffee b/coffee/lib/services/notification.coffee new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/coffee/lib/services/notification.coffee @@ -2249,37 +2249,46 @@ */ - angular.module('News').directive('clickSlideToggle', function() { - return function(scope, elm, attr) { - var options, slideArea; - options = scope.$eval(attr.clickSlideToggle); - if (angular.isDefined(options.selector)) { - slideArea = $(options.selector); - } else { - slideArea = elm; - } - elm.click(function() { - if (slideArea.is(':visible') && !slideArea.is(':animated')) { - return slideArea.slideUp(); + angular.module('News').directive('clickSlideToggle', [ + '$rootScope', function($rootScope) { + return function(scope, elm, attr) { + var options, slideArea; + options = scope.$eval(attr.clickSlideToggle); + if (angular.isDefined(options.selector)) { + slideArea = $(options.selector); } else { - return slideArea.slideDown(); + slideArea = elm; } - }); - if (angular.isDefined(options.hideOnFocusLost) && options.hideOnFocusLost) { - $(document.body).click(function() { + elm.click(function() { if (slideArea.is(':visible') && !slideArea.is(':animated')) { return slideArea.slideUp(); + } else { + return slideArea.slideDown(); } }); - slideArea.click(function(e) { - return e.stopPropagation(); - }); - return elm.click(function(e) { - return e.stopPropagation(); - }); - } - }; - }); + if (angular.isDefined(options.hideOnFocusLost) && options.hideOnFocusLost) { + $(document.body).click(function() { + return $rootScope.$broadcast('lostFocus'); + }); + $rootScope.$on('lostFocus', function(scope, params) { + if (params !== slideArea) { + if (slideArea.is(':visible') && !slideArea.is(':animated')) { + return slideArea.slideUp(); + } + } + }); + slideArea.click(function(e) { + $rootScope.$broadcast('lostFocus', slideArea); + return e.stopPropagation(); + }); + return elm.click(function(e) { + $rootScope.$broadcast('lostFocus', slideArea); + return e.stopPropagation(); + }); + } + }; + } + ]); /* # ownCloud news app |