From 56327838cdade8422082535a281ca51856ebded0 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 4 Oct 2016 09:12:24 +0200 Subject: [PATCH] close lightbox if the user press the browswer back button --- app/coffee/app.coffee | 8 +++++++- app/coffee/modules/common/lightboxes.coffee | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 6fd780a3..cc5a7a99 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -690,7 +690,7 @@ i18nInit = (lang, $translate) -> init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $navUrls, appMetaService, - loaderService, navigationBarService, errorHandlingService) -> + loaderService, navigationBarService, errorHandlingService, lightboxService) -> $log.debug("Initialize application") $rootscope.$on '$translatePartialLoaderStructureChanged', () -> @@ -737,6 +737,11 @@ init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $na $rootscope.$on '$locationChangeStart', (event) -> errorHandlingService.init() + if lightboxService.getLightboxOpen().length + event.preventDefault(); + + lightboxService.closeAll() + # On the first page load the loader is painted in `$routeChangeSuccess` # because we need to hide the tg-navigation-bar. # In the other cases the loader is in `$routeChangeSuccess` @@ -861,5 +866,6 @@ module.run([ "tgLoader", "tgNavigationBarService", "tgErrorHandlingService", + "lightboxService", init ]) diff --git a/app/coffee/modules/common/lightboxes.coffee b/app/coffee/modules/common/lightboxes.coffee index 2b42ce89..04d3d0c0 100644 --- a/app/coffee/modules/common/lightboxes.coffee +++ b/app/coffee/modules/common/lightboxes.coffee @@ -97,6 +97,10 @@ class LightboxService extends taiga.Service scope.$destroy() if scope $el.remove() + + getLightboxOpen: -> + return $(".lightbox.open") + closeAll: -> docEl = angular.element(document) for lightboxEl in docEl.find(".lightbox.open")