From 79080b3569aa7caa8beefcaabd11fef93f1c263f Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 28 Sep 2017 23:29:37 +0200 Subject: [PATCH] Routing fixes * Check if `Backbone.history.start()` has been called before. * Only call it after routes have been registered. * Use route for switching between login and register forms --- spec/register.js | 7 +++---- src/converse-core.js | 7 ++++--- src/converse-register.js | 10 ---------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/spec/register.js b/spec/register.js index cbc750aa7..a6b27031f 100644 --- a/spec/register.js +++ b/spec/register.js @@ -37,16 +37,15 @@ return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'); }, 300) .then(function () { - var cbview = _converse.chatboxviews.get('controlbox'); test_utils.openControlBox(); var $panels = cbview.$('.controlbox-panes'); var $login = $panels.children().first(); var $registration = $panels.children().last(); - var $register_link = cbview.$('a.register-account'); - expect($register_link.text()).toBe("Create an account"); - $register_link.click(); + var register_link = cbview.el.querySelector('a.register-account'); + expect(register_link.textContent).toBe("Create an account"); + register_link.click(); test_utils.waitUntil(function () { return $registration.is(':visible'); }, 300).then(function () { diff --git a/src/converse-core.js b/src/converse-core.js index 065550559..974b58e35 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -2013,15 +2013,16 @@ this.connection = settings.connection; } - // TODO: fallback when global history has already been started - Backbone.history.start(); - function finishInitialization () { _converse.initPlugins(); _converse.initConnection(); _converse.setUpXMLLogging(); _converse.logIn(); _converse.registerGlobalEventHandlers(); + + if (!Backbone.history.started) { + Backbone.history.start(); + } } if (!_.isUndefined(_converse.connection) && diff --git a/src/converse-register.js b/src/converse-register.js index 81ffefaf3..22eaf75f7 100644 --- a/src/converse-register.js +++ b/src/converse-register.js @@ -81,7 +81,6 @@ ControlBoxView: { events: { - 'click .toggle-register-login': 'switchToRegisterForm', }, initialize () { @@ -89,15 +88,6 @@ this.model.on('change:active-form', this.showLoginOrRegisterForm.bind(this)) }, - switchToRegisterForm (ev) { - ev.preventDefault(); - if (this.model.get('active-form') == "register") { - this.model.set('active-form', 'login'); - } else { - this.model.set('active-form', 'register'); - } - }, - showLoginOrRegisterForm () { const { _converse } = this.__super__; if (_.isNil(this.registerpanel)) {