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 /js/app.js | |
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
Diffstat (limited to 'js/app.js')
-rw-r--r-- | js/app.js | 59 |
1 files changed, 34 insertions, 25 deletions
@@ -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 |