From 9e1a402b9481feb5ef3b13a9db8ac717491f8adf Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 4 Aug 2014 15:53:55 +0200 Subject: [PATCH] Set back button event in navigation.js --- src/js/app-controller.js | 2 -- src/js/controller/navigation.js | 3 +++ src/js/util/backbutton-handler.js | 19 ++++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/js/app-controller.js b/src/js/app-controller.js index 594b308..efbeaa6 100644 --- a/src/js/app-controller.js +++ b/src/js/app-controller.js @@ -24,7 +24,6 @@ define(function(require) { InvitationDAO = require('js/dao/invitation-dao'), DeviceStorageDAO = require('js/dao/devicestorage-dao'), UpdateHandler = require('js/util/update/update-handler'), - backBtnHandler = require('js/util/backbutton-handler'), config = appConfig.config, str = appConfig.string; @@ -55,7 +54,6 @@ define(function(require) { function onDeviceReady() { axe.debug('Starting app.'); - backBtnHandler.start(); self.buildModules(); // Handle offline and online gracefully diff --git a/src/js/controller/navigation.js b/src/js/controller/navigation.js index bd6a390..8a52418 100644 --- a/src/js/controller/navigation.js +++ b/src/js/controller/navigation.js @@ -5,6 +5,7 @@ define(function(require) { appController = require('js/app-controller'), config = require('js/app-config').config, notification = require('js/util/notification'), + backBtnHandler = require('js/util/backbutton-handler'), _ = require('underscore'), emailDao, outboxBo; @@ -54,6 +55,8 @@ define(function(require) { // Start // + // handle back button + backBtnHandler.start(); // init folders initializeFolders(); diff --git a/src/js/util/backbutton-handler.js b/src/js/util/backbutton-handler.js index 300d728..3b67f2c 100644 --- a/src/js/util/backbutton-handler.js +++ b/src/js/util/backbutton-handler.js @@ -34,25 +34,30 @@ define(function(require) { if (backBtnHandler.scope.state.lightbox) { // closes the lightbox (error msgs, writer, ...) - backBtnHandler.scope.state.lightbox = undefined; + backBtnHandler.scope.$apply(function() { + backBtnHandler.scope.state.lightbox = undefined; + }); axe.debug(DEBUG_TAG, 'lightbox closed'); - backBtnHandler.scope.$apply(); + } else if (backBtnHandler.scope.state.read && backBtnHandler.scope.state.read.open) { // closes the reader - backBtnHandler.scope.state.read.toggle(false); + backBtnHandler.scope.$apply(function() { + backBtnHandler.scope.state.read.toggle(false); + }); axe.debug(DEBUG_TAG, 'reader closed'); - backBtnHandler.scope.$apply(); + } else if (backBtnHandler.scope.state.nav && backBtnHandler.scope.state.nav.open) { // closes the navigation - backBtnHandler.scope.state.nav.toggle(false); + backBtnHandler.scope.$apply(function() { + backBtnHandler.scope.state.nav.toggle(false); + }); axe.debug(DEBUG_TAG, 'navigation closed'); - backBtnHandler.scope.$apply(); + } else { // exits the app navigator.app.exitApp(); } } - return backBtnHandler; }); \ No newline at end of file