diff --git a/core/client/views/login.js b/core/client/views/login.js index fc11162346..2adc7b27f8 100644 --- a/core/client/views/login.js +++ b/core/client/views/login.js @@ -2,15 +2,9 @@ (function () { "use strict"; - Ghost.Views.Login = Ghost.View.extend({ - templateName: "login", - - events: { - 'submit #login': 'submitHandler' - }, - - initialize: function (options) { + Ghost.SimpleFormView = Ghost.View.extend({ + initialize: function () { this.render(); $(window).trigger('resize'); }, @@ -18,12 +12,34 @@ afterRender: function () { var self = this; - $(window).on('resize', _.debounce(function (e) { - $(".js-login-container").center(); - }, 100)); + $(window).on('resize', self.centerOnResize); $(window).one('centered', self.fadeInAndFocus); - return this; + }, + + fadeInAndFocus: function () { + $(".js-login-container").fadeIn(750, function () { + $("[name='email']").focus(); + }); + }, + + centerOnResize: _.debounce(function (e) { + $(".js-login-container").center(); + }, 100), + + remove: function () { + var self = this; + $(window).off('resize', self.centerOnResize); + $(window).off('centered', self.fadeInAndFocus); + } + }); + + Ghost.Views.Login = Ghost.SimpleFormView.extend({ + + templateName: "login", + + events: { + 'submit #login': 'submitHandler' }, submitHandler: function (event) { @@ -52,16 +68,10 @@ })); } }); - }, - - fadeInAndFocus: function () { - $(".js-login-container").fadeIn(750, function () { - $("[name='email']").focus(); - }); } }); - Ghost.Views.Signup = Ghost.View.extend({ + Ghost.Views.Signup = Ghost.SimpleFormView.extend({ templateName: "signup", @@ -69,10 +79,6 @@ 'submit #register': 'submitHandler' }, - initialize: function (options) { - this.render(); - }, - submitHandler: function (event) { event.preventDefault(); var email = this.$el.find('.email').val(),