diff --git a/Changelog.md b/Changelog.md index bd24efe82d6fbe4aaf6615ce9245d1a315ec9850..c44572baa079279a57f0546a8f94c689ff8feeb9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,6 +22,7 @@ * Made Unicorn timeout configurable and increased the default to 90 seconds * Follow DiasporaHQ upon account creation is now configurable to another account [#4278](https://github.com/diaspora/diaspora/pull/4278) * Use first header as title in the single post view, when possible [#4256](https://github.com/diaspora/diaspora/pull/4256) +* Close publisher when clicking on the page outside of it [#4282](https://github.com/diaspora/diaspora/pull/4282) # 0.1.1.0 diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 10275e8d68d2c6a78a57bd65e6c15d3c7aa5f8f8..258d8b149305cd516d4e743aa6097aed0ef4707c 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -20,7 +20,7 @@ var app = { views: {}, pages: {}, forms: {}, - + user: function(userAttrs) { if(userAttrs) { return this._user = new app.models.User(userAttrs) } return this._user || false diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index efe7f38513c83101014b70dfe8804963caade027..dcb8471f5fe09d3ae1ab2c95ad81f80a5dcffc42 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -65,6 +65,15 @@ app.views.Publisher = Backbone.View.extend(_.extend( // textchange event won't be called in Backbone... this.el_input.bind('textchange', $.noop); + var _this = this + $('body').on('click', function(event){ + // if the click event is happened outside the publisher view, then try to close the box + if( _this.el && $(event.target).closest('#publisher').attr('id') != _this.el.id){ + _this.tryClose() + } + }); + + return this; }, @@ -249,6 +258,13 @@ app.views.Publisher = Backbone.View.extend(_.extend( return this; }, + tryClose : function(){ + // if it is not submittable, close it. + if( !this._submittable() ){ + this.close() + } + }, + open : function() { // visually 'open' the publisher this.$el.removeClass('closed');