From f5c8ebcb90f34f1b49c6be29fbd1ab5ec2cf2d75 Mon Sep 17 00:00:00 2001 From: Sri Vishnu Totakura Date: Sat, 6 Jul 2013 14:45:33 +0530 Subject: [PATCH] publisher closes when clicked anywhere outside its division after opening fixed app.publisher undefined error app view removed and click event binder added in the publisher view initializer. removed unwanted console log attempted to fix this.el undefined error --- app/assets/javascripts/app/app.js | 2 +- .../javascripts/app/views/publisher_view.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 10275e8d6..258d8b149 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 efe7f3851..dcb8471f5 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');