From e263cb81caf4a1ab51681939244601e955d44c4e Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 27 Mar 2013 19:43:37 -0400 Subject: [PATCH] Make sure share dialog goes away when clicking outside of it, including links to other routes --- app/assets/javascripts/discourse/views/share_view.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/views/share_view.js b/app/assets/javascripts/discourse/views/share_view.js index dad1c9c28b2..24c9688d304 100644 --- a/app/assets/javascripts/discourse/views/share_view.js +++ b/app/assets/javascripts/discourse/views/share_view.js @@ -29,7 +29,9 @@ Discourse.ShareView = Discourse.View.extend({ didInsertElement: function() { var _this = this; - $('html').on('click.outside-share-link', function(e) { + $('html').on('mousedown.outside-share-link', function(e) { + // Use mousedown instead of click so this event is handled before routing occurs when a + // link is clicked (which is a click event) while the share dialog is showing. if (_this.$().has(e.target).length !== 0) { return; } @@ -50,7 +52,7 @@ Discourse.ShareView = Discourse.View.extend({ _this.get('controller').shareLink(e, url); return false; }); - $('html').on('keydown.shareView', function(e){ + $('html').on('keydown.share-view', function(e){ if (e.keyCode === 27) { _this.get('controller').close(); } @@ -59,8 +61,8 @@ Discourse.ShareView = Discourse.View.extend({ willDestroyElement: function() { $('html').off('click.discoure-share-link'); - $('html').off('click.outside-share-link'); - $('html').off('keydown.shareView'); + $('html').off('mousedown.outside-share-link'); + $('html').off('keydown.share-view'); } });