Fix issue about menu not disappearing on firmware page
In firmware update page "More info” dialog did not disappear until
it is clicked again. With this push users can click anywhere outside
the menu and it disappears.
Resolves openbmc/phosphor-webui#32
Change-Id: I1519caf2428c702af03fb0e4dd8a08d0c0588abf
Signed-off-by: Ryan Arnell <iffy.ryan@ibm.com>
diff --git a/app/common/directives/click-outside.js b/app/common/directives/click-outside.js
new file mode 100644
index 0000000..ffe1464
--- /dev/null
+++ b/app/common/directives/click-outside.js
@@ -0,0 +1,24 @@
+window.angular && (function(angular) {
+ 'use strict';
+
+ angular.module('app.common.directives')
+ .directive('clickOutside', function($document) {
+ return {
+ restrict: 'A', scope: {clickOutside: '&'},
+ link: function(scope, el, attr) {
+ function clickEvent(e) {
+ if (el !== e.target && !el[0].contains(e.target)) {
+ scope.$apply(function() {
+ scope.$eval(scope.clickOutside);
+ });
+ }
+ }
+ $document.bind('click', clickEvent);
+
+ scope.$on('$destroy', function() {
+ $document.unbind('click', clickEvent);
+ });
+ }
+ }
+ });
+})(window.angular);
\ No newline at end of file