diff options
author | Giovane Liberato <giovaneliberato@gmail.com> | 2015-12-08 16:06:19 -0200 |
---|---|---|
committer | Giovane Liberato <giovaneliberato@gmail.com> | 2015-12-08 16:06:19 -0200 |
commit | d62ea0a762f4fa80ff2e0d2c3e4ea5bf3bb6c764 (patch) | |
tree | 8fe806a53ce60c89e5618e55cb4a7419df94c37f /web-ui/app | |
parent | 77ef504e27e48f1e3b8b86038730b75114a2c44f (diff) |
Closes user settings box when clicking outside it. #509 w/ @pereiragislene
Diffstat (limited to 'web-ui/app')
-rw-r--r-- | web-ui/app/js/user_settings/ui/user_settings_box.js | 22 | ||||
-rw-r--r-- | web-ui/app/js/user_settings/ui/user_settings_icon.js | 3 |
2 files changed, 23 insertions, 2 deletions
diff --git a/web-ui/app/js/user_settings/ui/user_settings_box.js b/web-ui/app/js/user_settings/ui/user_settings_box.js index ece46c49..d3de23ed 100644 --- a/web-ui/app/js/user_settings/ui/user_settings_box.js +++ b/web-ui/app/js/user_settings/ui/user_settings_box.js @@ -27,7 +27,8 @@ define( return defineComponent(function () { this.defaultAttrs({ - close: '#user-settings-close' + close: '#user-settings-close', + userSettingsBoxContainer: '#user-settings-box' }); this.render = function (event, userSettings) { @@ -41,6 +42,25 @@ define( this.on(this.attr.close, 'click', function() { this.trigger(document, events.userSettings.destroyPopup); }); + + this.on(document, 'click', function(e) { + var userSettingsBoxContainer = $(this.attr.userSettingsBoxContainer).get(0); + var target = e.target || e.srcElement; + + if (target !== userSettingsBoxContainer && !isChildOf(target, userSettingsBoxContainer)) { + this.destroy(); + } + }); + + function isChildOf(child, parent) { + if (child.parentNode === parent) { + return true; + } else if (child.parentNode === null) { + return false; + } else { + return isChildOf(child.parentNode, parent); + } + } }; this.destroy = function () { diff --git a/web-ui/app/js/user_settings/ui/user_settings_icon.js b/web-ui/app/js/user_settings/ui/user_settings_icon.js index 9471b0f4..a6385dc1 100644 --- a/web-ui/app/js/user_settings/ui/user_settings_icon.js +++ b/web-ui/app/js/user_settings/ui/user_settings_icon.js @@ -43,8 +43,9 @@ define( } }; - this.triggerToggleUserSettingsBox = function() { + this.triggerToggleUserSettingsBox = function(e) { this.trigger(document, events.ui.userSettingsBox.toggle); + e.stopPropagation(); }; this.after('initialize', function () { |